Auto enable UFW on startup

Posted June 24, 2015 33.7k views
NginxUbuntuSecurityFirewallConfiguration ManagementLEMP

Hi everyone, i love this community!

Today i ask for help, i have a problem in my droplet.
When i restart my server the Firewall UFW is always disabled.
in my file: /etc/ufw/ufw.conf
i have enabled to auto-start, but it does not work.

What can i do? can Ajenti/-V have something to do?

Thanks everyone!


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

As @digitaldragon mentioned, this looks like it was a bug that has since been fixed. Here’s the changelog entry:

ufw (0.34~rc-0ubuntu4) utopic; urgency=medium

  * Install the SysV init and upstart script for both Debian and Ubuntu.
    Debian has upstart too, and in Ubuntu we need the init script for LSB
    dependencies and for systemd. (LP: #1341083)
    - Rename debian/ufw.init.debian to debian/ufw.init
    - Rename debian/ufw.upstart.ubuntu to debian/ufw.upstart
    - Remove all the distro specific code from debian/rules and just call
  * Drop the distro specific logrotate configs, and use the ubuntu one with
    "rotate" instead of "reload" everywhere, as Debian's rsyslog init also
    supports "rotate".
  * Add a systemd unit:
    - Add debian/ufw.service
    - Add dh-systemd build dep.
    - debian/rulles: Call dh_systemd_{enable,start}.

 -- Martin Pitt <>   Wed, 30 Jul 2014 15:06:25 +0200

Ran into a problem with this answer, here is the fix.

@JonsJava suggested adding this line to /etc/rc.local

ufw eanble

however it is spelled incorrectly, it should be:

ufw enable

so, it took a while to debug this because rc.local doesn’t automatically log anywhere.
if you add these lines to the top of rc.local, you will see the error with @JonsJava ’s answer.

exec 2> /tmp/rc.local.log      # send stderr from rc.local to a log file
exec 1>&2                      # send stdout to the same log file
set -x                         # tell sh to display commands before execution

adding this line to /etc/rc.local
fixed the issue for me

ufw enable