I'm wondering if it's possible to get UFW to list the configured firewall rules even when it's not enabled. I only have ssh access to the server at this time, and I don't want to enable UFW if there's not a rule configured allowing ssh. However, since UFW is currently not enabled, I just get an "inactive" message when I run "ufw status".
Is there a special flag I can use or even some config file I can look at to see what rules are configured even when the firewall is disabled?
There is now a
ufw show added
command that will list the configured rules for you, even when the firewall is inactive. It was added as a fix for this bug report and added in v0.33So now you can do:
The format of the output from
ufw show added
makes it much easier to write the delete command for each rule too.There is currently not a way to show the rules you have entered before enabling the firewall via the CLI command. You can inspect the rules files directly however. /lib/ufw/user*.rules contain the rules controlled via the 'ufw' CLI command. Eg:
This will show output like the following (for the rule added with 'sudo ufw allow OpenSSH):
The 'tuple' is the shorthand used internally by ufw to keep track of rules, and can be interpreted as one of these:
It might be useful to be able to add another status command to support this. Please consider filing a bug.
General rules are in
/etc/ufw
. User defined rules are in/lib/ufw/user*
.In Ubuntu 16.04, user defined rules are stored in
/etc/ufw/user.rules
. Therefore, you can see the rules with:From the command line, there doesn't seem to be a way. However, if you're SSH'ing from an Ubuntu box (to an Ubuntu box), you might want to try this, slightly convoluted method :
Basically, install gufw on the remote box, then connect with X forwarding and run the GUI.
On the remote device, after connecting with
-X
as an option :That will show you the ruleset without having to activate it.
Be warned that if the remote device is a true "headless" server, then installing GUFW might pull down an unpleasant number of dependencies. But unless someone here know a trick to make UFW show you the output you need without activating it first, then this might be your only option.
I did try
sudo ufw show raw
, but that shows the iptables output, which I can't make head nor tail of.