The only way you can keep a male dog away from a female dog in heat is to take the dog to the vet and get him neutered. If you also own the bitch in heat, get her spayed, too. This might seem harsh, but it's the only way to guarantee that the dogs won't mate. Dogs are incredibly crafty when it comes to finding a mate. You might think you have all the bases covered and that no way can the male and female dog get together.
You'd think wrong.
The Tenacious Male Dog
Male dogs can scent a bitch in heat up to four miles away and will escape from yards, houses, cars, your hands, collars, kennels and even Bloodhounds to find that bitch. Male dogs will even give up eating and sleeping so they can be sure they do not miss any opportunity. During the time the bitch is in heat, a male suitor can loose a lot of body weight.
They also can loose their lives. Male dogs get in a lot of fights for the right to breed. They also get into fights with the bitch in heat in case she does not watch to breed. But the wandering male suitor is most in danger of traffic to and from the bitch's home and from the anger of the bitch's owner. For example, in England, a farmer has the legal right to shoot any stray dog on their property if the dog is "bothering the livestock".
But I've Got A Great Idea!
To show you how utterly futile it is to try to keep male dogs away from a bitch in heat, I'll relate a true story here, taken from Jilly Cooper's "Intelligent & Loyal: A Celebration of the Mongrel" (1981). The owner of a prize German Shepherd bitch thought he had a sure-fire way to keep the dogs off of her. He tied her to the kitchen table as soon as she came into heat. The owner felt safe enough to leave the kitchen.
However, he left a window open. When the owner came back to the room, his German Shepherd was also tied to the local stray mongrel male dog. The puppies came right on schedule.
The Dog Overpopulation Problem
Just in America alone, according to the Humans Society of the United States, there are an estimated six to eight million stray dogs brought to shelters. Three to four million dogs in shelters are put to sleep because there are no homes for them. The odds of you finding a good home for any puppies your dog either sires or whelps is astronomically slim. It also costs hundreds (even thousands) of dollars to care for a pregnant bitch and her puppies.