
Long ago dogs lived in packs. If a stranger came around, one dog would bark and warn the others, and they would attack the stranger. Your dog thinks of you as one of its pack.
If a stranger comes near you or your home your dog will bark to keep him away.
A dog that is chained up has a very small home ground and will guard it even more fiercely. That is why it barks so loudly at strangers.