62

You add a rule like this:

ufw allow 22/tcp

The rule is saved, and is applied even after reboot. But it's not written anywhere in /etc/ufw. Where is it saved to? (Ubuntu, using ufw as pre-installed.)

0

7 Answers 7

59

In my Ubuntu 11 server, the firewall rules are saved in /lib/ufw/user.rules

6
  • 2
    Bingo, thanks. There's also a user6.rules (which doesn't have all the rules I created, but otherwise looks similar). Commented Feb 13, 2013 at 8:20
  • 3
    user6.rules is for IP version 6 (ipv6) firewall rules.
    – Daniel t.
    Commented Feb 13, 2013 at 14:41
  • 1
    Still correct in Ubuntu 14, thank you. Commented Aug 27, 2015 at 1:24
  • 8
    What a crazy location! I just spent 20 minutes looking for this :-( Commented Dec 2, 2015 at 16:48
  • I didn't, because I searched first on ServerFault :-) But I agree, it's anything but obvious... Commented Sep 29, 2022 at 11:58
36

Ubuntu 16.04 LTS

/etc/ufw/user.rules

Debian 9

/etc/ufw/user.rules

In general, try:

locate user.rules

Should output something like:

/etc/ufw/user.rules
/usr/share/ufw/user.rules
/usr/share/ufw/user.rules.md5sum
/usr/share/ufw/iptables/user.rules
3
  • 2
    It's recommended to run updatedb at least once before using locate.
    – ccpizza
    Commented Jan 15, 2017 at 19:44
  • 2
    @ccpizza On Ubuntu, at least, updatedb is run daily by cron. See /etc/cron.daily/mlocate.
    – Jivan Pal
    Commented Jun 7, 2020 at 17:07
  • Still valid for Ubuntu 22.04 and Debian 11 as of 2022. Insane! Commented Sep 29, 2022 at 12:01
12

I believe it's under lib/ufw/rules[6].rules

4

In my version, 8.04 LTS Server the files are stored in /var/lib/ufw as /var/lib/ufw/user.rules and /var/lib/ufw/user6.rules.

3

This should work on all Linux systems assuming a ".rules" suffix and residing beneath a directory named "ufw":

sudo find / -name "*.rules" -exec ls -l {} \; | grep ufw

Using the "ls -l" shows that some of them are links to others, and which ones have been updated most recently (implying they are active?)

2
  • 1
    Assuming that Debian/Ubuntu have been consistently implementing their usual configuration for ufw as well, there is some logic implied: original (raw from the distro) files should be under /usr/share/ufw/; locally changed/overridden files under /etc/ufw; dynamically changed rules (for some reason) ought to be under /run (I just have a lock file there). The exception to the usual configuration is /lib/ufw which should also have some rules in it, but just has a startup script for ufw. Commented Sep 29, 2022 at 12:07
  • 1
    The way /etc overrides what is on /run which overrides what is on /lib (which is usually a symlink to /usr/share) is pretty consistent among most configurations in Debian & Ubuntu. Commented Sep 29, 2022 at 12:08
1

On Ubuntu 16 and up user firewall rules are stored in /etc/ufw/user.rules and /etc/ufw/user6.rules. Overall all UFW rules and configs located in /etc/ufw

enter image description here

0

As of September 2021, you can find all files and configuration of what is called the UFS Framework using man ufw-framework. It describes in detail where each file goes, what it does, and how the system works together to launch the ufw framework at boot time.

This is valid for at least Ubuntu 22.04 and Debian 11 (Debian has an older version of the man page installed by default, but saying essentially the same).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .