I am using wg-quick
to open a VPN connection. I can see the utility is setting some nft
rules and I would like to understand them. I have moderate knowledge of iptables but none of nftables.
Here is the Wireguard config file:
[Interface]
PrivateKey = xxxxx
Address = 10.2.0.2/32
DNS = 10.2.0.1
[Peer]
PublicKey = yyyyyyyy
AllowedIPs = 0.0.0.0/0
Endpoint = 185.159.157.129:51820
When I invoke wg-quick
I see this:
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.2.0.2/32 dev wg0
[#] ip link set mtu 1420 up dev wg0
[#] resolvconf -a tun.wg0 -m 0 -x
[#] wg set wg0 fwmark 51820
[#] ip -4 route add 0.0.0.0/0 dev wg0 table 51820
[#] ip -4 rule add not fwmark 51820 table 51820
[#] ip -4 rule add table main suppress_prefixlength 0
[#] sysctl -q net.ipv4.conf.all.src_valid_mark=1
[#] nft -f /dev/fd/63
Here is a dump of the nft
rules:
table ip wg-quick-wg0 {
chain preraw {
type filter hook prerouting priority raw; policy accept;
iifname != "wg0" ip daddr 10.2.0.2 fib saddr type != local drop
}
chain premangle {
type filter hook prerouting priority mangle; policy accept;
meta l4proto udp meta mark set ct mark
}
chain postmangle {
type filter hook postrouting priority mangle; policy accept;
meta l4proto udp meta mark 0x0000ca6c ct mark set meta mark
}
}
What do these nft
rules mean, what are they for, and why are they needed?