When your dog is barking, say "Quiet" in a calm, firm voice.
Wait until he stops barking, even if it's just to take a breath, then praise him and give him a treat.
If your dog barks when alone, tire him out before you go.
Take a long walk or run, play ball or take a trip to the dog park before leaving.