Ethical Hacking Series, Part 8. In Part 7 we covered the protocols and ports devices use to talk. This part is about the addresses they talk to, and the firewalls that decide which conversations are allowed. There are live demos on a home network, an AWS EC2 server and Ubuntu’s own firewall.
What an IP address is
Every device on a network needs an address so data can find it, just as every house needs one for post to arrive. That’s the IP address.
IPv4
An IPv4 address is 32 bits long, written as four numbers called octets, each 8 bits and therefore between 0 and 255, separated by dots: 192.168.1.10. Thirty-two bits allows 232 combinations, about 4.3 billion addresses. That sounded like plenty in the 1980s. With phones, laptops, TVs, cameras and servers everywhere, it isn’t, and the free pool of IPv4 addresses has effectively run out.
IPv6
IPv6 was designed to solve that. Its addresses are 128 bits long, written in hexadecimal, like 2001:db8:85a3::8a2e:370:7334. That’s enough addresses that running out is not a practical concern. IPv6 adoption is growing, and many mobile networks in India already use it, but IPv4 is still what you’ll work with most of the time, and what most of this series uses.
Public vs private addresses
IPv4 survived this long mainly because of one trick: most devices don’t have a public address at all.
Private IP addresses work only inside a local network. Your router hands them out (using DHCP, from Part 7), usually from ranges like 192.168.x.x or 10.x.x.x. Thousands of homes can use exactly the same 192.168.1.10, because those addresses never appear on the internet.
A public IP address is unique on the whole internet. Your ISP usually gives your home router just one.
NAT: many devices, one public IP
Network Address Translation (NAT) is how your laptop, phone and TV all reach the internet through that one public address. When a device sends a request out, the router replaces the device’s private address with the router’s public one and keeps a note of which device asked. When the reply comes back, the router uses that note to pass it to the right device.
In the video I prove this with my own web server. I open my website from different devices on my home Wi-Fi, a laptop and a phone, then check the Nginx access log on the server:
sudo tail -f /var/log/nginx/access.log
Every request shows the same IP address, my home’s public IP, no matter which device it came from. From the internet’s point of view, the whole household is one address. That’s NAT at work.
For security, NAT has a useful side effect. Devices behind it can’t be reached directly from the internet unless the router is told to forward traffic to them. It isn’t a firewall, but it hides your internal network. It also explains why, during investigations, one IP address in a log can represent many people, such as an entire office or a mobile carrier’s customers.
What a firewall does
A firewall is like a security guard at the entrance to a building. Every visitor (each piece of network traffic) is checked against a list of rules: who it’s from, where it’s going, which port. Then it’s either let in or turned away. Firewalls can filter traffic coming in (inbound), going out (outbound), or both.
Hardware firewalls
Hardware or network firewalls sit between networks and protect everything behind them. Your home router has a basic one. By default it drops unsolicited inbound connections and often ignores pings from the internet. In the video I scan my own home public IP with Nmap from outside, and the ports show as filtered. Nothing answers, because the router drops the probes.
nmap -Pn your-public-ip
(-Pn tells Nmap not to rely on ping first, because, as we saw in Part 5, a host that ignores ping isn’t necessarily down.)
Companies use dedicated firewall appliances from vendors like Cisco, Palo Alto Networks and Fortinet. Those can inspect traffic in far more detail, enforce policies between internal networks and detect known attacks.
Software firewalls
Software or host-based firewalls run on the machine itself and protect just that one device. Windows Defender Firewall is the one most people have. On Linux there’s iptables/nftables, usually managed through a friendlier tool like UFW on Ubuntu. They matter because a host firewall still protects a laptop when it leaves the office network, or a server whose network firewall was misconfigured.
Demo: two layers of firewall on AWS
Layer 1: the security group
I launch an Ubuntu EC2 instance, install Nginx, and allow HTTP (port 80) in its security group, which is AWS’s firewall around the instance:
sudo apt update
sudo apt install nginx -y
Opening the instance’s public IP in a browser shows the Nginx welcome page. Then I remove the inbound HTTP rule from the security group and reload. The page no longer loads and the browser eventually times out, because AWS now drops the traffic before it ever reaches the server.
Layer 2: UFW on the server
Next I add the HTTP rule back in the security group, so AWS allows port 80 again, and block it on the server instead with UFW:
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw enable
sudo ufw deny 80/tcp
sudo ufw status numbered
The page stops loading again, even though AWS is letting the traffic through. This time the server itself refuses it.
One warning before you try this on a cloud server: always allow SSH (port 22) before running ufw enable. If you enable UFW without that rule, it blocks your own SSH session and you’re locked out of the instance.
Defence in depth
The point of the demo is that the two firewalls protect you independently. If someone accidentally opens a port in the security group, the host firewall still blocks it. If the server’s firewall is disabled during troubleshooting and never turned back on, the security group still protects it. This layering is called defence in depth: no single control is trusted to be perfect, so you stack several.
For an attacker, the same idea explains why finding an open port in a cloud security group doesn’t always mean the service is reachable, and why it’s worth checking each layer. For a defender, the rule is to open only what’s needed at every layer. The IP addressing and CIDR guide covers how these addresses are planned in AWS, and AWS WAF adds a layer that inspects web requests themselves.
Practice tasks
- Find your laptop’s private IP (
ip a) and your home’s public IP (search “what is my IP”), and explain why they’re different. - If you have a web server, open it from two devices on the same Wi-Fi and confirm the access log shows one IP.
- On an EC2 test instance, recreate both demos: block port 80 in the security group, then with UFW.
- Run
sudo ufw status verboseand explain each rule and the default policies.
A note on ethics: scan only your own public IP and servers, or systems you have written permission to test.
What’s next
Next is Part 9: the OSI model, a way to make sense of everything in Parts 6 to 8 layer by layer, plus building out your hacking lab. To review what came before, see Part 6: networking basics and Part 7: HTTP vs HTTPS and protocols.
Watch Part 8 on my YouTube channel, Madhukar Reddy (@awsandevops).
