There are two types of water hammer.
One is a single bang when any valve is shut off quickly. This can be a manual valve or automatic such as a toilet flush or the shut off cycle of a dishwasher. In this case a "water hammer arrest" device should be installed. Most plumbing sippliers have these and they would start at about $15. this device uses a column that holds air which "cushions" the shock of suddenly switching the water off. There are many types and sizes. Some have pistons in them to prevent the air column from emptying of air by the suction of the passing water over time. In the case of the pistonless (sometimes they use a diaphram) unit, the water would have to be emtied from the system about every 6 months or so, in order to restore the air.
The second is a chattering, sometimes very loud and persistant. This is caused by a mecanically resonant condition in the mounting and/or the position of the supply pipes. In this case one needs to find the spot where this is occuring (it will be obvious from visisble movement of the pipes.) and then rearrange and support that section of pipe so that it is firm in its position. One way to do that is to clamp it to a solid surface. You may move the pipe to be adjacent to a firm surface (a wooden beam or stud) or place a firm surface such as a 2X4 next to it and then strap the pipe to it. After that it is still a good idea to install a "water hammer arrest" device.
Len Birarda
September 2010