Using #iptables to forward a whole IP address to another (server)
iptables -A PREROUTING -t nat -d $src -j DNAT --to $dst iptables -A POSTROUTING -t nat -d $dst -j MASQUERADE
Connections from anywhere to $src will get forwarded to $dst (though source IP will be changed to that of eth0 or default outbound device). Useful when moving servers; keeps the old address alive for a bit. Though we lose ‘real’ source address.
For example, if forwarding IP address used by an SMTP server, all email will appear to come from $eth0. If $eth0 (could be the same as $src, but not guaranteed) is privileged, in the sense that it is allowed to relay, then anyone will be able to relay through the SMTP server. But works in a pinch, while DNS changes are propogating through the ‘net.
A somewhat more concrete example. Say you have IP address 188.8.131.52; if you do
iptables -A PREROUTING -t nat -d 184.108.40.206 -j DNAT --to 220.127.116.11 iptables -A POSTROUTING -t nat -d 18.104.22.168 -s 22.214.171.124 -j MASQUERADE
126.96.36.199 is now forwards to Google’s Public DNS Server. You can now use 188.8.131.52 as if it were 184.108.40.206.