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