Two firewall layers
On an EC2 server, traffic is usually controlled by at least two layers:
- AWS Security Group at the cloud network boundary.
- UFW on the Ubuntu instance.
Both can block traffic, but they operate at different places.
Security Group
A Security Group decides which traffic is allowed to reach the instance from the AWS side.
Common web server rules:
22/tcponly from a trusted IP for SSH.80/tcpfrom anywhere for HTTP.443/tcpfrom anywhere for HTTPS.
If a port is blocked here, the request never reaches Ubuntu.
UFW
UFW is the host-level firewall. It controls what the operating system allows after traffic reaches the instance.
This gives a second boundary:
sudo ufw status
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
UFW is useful because it keeps host policy visible even when cloud rules change.
Debugging rule
When traffic fails, check from outside to inside:
- DNS points to the instance.
- Security Group allows the port.
- UFW allows the port.
- A process is listening on the port.
- The application responds correctly.
That order prevents confusing a firewall issue with an application issue.