Quick answer
How do I set up an nftables firewall on a dedicated server?
Write the rules in /etc/nftables.conf with an input chain set to policy drop, accept established traffic, loopback, ICMPv6 neighbour discovery and the ports in use, check it with nft -c -f, then load it under a 5-minute rollback timer. CryptoDedicated machines have no KVM console, so the timer matters. Servers start at $83.69 per 30 days, paid in crypto.
In brief
- One file: /etc/nftables.conf holds IPv4 and IPv6 rules together in an inet table.
- Default drop inbound: only listed ports open; outbound stays open, except port 25 closed by the network.
- Never skip ICMPv6: without neighbour discovery, the IPv6 /64 of the machine stops working.
- Safety net:
systemd-run --on-active=300restores the previous ruleset unless the timer is cancelled. - Persistence:
systemctl enable nftablesloads the file at every boot.
Which rules does a server ruleset need?
Eight rules make a complete inbound policy for a typical server; everything else is a port added to one set.
| Rule | nftables expression | Purpose |
|---|---|---|
| Connection tracking | ct state vmap { established : accept, related : accept, invalid : drop } | Replies to outgoing traffic pass; broken packets drop |
| Loopback | iifname "lo" accept | Local services talking to each other |
| ICMPv6 essentials | icmpv6 type { nd-neighbor-solicit, nd-neighbor-advert, nd-router-advert, … } accept | Keeps IPv6 reachable |
| Ping, rate limited | icmp type echo-request limit rate 5/second accept | Monitoring without flood |
| SSH, rate limited | tcp dport 22 ct state new limit rate 15/minute accept | Admin access, slows brute force |
| Web | tcp dport { 80, 443 } accept | HTTP and HTTPS |
| Admin-only ports | ip saddr @admins tcp dport 8006 accept | Panels reachable from known IPs only |
| Default | policy drop | Everything not listed |
How do I apply the firewall without locking myself out?
Install and back up
apt install nftables, then save the current rules with nft list ruleset > /root/nft-before.conf.
Write /etc/nftables.conf
Use the file below; add the ports of the services actually running, found with ss -tulpn.
Check the syntax
nft -c -f /etc/nftables.conf parses the file without loading it and prints the faulty line if any.
Arm the rollback timer
systemd-run --on-active=300 --unit=nft-rollback starts a job that reloads the backup in 5 minutes.
Load the new rules
nft -f /etc/nftables.conf applies them at once, atomically.
Test from a second terminal
Open a fresh SSH session and reach each service. If all works, stop the timer with systemctl stop nft-rollback.timer.
Enable at boot
systemctl enable nftables so the same file loads after every reboot.
#!/usr/sbin/nft -f
flush ruleset
table inet firewall {
set admins {
type ipv4_addr
elements = { 198.51.100.7 }
}
chain inbound {
type filter hook input priority 0; policy drop;
ct state vmap { established : accept, related : accept, invalid : drop }
iifname "lo" accept
icmp type echo-request limit rate 5/second accept
icmpv6 type { nd-neighbor-solicit, nd-neighbor-advert, nd-router-advert, nd-router-solicit, echo-request, packet-too-big, time-exceeded, parameter-problem, destination-unreachable } accept
tcp dport 22 ct state new limit rate 15/minute accept
tcp dport { 80, 443 } accept
ip saddr @admins tcp dport 8006 accept
}
chain forward {
type filter hook forward priority 0; policy drop;
}
}apt install -y nftables
nft list ruleset > /root/nft-before.conf
nft -c -f /etc/nftables.conf
systemd-run --on-active=300 --unit=nft-rollback /bin/sh -c 'nft flush ruleset; nft -f /root/nft-before.conf'
nft -f /etc/nftables.conf
# from a NEW terminal: ssh in, test the web ports, then
systemctl stop nft-rollback.timer
systemctl enable nftablesWhy is a rollback timer worth the extra line here?
Because CryptoDedicated gives no IPMI or KVM console: a ruleset that drops SSH leaves only a reinstall from the dashboard, which erases both drives. The timer turns that risk into a five-minute wait.
systemd-run --on-active=300 creates a transient timer and service. If the new rules cut the connection, nothing needs to be done: five minutes later the old ruleset returns and SSH answers again. If everything works, systemctl stop nft-rollback.timer cancels it. The same habit applies to SSH changes, as described in how to secure a new dedicated server.
How do I add NAT for VPN clients or virtual machines?
Add a forward rule for the private subnet and a separate nat table with a masquerade rule on the outgoing interface. For a WireGuard tunnel on 10.8.0.0/24 the additions are:
- in
chain forward:iifname "wg0" acceptandoifname "wg0" ct state established,related accept - a new table
table ip natwithchain postrouting { type nat hook postrouting priority srcnat; ip saddr 10.8.0.0/24 oifname "eno1" masquerade } udp dport 51820 acceptin the inbound chain
The full tunnel setup is in the WireGuard VPN server guide; the same pattern serves Proxmox VMs on vmbr1.
What does the firewall not protect against?
Volumetric floods that fill the 1 Gbit/s port before packets reach the machine. CryptoDedicated sells no separate DDoS product; protection is whatever the datacenter network filters by default. A local firewall still helps against smaller floods and scans:
limit rateandmeterexpressions cap new connections per source;- services that do not need to be public bind to 127.0.0.1 or sit behind the admins set;
- game servers expose one port each, as in the Minecraft server guide.
According to CryptoDedicated's survey of 30 October 2026, 16 of 34 dedicated-server sellers kept the right to ask for ID on some orders; CryptoDedicated asks for none, which makes the customer's own firewall the first line of defence.
Frequently asked questions
Should I use ufw or firewalld instead of nftables?
Both work and write nftables rules underneath on current systems. AlmaLinux 10 and Rocky Linux 10 ship firewalld by default; on Debian and Ubuntu a plain nftables.conf is the most transparent option.
Do I need rules for outgoing traffic?
Not usually. Outbound stays open, except port 25, which the network closes on every CryptoDedicated machine.
Why does IPv6 stop working after enabling the firewall?
ICMPv6 neighbour discovery is being dropped. Allow nd-neighbor-solicit, nd-neighbor-advert and nd-router-advert as in the ruleset above.
Does Docker conflict with nftables.conf?
Docker adds its own rules and a flush ruleset at boot removes them until Docker restarts. Restart Docker after loading the file, or keep Docker's chains separate.
Verdict
- A single inet table with policy drop, ICMPv6 essentials and named port sets is all a dedicated server needs inbound.
- On a CryptoDedicated machine, always arm the rollback timer before loading rules: there is no console to undo a mistake.
- Pair the firewall with key-only SSH; neither replaces the other.
Sources (4)
- Simple ruleset for a server — nftables wiki (read 2026-11-30)
- nft(8) — netfilter project (read 2026-11-30)
- nftables — Debian Wiki (read 2026-11-30)
- systemd-run(1) — systemd (read 2026-11-30)
A server to firewall your way
Ryzen 5600, 6 cores / 12 threads, IPv4 plus an IPv6 /64: $83.69 per 30 days in crypto.
- Sold by CryptoDedicated LLC, New Mexico, USA
- Machine ready within 1 hour of confirmation
- No KYC, no email required
- Downtime credited back to the balance
Read next
- Secure a new serverSecure a new dedicated server in 7 steps: updates, a sudo user, key-only SSH, auto patches, fail2ban, a port audit. Machines from $83.69.
- WireGuard VPN serverSet up a WireGuard VPN server on a dedicated machine: keys, wg0.conf, forwarding, nftables NAT and a client file. 1 Gbit/s port from $83.69.
- Minecraft serverHost a Minecraft Java server on a dedicated machine: Java 25, server.jar, EULA, systemd, port 25565. 8-core Ryzen 9700X from $154.54.
- Acceptable useCryptoDedicated acceptable use policy: what may and may not run on a dedicated server, how abuse reports are handled, and when a machine is suspended.