Nftables

Introduction

  • Successor to iptables Alt text

Commands

  • nft list ruleset

  • nft -a list ruleset: list with handle to use for other delete and add commands

  • nft -i: interactive mode

  • sysctl -w net.ipv4.conf.all.log_matians=1: log kernel packet

    • view by: tail -f /var/log/kern.log

  • sysctl -w net.ipv4.conf.all.route_localnet=1: allow routing to 127.0.0.x address

Chains

  • Rule action:

    • drop: silently drop traffic

    • reject: response to client with icmp message

    • accept: accept traffic

    • jump: Jump to chain and go back to this position

    • goto: goto chain and will not go back

VMAP

Set

  • nft add element ip filter allowed_ips { 192.16.1.1 - 192.168.1.10}: add a range to set

Configure firewall policies

  • load configuration: nft -f input.nft

  • Command to monitor:

    • conntrack -L: list connection state table

    • conntrack -L -p icmp: list icmp packets

Input Chain

Block traffic after 3 attempts

Get statistics of outbound connections

  • Any new connection will log userid, destination address and port

  • Viewing statistics using: nft [-N] get ruleset, -N to do reverse DNS query of ip address

Source Network Address Translation (SNAT)

  • Another way to do above

  • Delete/Add rules

  • Insert rule

Natting in load balancing way

Destination Network Address Translation (DNAT)

Change address when packets arrive at the firewall

  • nft add element ip nat ip_map { 1234 : 1.1.1.1 . 1234 }: add element to the map

Change address when packets leave the firewall

Redirect Port

  • Above command will create the following ruleset

Reference

Last updated