Dogs are territorial as Sandra said. From what I've read, they know the difference between people you greet and let into your house and people you don't. This is why they bark at the mail carrier and delivery people. They come up on your porch, but you never let them in the house.
It sounds like you are talking about strangers though, right? If I opened the door to a stranger, my dog would not stop barking. Even my previous dog who had better manners would bark. Though, she would have taken my cue as to when it was okay to stop. My Jack Russell? Not so much. Hopefully, your dog would know the difference if a threat was posed. Most dogs do without any special training.
In some ways this is good. If you get a religious or salesperson, they are usually deterred by the barking dog. I had a group of Jehovah Witnesses come half way up our walkway, stop to hear the dog, then turn around. Good doggie