Dogs are by nature alert and watchful. This can develop into territorial behaviour which is excessive guarding of an area. If you allow your dog lots of free unsupervised access to the front of your home where people are passing by your dog may bark at them. The people continue on their way. However your dog’s behaviour has now been reinforced by the passers by. Your dog will now associate the two behaviours in his/mind. After a few repeated experiences you now have a territorial dog. This can seem innocent enough.
Then one day you take your dog out for a walk and he SUDDENLY barks and lunges at people to your dismay and surprise. To me this is not surprising at all. Your dog is now repeating the same behaviour he practices in the garden outside the property on a walk when he sees people advancing towards him and his owners which at home he has been allowed to guard.
One way to prevent this behaviour is never to allow your dog to have free access out the front of the property without your supervision. Never ever let him run at people or vehicles along a perimeter fence railings or hedge.
My dogs are always kept to the rear of the property and are only out the front with me under my supervision.