57

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.)

Steve Bennett
  • 5,750
  • 12
  • 47
  • 59

6 Answers6

57

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

Daniel t.
  • 9,291
  • 1
  • 33
  • 36
33

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
tivnet
  • 435
  • 4
  • 6
12

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

golja
  • 1,621
  • 10
  • 14
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.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
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?)

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
Craig Hicks
  • 677
  • 1
  • 5
  • 13
  • 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`. – Gwyneth Llewelyn Sep 29 '22 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. – Gwyneth Llewelyn Sep 29 '22 at 12:08
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).