Dogs bark at the fence for a couple of different reasons. First and foremost, they are guardians of your yard and home, so they bark to let you know when there are any changes in the area. Some reserve their barks for actual "intruders," such as gardeners, pool cleaners, etc., but many bark any time someone walks by the fence. Or walks by on the other side of the street. Or when a bird lands on the fence. Or the squirrels run by. Or the wind blows and makes the fence moan. You get the picture. Territorial barking varies in frequency and intensity depending on the dog and depending on your response to the barking.
First off, don't just yell at them to knock it off. They are doing their job, so you yelling just makes it worse because they don't think you understand the importance of the situation. Go find out why your dog is barking. Even if you aren't sure, meaning there isn't an obvious reason to you for their barking, go find out and acknowledge them. Once you've done that, then tell them to be quiet and redirect their attention elsewhere. Don't call them using the word "come," however, because calling them away from barking isn't something they will perceive as a positive experience. You want to use the "come" command only for those situations where your dog will perceive coming to you as a plus. Trust me, they'd rather bark at the fence! Try whistling or clapping your hands to get their attention and then offer an alternative activity. If you want them to come inside, squeak a toy and toss it in the house for them to chase. Or, better yet, whistle to get their attention, ask them for something fun like touch or shake, and then toss a treat inside for them to chase after. This makes coming away from the fence and discontinuing barking a lot more interesting for your dog.
If your dog is barking at your neighbors when they are in their own yard, keep in mind that they do this because that fence is shared; your neighbor thinks they own the fence, but your dog KNOWS the fence is actually his! Make running that shared fence line less desirable by putting up a pointy, picket fence a foot in front of it, or prickly plants, or wobbly stones to discourage rushing the fence. You can even use motion activated sprinklers to spray your dog with water to discourage running that shared fence line. And remember that while you may be able to control your dog's barking when you are home, all bets are off when you aren't there to respond to their barking with a consequence. Thus, hyper vigilant dogs should be confined to their crates, kept indoors, or put in their dog run away from those shared fences so they are less likely to disrupt the neighborhood.
And if you are lucky, your neighbors will appreciate the work your dogs do to keep the neighborhood safe. One of my neighbors believes that the reason her house didn't get broken into like the one two doors up from her this past summer is because anyone breaking in would have to try to sneak in along the side of her house and that's a fence line that Ozzie guards meticulously. He's got a big bark and she tells him how good he is when he barks there at her gardener and her pool guy. She told me she feels safer knowing he's keeping an eye on things. The neighbors on the other side aren't nearly as appreciative of his hard work, so I call him off of their fence to make sure we are being neighborly. It's a constant job monitoring a barking dog, but barking is something dogs do well (and often) and one of the reasons we domesticated them in the first place.
As always, if you have questions about your pet's behavior, you know where to find me.
Ozzie on fence patrol. He makes the rounds in the yard several times a day.