One way which isn’t always practical, is to temporarily keep your dog in the house while you’re not at home and in a room that doesn’t allow him to bark at passersby through the window.
The long-term approach is to use desensitization and counter-conditioning, that is, slowly getting your dog used to strangers coming near the fence and whereby he can start to associate strangers as not being a threat and in return will act friendly and or at the least be calm/tolerant of those passing by.
For this to work, at first you’ll have to recruit some strangers (to your dog) and ask them to approach the fence at a distance that your dog is comfortable with. Reward your dog for noticing the stranger but not barking at them.
Slowly move the dog and/or stranger closer together and keep rewarding good behavior. Try to set your dog up for success as much as possible. The less often you get your dog’s threshold wrong, the quicker he’ll learn.
Also, it is very important for the stranger not to become fearful or move away if your dog does start barking, as this will only reinforce the unwanted behavior. Just ask the person to stay still and move your dog further away from the fence. Most of all, this requires plenty of patience as it might take a while.
Dogs are territorial and will protect their area whenever there is some natural or an artificial border separating their territory from what they consider as not their territory. Most of them aren’t extremely aggressive if at all when it comes to that though, and if you opened the fence doors you’d likely observe your dog bark while a passer by walks next to the fence, and stop soon after they pass by the open door. That might not be possible to do in your case, but you have probably observed this behavior previously with other dogs behind fences.
I’m describing this to somewhat lower your expectations, because you’re unlikely to stop your dog barking at passers by when they approach some barrier they have learned to protect or have adopted as their territory. When I say learn, I mean that in large part of this behavior would be preconditioned and greatly depends on the dogs breed, and when I say their territory, some dog breeds that are more lenient to strangers approaching might be less likely to bark than others.
So another way to prevent that would be distancing your dog from the fence itself, maybe by building a kennel within that fence but far enough from it for the dog to feel comfortable with strangers passing by (it would depend on each individual dog really, even their status in the pack if you have more than one), but I would advise against chaining your dog or anything of that sort, due to how this harbors energy that needs to be exerted, is cruel and how stressful this can be for any dog.
When you think about it, your dog is doing its job when barking at strangers. And strangers here means any one passing or getting too close that the dog hasn’t yet successfully identified as someone that they know they can trust and isn’t a threat. Different dog breeds will have different sight, smell and hearing abilities, apart from the common calmness, fear and energy they can all sense and feel from other living creatures, how each one gauges whether someone is a “good or “bad” person will vary as well.
Alternatively, if at all possible, move your fence to be slightly protruding onto the street, at least a bit more than your neighbor’s so the dog can see, smell and hear incoming strangers before they nearly brush against your fence and surprise your dog, making him bark even more vigorously.
Or even the other way around, recess your fence inwards so there’s enough of space between the pathway beyond the fence and the fence itself. Anyway, there are many ways to help prevent or lower the frequency of this barking through the fence, once you know where this behavior originates from and if you correct them when you see the signs before hand.
Observe your dog, allow it to move freely on your lawn and take a mental note of when the dog doesn’t feel threatened by passers by, and when it does. Then apply these rules learned to whatever would keep your dog from barking through the fence. Some breeds tend to be more nervous while others might be easier to apply any of these rules to and mitigate this problem.
Terriers are particularly territorial (not where the name comes from, though), also shepherds but usually when there’s something else than themselves to protect within the protected area, and some hounds or similar might not even give any attention to passers by. As a general rule of thumb, bigger dog breeds tend to be more confident in themselves and be slower, less energetic in their reactions to strangers. Unless they feel they really have to. So, learn your dog’s ways and you two will work together to figure things out in the most effective ways.
Lastly, an anti-bark collar is always a viable method. They have rechargeable ones that are automatic, waterproof, the best ones have a vibrate button, beeping sound, and shock, with options for each setting to put the shock on level 0 which is highly suggested. If you’re like me, I would never want to shock my dog, the bark collar I have works just fine using only the sound and vibrate alone.