I followed the guide here to add some rules to the nat
table. Everything worked fine until I decide to reboot the server to see if everything works. Well, it doesn't. After reboot, PREROUTING
section in nat
table is empty (I checked with iptables -t nat -L
).
If I run ufw reload
or ufw disable & ufw enable
and check again, the rules are added just fine. I tried to reset ufw (ufw reset
) and start from scratch, no good - once I reboot, PREROUTING
section would contain nothing.
I see guides about how to apply the rules without reboot, but I want the rules to persist between reboots. What am I missing?
*nat
:PREROUTING ACCEPT [0:0]
-F
-A PREROUTING -p udp --dport 587 -j REDIRECT --to-ports 9587
COMMIT
(I didn't touch anything below, I added -F so I don't get duplicate rules during ufw reloads)
#
# rules.before
#
# Rules that should be run before the ufw command line added rules. Custom
# rules should be added to one of these chains:
...
(Ubuntu 16.04 LTS, ufw 0.35)
Some updates: I've tried all kinds of resetting, nothing helps, so I just gave up. I went back to old-school iptables and use iptables-persistent
to restore my iptables on reboot. If anyone get any idea how can I make ufw work, please do let me know.
/etc/rc.local
as per the next section in the doc you referenced.rules.before
it mentions Custom # rules should be added to one of these chains: # ufw-before-input # ufw-before-output # ufw-before-forward Not sure what that means exactly since you mention that disabling and reenabling ufw seems to add the rules just fine.