Skip to content

Security Operations / Host hardening · Step 5 of 10

Lesson: Host FirewallsSwitch
← Security Operations

Security investigations

Host Firewalls

Allow only the connections a host needs, without locking yourself out.

A host firewall filters traffic on the machine itself. It adds a layer even when a network firewall exists. The usual policy for incoming traffic is to deny by default and allow what you need.

Find your tool

Linux filtering happens in the kernel (netfilter). Common front ends are ufw on Ubuntu, firewalld on Fedora and RHEL, and nft for nftables directly. Use one manager, so tools do not overwrite each other.

$ sudo ufw status
Status: inactive
$ sudo firewall-cmd --state
running

These are from two different machines. sudo nft list ruleset shows the nftables rules in the kernel.

ufw: allow first, then enable

$ sudo ufw default deny incoming
$ sudo ufw default allow outgoing
$ sudo ufw allow 22/tcp
$ sudo ufw enable

Add the SSH rule before enabling on a remote host, using your real SSH port. Keep your current session open and test a new one. Have console access ready. To restrict by source:

$ sudo ufw allow proto tcp from 203.0.113.0/24 to any port 22

A narrower rule only helps if you do not also keep a broad allow for the same port.

firewalld: zones

firewalld puts interfaces and source addresses into zones, each with its own rules. A rule in the wrong zone has no effect on your traffic.

$ sudo firewall-cmd --get-active-zones
public
  interfaces: eth0
$ sudo firewall-cmd --permanent --zone=public --add-service=https
$ sudo firewall-cmd --reload
$ sudo firewall-cmd --zone=public --list-services
dhcpv6-client https ssh

--permanent changes the saved configuration only. --reload makes it active. Without --permanent, a change applies now but is lost on reload or restart.

Verify from outside

A rule list is not a test. From another machine you are allowed to use, connect to a permitted port and to a blocked one. Check IPv6 too. Remember that Docker publishes ports with its own rules, which can bypass ufw settings. Cloud security groups are a separate layer.

Try it

Look at the current status on a test machine without changing it. Then work through the firewalld zone lab.

Check your understanding

Host Firewalls

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.