Some dogs smell unpleasant because they have infected mouths. Dental tartar and infections of the gums (what your dentist calls periodontal disease) create foul breath due to the high numbers of bacteria. If the dog in question then licks themselves regularly, they spread that smelly, bacteria-laden spit all over their fur. You can wash it off, but it comes right back. That dog needs some dental care, perhaps even the removal of some severely infected teeth.
Other dogs smell funky when their ears are infected. Ear canals in dogs are much longer than ours, and curved in a way that can trap water or any fluid. Not surprisingly, dogs that love to swim often get ear infections. If your dog's ears smell unpleasant, go see the vet. Have your veterinarian swab the ears and look at the goo under the microscope to determine if the infection is mostly yeast or mostly bacteria. Then they can show you how to clean and medicate the ears. Pay attention! Every dog should have their ears cleaned and checked at least once a month.
Another source of nasty dog odor can come from the anal glands. Anal glands are normal, scent marking glands found on either side of your dog's anus. Normally a small amount of smelly tan or brown liquid is expressed from these glands whenever a dog has a bowel movement. This is used to mark territory. When the glands fill up, they sometimes leak or become infected. Your veterinarian can empty the glands and make dietary recommendations to help your pet empty them on their own.
Usually dogs smell bad when they have a skin infection. Like the ears, skin can be infected with either yeast or bacteria, as well as some nasty little parasites. Once your veterinarian identifies the culprit, they can help you get rid of the infection with appropriate diet, bathing, or medication. Sometimes it takes all three. And sometimes a skin infection is a sign of something that is happening inside the body. Don't be surprised if it takes some testing and time to clear up the smell.
Finally, dogs have a funny liking for things that smell bad. They will often roll in or eat something gross and stinky if they get the chance. One theory for this behavior is that it helps to disguise their scent for the hunt. I have a hard time imagining my goofy, laid-back Rotti hunting anything, but it helps me contain my anger as I bathe her to think that she is yearning for her wild dog origins.