Cats are natural prey for dogs, who are usually bigger and like to chase smaller animals. Though you can take some steps to prevent a dog from attacking a cat, remember that it is in the dog's natural instinct. Though his behavior can be restrained and taught to some degree, your dog may always feel an inclination to hunt cats. This does not make him a bad dog, and your success in training him not to attack a cat depends on the age of the dog, your consistency in training and your approach.
Spay or neuter your dog. This is the single most important thing you can do to decrease your dog's aggression toward your cat, other dogs, and people.
Socialize your dog at a young age to be around cats, other dogs and small children. This will increase his comfort and decrease his anxiety around any small animal in the future. Puppies are easier to manipulate and more likely to want to play than older dogs, who are more likely to want to hunt and kill.
Establish separate spheres within your home. Both the cat and the dog should be able to get to their food and water bowls without crossing through the other's area. Let them sniff the other's bedding and living spaces while the other animal is in a separate room. For the first few weeks at least, the dog and cat should be kept separated at all times except when you are having a close supervision session. You can use baby gates to separate the cat and dog in different areas of your home or keep the dog in the yard and the cat in a room with her litter box.
Exercise your dog and wear out his energy level before introducing him to the cat. If the dog is tired, he will be less energetic and excitable, and more likely to respond to the cat in a calm manner. Take him on a walk or run around with him.
Supervise and closely monitor the cat and the dog being in the same room. Do this often and repeatedly so the animals can get used to seeing each other. Keep your dog on a leash at all times during these sessions and keep him close to you, in case you need to separate the animals or step between them before things get heated. Gently pet him and speak softly. Do not use your "bad dog" tone at any time, even if he is barking or lunging at the cat--he's not being bad, he's being a dog. Getting frustrated and speaking in an angry tone will teach him that interactions with the cat are negative and fraught. Try to distract him by interrupting his line of sight to the cat, jingling keys at him, or playing gently with a chew (not a throw or chase) toy. Let the pets investigate each other from an initial distance. Cats will generally not attack a dog unless cornered, but there will be hissing and growling and barking. These initial sessions are important in making sure neither animal develops a bullying relationship with the other.
Train your dog in basic behavioral obedience. If your dog is well trained enough to come, sit, leave it, and stay when you say so, you will have greater ability to manipulate his behaviors even in tense situations.
Avoid cats on the street while walking your dog, and try to deter cats from entering the yard where your dog plays. Even if your dog gets used to the cat in your home, he may still want to chase and attack strange cats. Check your yard before releasing the dog to play and keep your dog leashed in residential areas where cats might be outside.