Sub topic 15
Firewall rules, port forwarding, and DMZ
This chapter assumes you know what an IP address, a port, and NAT are. It also assumes you can read a basic router settings page. The chapter explains how a SOHO router decides which traffic from the internet may reach a device inside the network, and the three tools it gives you to control that: firewall rules, port forwarding, and a DMZ.
Why inbound traffic is blocked by default
A SOHO router uses NAT to share one public IP address among many private devices. When a laptop opens a web page, the router records the connection in a state table. It sends the reply back to that laptop. This is called stateful inspection.
A packet that arrives from the internet and matches no entry in the state table has no known destination. The router drops it. This default makes a home network safe from random scans. It also means that a server you run at home is unreachable from outside until you change the rules.
Firewall rules
A firewall is software or hardware that allows or blocks traffic based on rules. Most SOHO routers have a built-in firewall that is on by default. A rule usually matches on some combination of these fields:
- Source IP address or range
- Destination IP address or range
- Protocol, such as TCP or UDP
- Port number
- Direction, either inbound or outbound
Each rule has an action: allow or deny. The router checks rules in order and applies the first match. If no rule matches, the default policy applies. A good default is to deny inbound traffic and allow outbound traffic.
Rule order matters. A broad "allow all" rule placed above a narrow "deny" rule makes the deny rule useless.
| Term | Meaning |
|---|---|
| Allow | Lets matching traffic pass |
| Deny (drop) | Silently discards matching traffic |
| Reject | Discards traffic and sends an error back to the sender |
| Inbound rule | Applies to traffic coming from the internet |
| Outbound rule | Applies to traffic leaving the network |
Exam questions often ask which device filters traffic by port. The answer is the firewall. Remember that a software firewall runs on one computer, while a hardware firewall (such as the one in a router) protects the whole network.
Port forwarding
Port forwarding is a router rule that sends inbound traffic for one public port to a specific private IP address and port. It is also called a static NAT mapping or a virtual server.
Suppose a small office hosts a web server at 192.168.1.50. The router's public address is the only one the internet can see. You create this rule:
| Field | Value |
|---|---|
| External port | 80 |
| Protocol | TCP |
| Internal IP address | 192.168.1.50 |
| Internal port | 80 |
Now a request to the public address on port 80 reaches the web server. Other ports stay blocked.
Some routers also support port triggering. With triggering, the router opens an inbound port only after an internal device makes an outbound connection on a chosen trigger port. The inbound port closes again after the session ends. It is more selective than forwarding, because no port stays open while the device is idle. It also works for only one internal device at a time.
Make the target address stable
A forwarding rule points at a fixed IP address. If the server gets a different address from DHCP, the rule sends traffic to the wrong device or to nothing. There are two fixes:
- Create a DHCP reservation, so the router always gives the server's MAC address the same IP address.
- Assign a static IP address on the server, outside the DHCP pool.
The reservation approach is easier to manage because the router still controls all addressing.
DMZ
A DMZ (demilitarized zone) is a network segment that sits between the internet and the private network. A true enterprise DMZ is separated from the internal LAN by a second firewall, so a compromised public server cannot easily reach internal devices.
SOHO routers offer something simpler, often called "DMZ host." You enter one private IP address, and the router forwards all unsolicited inbound traffic, on every port, to that device. Port forwarding rules that you created still take priority for their ports.
The device in the DMZ is exposed to the internet with almost no protection from the router. Use this feature only for testing, or for a device that has its own strong firewall and security updates. A game console that fails to connect is a common reason people enable it, but forwarding the specific ports it needs is the safer fix.
Comparing the three tools
| Tool | What it opens | Typical use | Risk |
|---|---|---|---|
| Firewall rule | Allows or blocks traffic by address, protocol, and port | Block a port or a site, restrict outbound traffic | Low if rules are ordered correctly |
| Port forwarding | One or more specific ports to one internal device | Web server, remote desktop, camera, game host | Medium, since the opened service must be kept patched |
| DMZ host | All unsolicited ports to one internal device | Testing, troubleshooting a connection problem | High |
Related controls on the router
Several other settings affect which devices and traffic are allowed:
- MAC filtering allows or blocks devices by their hardware address. It is weak protection, because MAC addresses are visible on the air and can be spoofed.
- Content filtering blocks websites by category or keyword, usually for a parental control or office policy.
- UPnP (Universal Plug and Play) lets devices on the LAN create their own forwarding rules automatically. It is convenient, but malware or a buggy application can open ports without your knowledge. Many security guides recommend turning it off.
Common ports used in forwarding rules
You should recognize these port numbers for the exam, because forwarding rules and firewall rules use them.
| Service | Protocol and port |
|---|---|
| HTTP | TCP 80 |
| HTTPS | TCP 443 |
| SSH | TCP 22 |
| RDP (Remote Desktop) | TCP 3389 |
| FTP | TCP 20, 21 |
| DNS | UDP and TCP 53 |
Opening RDP (port 3389) directly to the internet is risky, since automated attacks constantly try to guess passwords. A VPN is the safer choice for remote access.
Troubleshooting forwarding problems
When a forwarded service does not work from outside, check these points in order:
- Confirm the service works from inside the LAN, using the server's private address.
- Check that the rule uses the correct protocol (TCP versus UDP) and the correct internal IP address.
- Check that the server's own software firewall allows the port.
- Check that the ISP does not block the port, as some providers block 25 or 80 on residential lines.
- Test from a different network, such as a phone on cellular data. Many routers do not loop an inside request back to the public address, so testing from inside can fail even when the rule is correct.
- Check whether the router has a private address on its WAN port. If it does, the ISP is using carrier-grade NAT and forwarding cannot work without the ISP's help.
Exercise
A technician forwards TCP port 3389 to 192.168.1.20 so an employee can use Remote Desktop from home. It worked for a week, then stopped. The router rule is unchanged. What is the most likely cause, and what is the best permanent fix?
Show answer
The PC at 192.168.1.20 most likely received a different address from DHCP, so the rule now points to the wrong address. The fix is a DHCP reservation for that PC's MAC address, or a static address outside the DHCP pool. For security, also consider replacing the open port with a VPN.
Exercise
A customer's game console cannot host online matches. A colleague suggests putting the console in the DMZ. Why is this risky, and what should you try first?
Show answer
A DMZ host receives all unsolicited inbound traffic on every port, so the console is exposed to the internet with little protection. First forward only the specific ports the game requires, or enable UPnP only if the customer accepts the risk. Use the DMZ only as a short test to confirm the router is the cause.