Persistent 0.0.0.0 Routes and SSH Blockage in nftables
When an SSH session drops halfway through, the first thing I usually check is the routing table. On a system that relies on nftables, a stale default route pointing to 0.0.0.0/0 that survived a network interface change can silently swallow the packets destined for the SSH server, making the client hang until it times out. Below is a hands‑on walk‑through of how I detect, diagnose, and fix this issue on a modern Linux host.
Why a 0.0.0.0 Route Matters
0.0.0.0/0 is the default gateway. If it points to a downed interface or a gateway that no longer exists, any packet that doesn’t match a more specific route gets sent there. In a system that uses nftables for filtering, the default route can be hidden behind a rule that drops traffic to the gateway’s IP. SSH packets go to the gateway, get dropped, and the connection stalls. The problem is often invisible because ip route show still lists the default route even after the interface is removed; the kernel keeps it until you flush it or reboot.
Quick Checklist
- Verify the routing table
ip route show - Check interface status
ip link show - Inspect nftables rules
nft list ruleset - Test connectivity to the gateway
ping -c 3 <gateway-ip>
If any of these steps reveal a mismatch, you’re probably dealing with a stale default route.
Step‑by‑Step Diagnosis
1. Inspect the Routing Table
$ ip route show
default via 192.168.1.1 dev eth0 proto dhcp metric 100
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.42 metric 100
If eth0 is down, the default route is still sitting there. The kernel will keep it until you explicitly remove it.
2. Confirm Interface State
$ ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
If you see state DOWN or state UNKNOWN, that route is useless.
3. Look for nftables Rules Blocking the Gateway
$ nft list ruleset | grep -i drop
table inet filter {
chain input {
type filter hook input priority 0; policy accept;
ip daddr 192.168.1.1 drop
}
}
A rule that drops traffic to the gateway IP will silently drop packets that are routed there.
4. Test Reachability
$ ping -c 3 192.168.1.1
If the ping fails, the gateway is unreachable, confirming the route is broken.
Fixing the Route
Option A: Remove the Stale Route
sudo ip route del default via 192.168.1.1 dev eth0
Delete the route from the kernel. To keep it from re‑appearing after a reboot, edit /etc/network/interfaces, /etc/netplan/*.yaml, or the relevant NetworkManager configuration.
Option B: Replace the Route with the Correct Gateway
If the network changed and you now have a new gateway, update the route:
sudo ip route replace default via 10.0.0.1 dev eth1
Add the same line to your network configuration file to make it persistent.
Option C: Flush All Routes and Re‑apply
Sometimes the routing table gets corrupted. A clean slate can help:
sudo ip route flush all
# Re‑apply DHCP or static config
sudo dhclient eth0
nftables Adjustments
If the problem is a rule that drops traffic to the old gateway, delete or modify it.
sudo nft delete rule inet filter input ip daddr 192.168.1.1 drop
Or, if you want to keep a generic drop rule but allow the new gateway:
sudo nft add rule inet filter input ip daddr 10.0.0.1 accept
Remember: nftables rules are evaluated in order. Placing an accept before a drop for the same destination IP ensures the packet is allowed.
Practical Tips for Avoiding the Problem
| Practice | Why It Helps | Example |
|---|---|---|
Use systemd-networkd or NetworkManager | They automatically clean up routes when an interface goes down. | systemd-networkd config: Network=... |
Add post-up hooks to flush routes | Guarantees no stale routes after DHCP renewals. | post-up ip route flush dev eth0 |
| Audit nftables after every change | Prevents accidental drops. | `nft list ruleset |
| Enable persistent nftables | Rules survive reboots without manual reload. | systemctl enable nftables |
| Log dropped packets | Helps identify which rule is causing the block. | nft add rule inet filter input log prefix "nft-drop: " |
Real‑World Example
A colleague ran a container‑based web server on a Debian 12 host. After moving the host to a new VLAN, SSH stopped responding. The routing table still had the old default route:
default via 172.16.0.1 dev eth0
eth0 was now part of the new VLAN, but the gateway had changed to 172.16.1.1. The host’s nftables rules included:
ip daddr 172.16.0.1 drop
The SSH packets were routed to 172.16.0.1 and dropped. Fixing the route and deleting the stale rule restored SSH in under five minutes.
Trade‑offs and Caveats
- Flushing all routes can temporarily disrupt all network traffic. Use it during maintenance windows or with a console connection.
- Hard‑coding gateways in
/etc/network/interfacesis simple but brittle if the network changes. Consider DHCP orsystemd-networkdwithRouteMetric. - Deleting nftables rules is quick but may remove legitimate security controls if the rule was part of a broader policy. Always review the rule set before deletion.
- Persistent nftables is convenient, but if you rely on dynamic rule generation (e.g., from a firewall management tool), ensure the tool re‑applies rules after a reboot.
When to Escalate
If, after cleaning routes and nftables, the SSH issue persists, check:
- Kernel routing cache –
ip route flush cache. - SELinux/AppArmor – ensure they aren’t blocking outbound traffic.
- Hardware issues – faulty NIC or cable can cause intermittent drops.
- External firewall – sometimes the upstream firewall blocks the new gateway.
Useful Resources
- nftables documentation on kernel.org
- Network configuration guide on Debian.org
- Systemd‑networkd reference on systemd.io
These references provide deeper dives into nftables syntax, network configuration, and systemd networking.
See also
- Application-Level Firewalls
- Fixing a Midnight DNS Loop: When nftables Drops Queries on VPN Bridge
- Fixing “Permission denied (publickey)” after moving /etc/ssh/sshd_config
- Stopping /var/log from Dooming Your Server with a Simple tmpfs Trick
- Debugging flaky DNS on a Raspberry Pi bridge setup with nftables rules
- Nftables log‑filter tricks to find hidden routing loops on a bridged LAN