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 22.214.171.124; if you do
iptables -A PREROUTING -t nat -d 126.96.36.199 -j DNAT --to 188.8.131.52 iptables -A POSTROUTING -t nat -d 184.108.40.206 -s 220.127.116.11 -j MASQUERADE
18.104.22.168 is now forwards to Google’s Public DNS Server. You can now use 22.214.171.124 as if it were 126.96.36.199.