The idea that Earth is a magnet is far from new. It was first proposed in 1600 by a British physician named William Gilbert. Knowing it acts like a magnet is one thing. Knowing why it acts like a magnet is more difficult. In fact, finding out why is a fairly recent discovery. To find out why required new technology. It was the seismograph that made it possible to learn why the Earth acted like a magnet. Seismograph are used to study earthquakes. By studying earthquake waves they were able to learn about Earths interior. They discovered that Earth has an inner and outer core. The outer core consists of liquid metals, mainly iron and nickel. Scientists think that Earths magnetic field is generated here. It is caused by the motion of this liquid metal. The liquid metal moves as Earth spins on its axis. 
How did they learn why the Earth acts like a magnet?
By analyzing Earth core images