I am trying to do a DNAT rule in iptables if the packet with source address 192.168.86.212 and destination address 192.168.86.212 then change the destination address to 172.217.5.100.
sudo iptables -t nat -A PREROUTING -s 192.168.86.213/32 -d 192.168.96.212/32 -j DNAT -to-destination 172.217.5.100But I got this error message:
Bad argument `172.217.5.100'
Try `iptables -h' or 'iptables --help' for more information.I am very new to Ubuntu, any help is appreciated!
51 Answer
From man iptables-extensions, the DNAT target option is --to-destination (with two dashes) rather than -to-destination:
DNAT This target is only valid in the nat table, in the PREROUTING and OUT‐ PUT chains, and user-defined chains which are only called from those chains. It specifies that the destination address of the packet should be modified (and all future packets in this connection will also be mangled), and rules should cease being examined. It takes the follow‐ ing options: --to-destination [ipaddr[-ipaddr]][:port[-port]]It's not obvious why the error message flags the ipaddr argument rather than the option itself.