UFW: your friendly firewall
UFW is Ubuntu’s default firewall management tool. It simplifies configuring iptables, making it user-friendly even for beginners. In Chapter 11, Introduction to Network Security, we discussed GUFW, the graphical interface for UFW. Now, let’s look at how to use UFW without GUFW’s convenience.
These are the basic UFW commands:
- Check the status:
sudo ufw status
- Enable:
sudo ufw enable
- Disable:
sudo ufw disable
- Allow traffic:
sudo ufw allow 80/tcp
- Allows web traffic on port 80
- Deny traffic:
sudo ufw deny 22/tcp
- Blocks SSH connections on port 22
- Allow from specific IP:
sudo ufw allow from 192.168.1.100 to any port 22
For example, this code allows SSH and HTTP traffic:
ken@monster:~$ sudo ufw allow 22/tcp
ken@monster:~$ sudo ufw allow 80/tcp
ken@monster:~$ sudo ufw enable
ken@monster:~$ sudo ufw status
Status: active...