Testing Connections with Ubuntu Firewall (UFW)
When managing Ubuntu firewalls (typically UFW—Uncomplicated Firewall), testing connections ensures your rules work as intended. Below are key methods to validate connectivity, organized by tool and use case.
Before testing, confirm UFW is active and view its rules to understand which ports/IPs are allowed/denied:
sudo ufw status
Status: active
means UFW is enforcing rules; inactive
means it’s not blocking traffic.22/tcp ALLOW Anywhere
). If a port isn’t listed, it’s denied by default.telnet
(Simple TCP Check)Telnet tests basic TCP connectivity. Install it if missing (sudo apt install telnet
), then run:
telnet <server-address> <port>
Connected to <server-address>
(e.g., Connected to www.example.com
).Unable to connect to remote host: Connection refused
(firewall/port closed) or Connection timed out
(network issues).nc
(Netcat, More Flexible)Netcat (nc
) checks both TCP/UDP connectivity. Install it (sudo apt install netcat-openbsd
), then:
nc -zv <server-address> <port>
-z
scans without sending data, -v
enables verbose output.Connection to <server-address> <port> port [tcp/udp] succeeded
.Connection refused
(firewall/port closed) or Timeout
(network issues).UDP is connectionless, so tools like nc
are ideal. Use:
nc -zuv <server-address> <port>
-u
specifies UDP.For web services, use curl
to check if the firewall allows HTTP/HTTPS traffic:
curl -I http://<server-address> # HTTP
curl -I https://<server-address> # HTTPS
HTTP/1.1 200 OK
).Connection refused
(firewall blocking) or Timeout
(server issue).nmap
nmap
scans ports to detect open/closed/filtered states (filtered = blocked by firewall). Install it (sudo apt install nmap
), then:
nmap -p <port> <server-address>
nmap -p 22 localhost
checks if port 22 is open locally.open
: Port is accessible.closed
: Port is not listening (service not running).filtered
: Port is blocked by a firewall.sudo systemctl status apache2
).sudo ufw allow ssh
(or sudo ufw allow 22/tcp
).By combining these tools, you can systematically verify if your Ubuntu firewall is correctly configured and not blocking legitimate traffic.