Bad argument in iptables NAT command

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.100

But 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!

5

1 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.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like