How does dehydration contribute to headaches and can drinking water alleviate them?

How does dehydration contribute to headaches and can drinking water alleviate them?