0

I am trying to add a rule to my iptables, so that traffic trying to connect on port 9091 is forwarded to a different IP address. When searching I found this answer, which seems to fit my exact use case. When adopting the rule shown with my IP addresses and ports it looks like:

iptables -t nat -A PREROUTING -d 192.168.0.54 -p tcp --dport 9091 -j DNAT --to-destination 192.168.0.53

But when running I get the error:

iptables -t nat -A PREROUTING -d 192.168.0.54 -p tcp --dport 9091 -j DNAT --to-destination 192.168.0.53
iptables v1.8.7 (nf_tables): unknown option "--dport"
Try `iptables -h' or 'iptables --help' for more information.

I am not sure what's going on, everywhere I look, it says you have to make sure to specify a protocol before using the --dport option, but I am clearly specifying tcp. Any help would be appreciated.

1 Answers1

0

Okay well after an annoying hour this had a silly fix. I simply just wasn't running the command with sudo.

I don't work with iptables a bunch, so I wanted to get the syntax correct first, and then I assumed it would tell me it wasn't working because I didn't have permission. For some reason it just spits out the unknown option "--dport" instead though, but as soon as I ran it with sudo it worked.

sudo iptables -t nat -A PREROUTING -d 192.168.0.54 -p tcp --dport 9091 -j DNAT --to-destination 192.168.0.53