ERROR: problem running ufw-init Bad argument `*nat'

1.4k views Asked by At

I was trying to make my server's firewall redirect port 8080/TCP to port 80/TCP. This is simply done by adding the lines before the COMMIT line to create a new *nat

*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80

However, after disabling and trying to enable ufw, I got this error

ERROR: problem running ufw-init Bad argument *nat' Error occurred at line: 75 Try iptables-restore -h' or 'iptables-restore --help' for more information.

I had also enabled port forwarding in /etc/sysctl.conf file by uncommenting the line #net.ipv4.ip_forward=1

-- before #net.ipv4.ip_forward=1

--after net.ipv4.ip_forward=1

Therefore, this is not the problem.

1

There are 1 answers

0
Johnny On

No, its done after the COMMIT line, put it after the COMMIT line, add another COMMIT

# don't delete the 'COMMIT' line or these rules won't be processed
COMMIT

# NAT table rules
*nat
:PREROUTING ACCEPT [0:0]

# Forward traffic from port 8080 to port 80.
-A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80

COMMIT

disable ufw, enable ufw, and you good to go