CCyberwiki

Host and cloud firewalls

Host and cloud firewalls
TypeNetwork traffic filter
Host firewallsufw, firewalld, iptables
Cloud firewallsAWS security groups and network ACLs, Google Cloud VPC firewall rules, Hetzner Cloud Firewalls, DigitalOcean Cloud Firewalls
Decides bySource and destination address, port, protocol, direction

Traffic to a rented server can be filtered in two places. A host firewall is software on the server itself. On Linux, every modern firewall tool hands its rules to netfilter, the part of the kernel that decides what happens to each packet arriving at the machine; ufw, the default tool on Ubuntu, is one such front end.1 A cloud firewall is set up in the hosting provider's console or API instead of on the server: an AWS security group, a Google Cloud firewall rule, a Hetzner or DigitalOcean Cloud Firewall. DigitalOcean's is a network-based service, free of charge.2 Both kinds of firewall match traffic by address, port, protocol and direction. They start from different defaults and miss different traffic, so a port can be closed in one and open in the other.

Starting rules

ufw starts disabled on Ubuntu, so it filters nothing until someone runs ufw enable.1 A new AWS security group has no inbound rules, so it lets nothing in, and has one outbound rule that lets everything out.3 A Hetzner Cloud Firewall with no rules behaves the same way.4 Google Cloud's ready-made default network goes the other way: it comes with rules that allow SSH on port 22, Remote Desktop on port 3389 and ICMP (ping) from any IPv4 address.5

Table 1. Where each firewall applies and what its rules can say67542
FirewallApplies toRules
ufwThe server it runs onAllow, deny (drop silently), reject (tell the sender), limit
AWS security groupEach instance it is attached toAllow only; all rules are read before a decision
AWS network ACLA subnetAllow and deny, read in ascending number order until one matches
Google Cloud VPC ruleTargets in a VPC networkAllow and deny, ordered by priority; each rule is inbound or outbound
Hetzner Cloud FirewallServers it is applied to, directly or by labelAddresses and ports to allow; everything else blocked
DigitalOcean Cloud FirewallDroplets (DigitalOcean servers) it is applied toAllow, and since 4 August 2026 deny, which wins over a matching allow

A security group cannot deny. Blocking one source or another specific subset of traffic is the job of a network ACL, which covers a whole subnet (a range of addresses inside an AWS network).7

Connection state

A server that calls an outside API expects the answer to come back in, even though no inbound rule names that API. Stateful firewalls handle this by tracking each connection. When an AWS instance sends a request, the response is let in whatever the inbound rules say, and the reply to an allowed inbound request is let out whatever the outbound rules say.8 Hetzner and DigitalOcean firewalls track connections the same way.92 Google Cloud keeps a connection tracking table and treats an entry as live while at least one packet passes every 10 minutes.5

Some older protocols, such as FTP, SIP and PPTP, may use extra ports that do not count as replies, so a stateful firewall blocks them unless a rule allows those ports.9 An AWS network ACL keeps no state at all: the return half of every connection needs its own rule.7

ufw on a server

ufw keeps a default policy for each direction (incoming, outgoing and routed) and lists exceptions on top of it.6 A web server that its owner manages over SSH might use:

sudo ufw default deny incoming
sudo ufw allow 22
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verbose

In the status output, Anywhere means every IPv4 address (0.0.0.0/0) and every IPv6 address (::/0).6 Rules for IPv6 only take effect when IPv6 is turned on in /etc/default/ufw.6 A limit rule, such as ufw limit ssh/tcp, refuses an address that opens 6 or more connections within 30 seconds, which slows password guessing over SSH.6 Traffic that passes through the server on its way to another host, as on a router, needs separate rules written with the route keyword, because netfilter handles forwarded traffic in its FORWARD chain.6

Gaps between the layers

Docker

Docker writes its own netfilter rules. Traffic to a published container port is redirected in the nat table before it reaches the INPUT chain where ufw keeps its rules, so ufw never sees it. On hosts with firewalld, Docker adds a zone named docker whose target is ACCEPT.10

NewsBlur met this in June 2021 while moving its databases into containers. ufw on the new MongoDB server held a strict list of internal addresses, but Docker had added a rule opening port 27017 to the internet, visible in iptables -L though ufw reported itself active. A little over three hours later an automated attacker dropped the collections and posted a fake ransom demand for about 250 GB of data; the service came back from backups.11 Afterwards NewsBlur turned on database user authentication and pressed on with its move to a private network, writing that it "had been relying on the firewall".11 Docker's rules change only the server's own netfilter, not a firewall configured at the provider, which is why Securing a Docker application on a self-managed server pairs the two.

IPv6 and private networks

A rule set written for one address family leaves the other open. Besides the ufw setting above, a Google Cloud inbound rule with no source given applies to every IPv4 address and to no IPv6 address.5 Hetzner Cloud Firewalls do not filter traffic on Hetzner's private networks, and a firewall attached by label may not be applied to a server with no public IP or one past a limit.9 A service that must stay internal, such as a database, is covered in Publicly exposed database.

Wide rules

Security group rules are meant to avoid large port ranges and to limit each port to the sources that need it.8 A security group rule can name another security group as its source, which admits only the instances in that group rather than an address range.3 A network ACL with rules similar to the security groups adds a second layer at the subnet12, the arrangement described in Defence in depth.

In SecFlash

On the Cloud page, SecFlash reports a Hetzner server with no firewall (SF-CLD-101), a Hetzner firewall rule that opens a risky port to everyone (SF-CLD-102) and a Hetzner firewall applied to no server (SF-CLD-103). The DigitalOcean equivalents are SF-CLD-201, SF-CLD-203 and SF-CLD-204, with SF-CLD-202 for a rule that opens every TCP port. On the Server page, SF-SRV-102 names a port that answers from outside, and SF-SRV-104 a port open on IPv6 but not on IPv4.

See also

References

  1. a b Canonical (n.d.). "Firewall". Ubuntu Server documentation.
  2. a b c DigitalOcean (n.d.). "Cloud Firewalls". DigitalOcean Docs.
  3. a b Amazon Web Services (n.d.). "Security group rules". Amazon VPC User Guide.
  4. a b Hetzner (2021). "Firewalls: Overview". Hetzner Docs.
  5. a b c d Google Cloud (n.d.). "VPC firewall rules". Google Cloud documentation.
  6. a b c d e f Ubuntu (n.d.). "ufw: program for managing a netfilter firewall". Ubuntu Manpages, ufw 0.36.2.
  7. a b c Amazon Web Services (n.d.). "Infrastructure security in Amazon VPC". Amazon VPC User Guide.
  8. a b Amazon Web Services (n.d.). "Control traffic to your AWS resources using security groups". Amazon VPC User Guide.
  9. a b c Hetzner (n.d.). "Firewalls: FAQ". Hetzner Docs.
  10. back Docker (n.d.). "Packet filtering and firewalls". Docker Docs.
  11. a b NewsBlur (2021). "How a Docker footgun led to a vandal deleting NewsBlur's MongoDB database". The NewsBlur Blog.
  12. back Amazon Web Services (n.d.). "Control subnet traffic with network access control lists". Amazon VPC User Guide.