What Does the ufw enable Command Do in Ubuntu?
The ufw enable command in Ubuntu activates the
Uncomplicated Firewall (UFW), a user-friendly frontend for managing
netfilter firewall rules. When executed, this command boots up the
firewall framework, ensures it automatically starts on system boot, and
immediately begins enforcing the active security ruleset to protect the
system from unauthorized network access.
Activating the Firewall and Boot Persistence
By default, UFW is installed on Ubuntu but is set to an inactive
state. Running ufw enable changes this status
immediately.
- Immediate Enforcement: The firewall starts intercepting and filtering network traffic right away based on your defined rules.
- Boot Persistence: The command modifies the system configuration so that the firewall automatically launches every time the Ubuntu server or desktop restarts. You do not need to re-run the command after a reboot.
Enforcing Default Policies
Upon activation, ufw enable applies the standard default
firewall policies if you haven’t customized them. For most standard
setups, these defaults include:
- Blocking Incoming Traffic: All incoming connection requests from outside networks are blocked by default, protecting open ports from unauthorized access.
- Allowing Outgoing Traffic: All outgoing connections from your machine to external networks are permitted, allowing you to browse the web, download updates, and connect to outside services without restriction.
Impact on Active Connections
When you run ufw enable, the system will typically
display a warning message:
Command may disrupt existing ssh connections. Proceed with y/n?.
If you are managing an Ubuntu server remotely via SSH, you must
ensure that you have allowed SSH traffic
(sudo ufw allow ssh) before enabling the firewall. If you
do not create an exception for port 22 (or your custom SSH port) before
activating UFW, the ufw enable command will cut off your
current remote session and lock you out of the server.