Server firewall and firewall templates

The per-server firewall enforced on the node, its rules, rate limits, country rules, hit counters and dropped-packet log, and firewall templates.

Each server has a stateful firewall that runs on its node, outside the server. A customer who breaks the firewall inside their server still has this one, and a compromised server cannot turn it off. This page covers the per-server firewall; the firewall that protects the node itself is described in Node firewall.

What it filters#

The firewall filters traffic between the server and the internet or other servers, on the server's public IPv4 and IPv6 addresses and, for a NAT server, its private address after the port forward. Rules on a NAT server therefore name the server's real ports, not the node's forwarded ports. Traffic between a server and its own node is not filtered.

It is off by default: a server that never had a firewall is not filtered at all.

When it is on, the node checks traffic in this order:

  1. Replies to connections that are already open pass.
  2. Essential ICMPv6 (neighbour discovery, router advertisements, packet too big, time exceeded, parameter problem) always passes, or IPv6 would break.
  3. The rules, in order. The first rule that matches decides.
  4. The default action: in (to the server) drop, out (from the server) accept. Both can be changed per server.

Not supported#

  • Bridged servers and servers on a VLAN. Their traffic is bridged, not routed through the node, so the firewall cannot be turned on. The server's Firewall tab says so and names what protects the server instead: the node's network rules on the bridge (DHCP servers and router advertisements it sends are dropped, ARP limits, the metadata block, SMTP and ping as the node's settings say). See Bridged networking and VLANs.
  • Agents older than 0.16.0. The tab says "This node's agent does not support the firewall yet; upgrade the agent." Changes are kept and sent once the agent is upgraded.

Turn the firewall on#

Whoever manages the server can do this: its owner, the owner's reseller, and administrators. A customer needs the firewall permission (see Customer permissions).

  1. Open the server and go to its Firewall tab.
  2. Add a rule that accepts SSH first: Add a rule, direction In, to the server, action Accept, protocol TCP, ports 22.
  3. Click Turn on and confirm.

Warning: With the firewall on and the default inbound action Drop, everything coming in is dropped until a rule accepts it. Every dialog that changes inbound traffic (turning the firewall on, the defaults, adding, changing or deleting a rule, applying a template) warns when the result would drop SSH from the internet. It is a warning only: the change can still be made.

The tab shows the state on the node: Applied on the node, Waiting for the node or Failed: with the reason. A change normally reaches the node in a few seconds.

To change the defaults, use Default actions and Save defaults. To switch filtering off, click Turn off; the rules are kept for later.

Rules#

Field Values
Direction In, to the server or Out, from the server
Action Accept or Drop
Protocol Any, TCP, UDP, ICMP (IPv4), ICMPv6
Ports TCP and UDP only: one port, a range such as 8000-8100, or up to 15 of them separated by commas. Empty for every port.
From / To Addresses: up to 15 IPv4 or IPv6 addresses or networks, separated by commas, empty for any address. Or Countries (see below).
Comment optional, up to 60 characters

A network must be given by its first address: 203.0.113.0/24, not 203.0.113.7/24. Addresses are stored in a canonical form, so 2001:DB8:0::1/128 is shown as 2001:db8::1.

Rules can be edited, moved up and down, and deleted. A server can have at most 100 rules, including the rules of templates its hosting plan requires.

Rate limits#

A rate limit is an option on a rule, not a rule of its own. Click Rate limit on the rule and set:

Field Values
New connections 1 to 10000
Per Second, Minute, Hour
Counted For each address on its own, or For all of the rule's traffic together
  • On an accept rule, new connections up to the rate are accepted; those over it go on to the next rules, then the default. Example: SSH accepted at 6 a minute per address stops password guessing without a separate drop rule.
  • On a drop rule, new connections over the rate are dropped; those under it go on to the next rules. Use it as a flood guard in front of an accept rule.

Only new connections are limited; open connections are never limited. The node allows a short burst of 5 before the limit applies.

Countries#

Instead of addresses, a rule can name up to 30 countries by their two-letter codes, such as CN, RU. A rule names addresses or countries, never both: use two rules for both. A country rule matches IPv4 and IPv6.

The country ranges come from DB-IP's "IP to Country Lite" database (CC BY 4.0, "IP Geolocation by DB-IP"). Each node downloads it itself, only while one of its servers has a country rule, and refreshes it monthly. The tab shows the state of the data under Country data:.

Note: Until the node has the country file (first download, or a failed download), a country rule matches no address: a drop by country drops nobody, and an accept by country lets nobody in through it.

For a node without internet access, the download URL can be pointed at a mirror with the agent setting firewall_countries_url.

Hit counters#

Every rule and both defaults show how many packets they matched and when they last matched. Counts survive reloads and agent restarts. Moving or editing another rule does not reset a rule's count; changing the rule itself starts its count again. Counts are only shown when the node has exactly the rules the panel wants, so a count never appears next to the wrong rule.

Dropped packets log#

Log dropped packets (off by default) records what the drop rules and a drop default drop. The Dropped packets panel lists them with time, direction, protocol, source and destination, and which rule dropped each (Dropped by).

Logging is limited to 10 packets a minute after a burst of 20 per server, and the node keeps the last 100 packets per server in memory only: nothing is written to the panel's database, and the list empties when the node restarts. On the node the kernel lines carry the prefix vmfw:

journalctl -k | grep vmfw

Rate limits, countries, hit counters and the log need agent 0.45.0 or later on the node. On an older node they are hidden and the tab says "Rate limits, countries, hit counters and the log of dropped packets need a newer agent on this server's node: update the node." See Agent updates.

Firewall templates#

A firewall template is a named, ordered set of rules with optional default actions, so a customer can give a server a ready set of rules without writing them.

Templates are managed in Security › Firewall templates, by administrators and resellers (customers have no such page):

  • Administrators make panel templates, offered to every server, and may make one for a reseller.
  • A reseller makes its own, offered to the servers of its customers, and can read the panel's.

Two examples come with the panel: Web server (in TCP 22, 80, 443; ICMP and ICMPv6 in) and Block outbound mail (out TCP 25, 465, 587 dropped).

To create one:

  1. Go to Security › Firewall templates.
  2. Give it a Name, optionally Default in and Default out, and click Make template.
  3. Open it and add its rules.

The list shows what uses each template: the servers that require it and the hosting plans that require it.

Apply a template to a server#

On the server's Firewall tab, click Apply a template, choose one and click Apply template. The dialog lists the rules it adds, the default actions it sets and the SSH warning for the result.

Applying copies the template: its rules are added at the end of the server's own rules, where they can be edited or deleted like any other, and its default actions become the server's own. A later change of the template does not reach the server. A template whose rules do not fit in the room left of 100 is refused, and the dialog says how many rules fit.

Required templates#

A hosting plan can require templates, in Customers › Hosting plans, section Required firewall templates. A server created from that plan:

  • gets the templates linked, with its firewall on, before it first starts;
  • has the required rules first, in order, then its own rules, so its own accept cannot undo a required drop;
  • takes a default action from the first required template that sets one, in place of its own.

A change of a required template (rules, defaults, or deleting it) is sent to every server that requires it. The owner sees a locked block "Required by your provider:" with the template's name and cannot remove it or turn the firewall off. Administrators can remove any required template, and a reseller its own, with Remove on the server's Firewall tab; they must remove it before they can turn the firewall off.

Servers that exist when a hosting plan starts requiring a template are not changed. See Hosting plans.

Note: If you upgraded from a panel version before templates were copied, run php artisan vmstack:copy-linked-firewall-templates once. It turns old links that no hosting plan requires into the server's own rules; the node gets exactly the same rules. Until it has run, such links show as "Linked" with Remove.

When changes are refused#

Firewall changes are refused while the server is suspended, locked, being built or deleted, or in error, and while its node does not answer. The tab says why and its buttons are disabled. A server in rescue takes changes, so its owner can let SSH in.

On the node#

The agent keeps the firewall in its own nftables table inet vmstack_fw, rendered as a whole and loaded in one transaction. It checks the table every minute and loads it again when it is missing or changed, for example after systemctl restart nftables. To look at it:

nft list table inet vmstack_fw

The panel compares the node's firewall with its own at each node poll. A difference marks the firewall Waiting and sends it again (after 10 minutes, an hour after two failures in a row, 6 hours after three or more).

The API offers the same operations, including the activity (counters and dropped packets); see the API reference. Changes are recorded in the audit log as firewall.changed and firewall_template.created|updated|deleted.

For common problems, see Networking troubleshooting.