The rotten egg smell you detect in your hot water is hydrogen sulfide gas, a byproduct of the metabolic processes of anaerobic bacteria in the water. The bacteria themselves aren't harmful, and neither is the gas -- at least not in the low concentrations you find in hot water. The odor definitely affects water quality, though, and it can be even worse if you have a water softener. The smell isn't the fault of your water heater, but you can usually eliminate by disinfecting the water heater and changing the anode rod.
Disinfecting the Water Heater
Whether or not you choose to replace the anode rod, you should flush the water heater with chlorine or hydrogen peroxide bleach. Before doing this, try turning the temperature on the water heater to HIGH for two hours. The increased heat may kill all the odor-causing bacteria.
Turn off the water heater by flipping off the breaker in the main panel or turning off the main gas valve. Close the cold water inlet valve. Allow the heater to cool for several hours. Relieve tank pressure by opening the temperature and pressure relief valve -- have a bucket underneath to catch the overflow -- or a nearby hot water faucet.
Connect a garden hose to the drain valve on the bottom of the tank and route the hose to a floor drain, toilet or sink, or someplace outdoors that is at the same level or at a lower level as the water heater.
Open the valve and drain enough water to make room of the chlorine or peroxide bleach you're using to disinfect the tank. You'll be adding the disinfectant in the proportion of 1 gallon for every 30 gallons in the tank.
Remove the T & P valve or the anode rod, using a wrench, and pour the disinfectant in through the opening. Replace the rod or valve, then open the cold water inlet to fill the tank. The tank is full when water starts flowing from a nearby faucet. Leave the disinfectant in the tank for 1 hour.
Open all the hot water faucets in the house and leave them open for two to three minutes to allow the water to disinfect the pipes. Close the faucets, turn off the water inlet and drain the tank. Once it's empty, open the cold water inlet and refill it with fresh water.
Let the fresh water remain in the tank for 15 minutes, then open the faucets in the house again to purge disinfectant from the pipes, turn off the cold water and drain the tank.
Replace the anode rod -- if you choose to do this -- then refill the tank and turn on the water heater, relighting the gas pilot if necessary.
About the Anode Rod
Water heaters have an anode rod to stave off corrosion of the inside of the tank; the rod does this by attracting ions in the water, which eventually corrode the rod itself. Magnesium in the rod increases the concentration of sulfates in the water, thereby increasing the number of sulfur-metabolizing bacteria and the amount of hydrogen sulfide gas. Removing the rod drastically reduces the life of the water heater and isn't a good option, and a standard aluminum rod usually doesn't solve the problem.
One solution is to replace your magnesium or aluminum rod with one made from an aluminum/zinc alloy. Another solution is to install a powered rod that you plug into a wall outlet. This type of rod actively introduces an electric current into the and doesn't corrode, so it doesn't provide food for bacteria.