Barrier Methods: Rusting may be prevented by stopping the water and oxygen getting to the iron with a barrier of grease, oil, paint or plastic.
Galvanising: (coating in zinc) also prevents water and oxygen getting to the iron, but with galvanising even if the barrier is broken the more reactive zinc corrodes before the less reactive iron. During the process, the zinc loses electrons to form zinc ions.
Sacrificial Protection: Zinc blocks are attached to iron boat hulls and underground pipelines to act as sacrificial anodes. Zinc is more reactive than iron, so oxygen in the air reacts with the zinc to form a layer of zinc oxide instead of the iron.