For a long time, many people have been urging me to configure firewall rules to protect their VPS, but... the complicated configuration of iptables has made me hesitate~~ (actually, I'm just lazy~~
Until I discovered this amazing tool called ufw
UFW, short for UncomplicatedFirewall[1], is the default firewall component on Ubuntu systems. It is a tool developed to simplify the configuration of iptables. UFW provides a very user-friendly interface for creating firewall rules based on IPV4 and IPV6.
Without further ado, let's get started with the tutorial
Environment#
Ubuntu 16.04
Installation#
apt install ufw
Configuration#
First, open the SSH port
ufw allow ssh
If your SSH port is not the default 22, then
ufw allow your_ssh_port
Open port 53 to ensure DNS functionality is not affected
ufw allow 53/tcp
ufw allow 53/udp
Optional: Open ports 80 and 443
ufw allow http/tcp
ufw allow https/tcp
Then
ufw default deny
Block external connections except for the above rules (outgoing traffic from the local machine is not affected)
ufw enable
Start the firewall, done!
Commands#
Enable the firewall: ufw enable
Disable the firewall: ufw disable
Reload the configuration: ufw reload
Check the firewall status: ufw status