I recently found out (or rather was awoken by) the noise of banging pipes at night in my house. I narrowed down the problem to the actual pipe that comes into the house. When I close the main valve, the banging goes away, when I open it, Banging comes back. What can it be? The pipe is not hitting anything, it seems to be coming from inside the pipe or something. We don't have an icemaker and the toilets are not leaking. Any ideas?
See if shutting off the water valves at the toilets stops the banging. When I had this problem, it was caused by a toilet fill valve opening and closing rapidly. I was able to solve it by keeping the toilet shutoff valve partially closed. It's probably due to overly high water pressure, and the real fix might be installing a pressure reducing valve on the main water supply.
Not saying for sure that this is your problem, but it's easy to test.