Two ways to prevent the rusting of iron are:
Oiling, greasing, or painting: By applying oil, grease, or paint, the surface becomes water proof and the moisture and oxygen present in the air cannot come into direct contact with iron. Hence, rusting is prevented.
Galvanisation: An iron article is coated with a layer of zinc metal, which prevents the iron to come in contact with oxygen and moisture. Hence, rusting is prevented.