← Home
Port Check Tool
2026-11-28 21:27

Defending the Perimeter: Modern nftables Hardening and SSH Dynamic Rate Limiting

Securing edge infrastructure requires deterministic control over ingress traffic before packets reach application listeners. While legacy iptables configurations are common, modern Linux kernels leverage nftables for atomic ruleset updates, unified address family handling, and significantly lower CPU overhead during high-volume connection spikes. Implementing stateful inspection and packet rate limiting at the netfilter stage serves as the primary line of defense against port scanning, syn-flood attacks, and credential stuffing attempts.

Building a Stateful nftables Ingress Baseline

A resilient firewall configuration begins with an explicit default drop policy for ingress packets, followed by permissive handling of established connections and loopback traffic. By using stateful connection tracking (conntrack), the kernel bypasses deep rule inspection for packets matching verified flows, drastically reducing latency for established web traffic.

#!/usr/sbin/nft -f

# Flush existing ruleset
flush ruleset

table inet filter {
    chain input {
        type filter hook input priority filter; policy drop;

        # Accept loopback traffic
        iif "lo" accept

        # Accept established and related connections
        ct state established,related accept

        # Drop invalid packets immediately
        ct state invalid drop

        # Allow limited ICMP echo requests (ping)
        ip protocol icmp icmp type echo-request limit rate 5/second accept
        ip6 nexthdr ipv6-icmp icmpv6 type echo-request limit rate 5/second accept
    }
}

Mitigating SSH Abuse with Dynamic Connection Metering

Automated bots continuously sweep default and alternate ports looking for open SSH daemons. Rather than relying solely on user-space log parsers, you can leverage native nftables meters to dynamically throttle incoming TCP handshakes per source IP. This approach drops rapid-fire authentication probes directly in kernel space before the SSH handshake consumes user-space resources.

# Add dynamic metering inside the input chain for TCP port 22
add rule inet filter input tcp dport 22 ct state new meter ssh_meter { ip saddr limit rate over 3/minute burst 2 packets } counter drop
add rule inet filter input tcp dport 22 ct state new counter accept

Isolating Web Ingress and Auditing Network Sockets

Production reverse proxies such as Nginx should only expose standardized TLS and HTTP interfaces to the public internet, keeping administrative endpoints bound to internal interfaces or overlay networks (such as WireGuard). Validate your active socket state using modern socket statistics, then declare strict ingress parameters for reverse proxy ports.

# Audit all active listening sockets on the host
sudo ss -tulpn

# Expose reverse proxy ports with TCP SYN flood protection
sudo nft add rule inet filter input tcp dport { 80, 443 } tcp flags syn / fin,syn,rst,ack limit rate 500/second burst 100 packets accept
sudo nft add rule inet filter input tcp dport { 80, 443 } ct state new accept