UFW is working really well for me except in the cases where it doesn't...
I want to be able to add another rule manually that will be applied on boot?
- where should i put this rule?
- how should I make it start at boot?
- how do I make it play nicely with UFW?
According to this Ubuntu wiki page (scroll down to "Advanced Functionality"), you can achieve what you want by putting your own
iptables
rules into the following files:/etc/ufw/before.rules
/etc/ufw/after.rules
The
before
file is evaluated before anyufw
rules are applied; theafter
file is evaluated after. (There are also correspondingbefore6
andafter6
rules files, for yourip6tables
rules.)These rules files are expected to be in
iptables-restore
-compatible syntax, presumably becauseufw
simply loads them usingiptables-restore
. Finally, note that you need to stop and restartufw
after you make any changes to the rules files.UFW will purge any MANUALLY added rule in
/etc/ufw/user.rules
which is NOT prefaced with a comment:When UFW sanity checks the rules on startup, it expects an accompanying comment. If it's NOT present, even if the syntax of the rule is correct, UFW will still purge it.
And don't just use any arbitrary comment: it MUST be the comment that UFW would insert when creating a user rule via the cli, ie:
So if you want to pre-seed a series of rules in a ruleset in a simple file, you'd still need to create the rules via UFW's CLI interface to learn the syntax of the comments it expects for the rule to pass validation and persist.
Try the foregoing with and WITHOUT the comment and reload the specimen HTTP rule above; you'll remark only with the comment does the manually added rule survive a restart (ufw enable) of UFW.
This is really counter-intuitive behaviour and not documented at all.