There are several ways to help dogs adjust to a visitor's presence without bad behavior. Effective options include:
Providing the dog a safe space and training them to use it.
This can be a crate, bed or just a corner of the room where they know they are safe. This should be the dog's established space, and they can be rewarded for using it with a treat or chew toy. The dog should be trained to go to that spot with a simple command, which can be used whenever a guest arrives.
Reinforcing all training commands, especially "stay" "down" and "no".
Reinforcing training helps keep the owner in control of their pet. Focusing on commands that will be important around guests will help the dog remember its manners and exhibit proper behavior when guests visit.
Leashing the dog when a guest arrives.
Using a short leash can remind the dog about proper behavior and keep the owner in control to minimize jumping or other poor behavior. Keep the leash near the door and train the dog to accept it whenever someone knocks or the doorbell rings. This will also help keep the dog under control so they do not run out the door when it opens.
Greet guests outside first, then move inside.
Very territorial dogs may do best when guests are initially greeted outside in a neutral area. Then the guest can enter the home and get settled, and after a minute or two the dog and owner can go inside. When the dog sees the guest is already part of the territory, dominance issues may be diminished.
Be confident when guests arrive.
Dogs take behavioral clues from their owners, and if an owner comfortably greets a guest with a good tone of voice, the dog will know this is a person to be trusted and welcomed. A hug or handshake can also help give the guest a touch of the owner's scent, which will help the dog feel more comfortable.
Introduce the dog properly.
Dogs get to know newcomers through sniffing, so allow the dog to greet guests in their own way. Permit the dog to approach and learn about the guest so they can accept the visitor more readily. The owner can guide a guest's hand to the dog's nose for a formal introduction and scent mixing the dog will understand.
Minimize guests at first.
If a dog is exceptionally nervous or has bad behavior around guests, avoid having a big party or many people over until the dog learns better manners and is more accustomed to the activity. This will help the dog get used to having different people around and it will learn there is no danger from guests.
Reward good behavior.
When a dog responds to commands and reacts appropriately to a guest, reward that behavior with a kind word, pat on the head or tasty treat. This will reinforce the dog's good behavior for future visits.