Dogs are definitely an intimidating, though seldom dangerous, part of cycling. Dogs, of course, are not the only threat from the surrounding fauna: one author was once attacked by a large and determined goose (they can break a man's leg, y'know). The fact is that some pet owner take a not-so-secret pleasure in keeping vicious attack-prone animals, and others are beat by their owners whenever it barks too much, both having the effect of putting an unpredictable and feral creature galloping up behind you.
The first step is to shout "NO!" as loudly and firmly as you can. This will deter a significant fraction of the dogs that decide to chase you for sport.
The best approach is to simply outrun the animal. This is an excellent reason to use a road bike, but even on my cheesy mountain bike I can generally sprint faster than a large dog can (on a road bike I can cruise faster than the dog can sprint, but that's another story).
Stop and Face the Dog
If riding away is not possible, there is nearly never a real problem. Some cyclists recommend bludgeoning the dog with car ariels, whips, pumps, clubs, and other things which could really hurt a dog. Almost every time, if you simply stop, dismount, and face the dog directly, it will trot up to you with it tail wagging. Most dogs are normally friendly, but all of them seem to go nuts when exposed to a moving bicycle. If you set off walking your bike, the dog will consider you just another normal person, rather than some bizarre Centaur thing. Unless you can determine that the dog really is a threat, anything more than a water bottle squirt really is brutal and uncalled for.
If the dog really is less than friendly, and you can't just sprint off into the distance, you'll probably have to dismount to deal with him anyway. The key is to have confidence. As one of the largest land animals on the planet, you are a formidable contender in any showdown, so exude that fact from your pores. Suppress your fears and radiate the notion that any dog that messes with you will regret it for the rest of his days, if he lives that long. Few dogs will attack a human obviously prepared for self-defense, so speak to it in firm tones, keep the bicycle between you and the dog, and slowly walk away.
If the dog attacks, and you can't or won't climb a tree or television antenna tower, your best bet is a pepper spray, sold in hardware stores. These have a range of a few metres and will set the dog straight in about the amount of time it takes for the nerve impulses to reach its brain. But pepper spray or no, attack back! Feeble twits that curl up into a ball in the face of adversity will be killed by a large dog. I don't know about you, but freezing in the headlights of a family sedan is not the way I want to go down.
We have an article discussing Weapons for Use Against Dogs, including pepper sprays, ammonia, using your bike pump effectively, and more.
If the dog is determined and large, your are in a fight for your life. You can avoid this problem by carrying pepper spray or buying a fast bike. If it is a smaller dog, you can hoist it up by the hind legs and bash it unconscious against a tree. Kicks to the balls and which break ribs are effective. If worst comes to worst, ram your entire arm down its throat. It will choke and die. Better your arm than your neck.
Your bike is very useful, but more as a tool than a weapon. Hold it between you and the dog, and be ready to throw it on him. This is an excellent tactic, if you can pull it off. You can jump on top of the bike, which will concentrate your body weight onto whatever anatomical feature your pedal and bar end are resting on, and proceed to cheapshot the dog or strangle it to death without getting bitten.
Groups are much more formidable than a lone rider. If you riding partner gets into trouble, you can save his butt with little risk to yourself by joining him or her. Also, many more tactics open themselves up: you can keep throwing your bikes at the dog until you get a hit and can pound him into submission, rather than getting only one shot. You can both thump him over the head or throw rocks at once, and only half of your total offensive ability can be occupied by an attacking dog at any one time.
When the Dust Settles
If you are bitten, make every effort to find the owner. If you cannot and the dog can't be quarantined, then you will have to undergo a long and painful series of rabies injections. So ask around the area, check with local shops.
Even for a light bite, get immediate medical treatment. If the dog owner is uncooperative about dealing with medical and other expenses, get a lawyer, as the law is completely and absolutely on your side.
If you successfully fend off an attack, notify the dog owner, and the dog warden or police about the incident. This is a very important responsibility, as the next victim may not be as well prepared as you were.