I’m currently trying to adapt a simple nft table for WireGuard to firewalld, but I’m new to firewalld and am uncertain about several things.
The nftables script
#!/usr/sbin/nft -f
table inet WGSERVER {
chain FORWARD {
type filter hook forward priority filter; policy drop;
iifname "wg-server" accept
oifname "wg-server" accept
}
chain NAT {
type nat hook postrouting priority srcnat; policy accept;
#ip saddr 10.0.0.0/24 oifname "eth0" masquerade
iifname "wg-server" ip saddr 10.0.0.0/24 oifname "eth0" jump do_masquerade
}
# [CVE-2021-3773]
chain do_masquerade {
meta iif > 0 th sport < 16384 th dport >= 32768 masquerade random
masquerade
}
}
A bit of context:
-
oifname "wg-server" accept
is for allowing clients assigned with IPv6 addresses to be able to receive connection. - The NAT rule is very specific, as I used to also have OpenVPN on the server, and the server was constantly probed/attacked, so I wanted to prevent abuse or weird things happening.
Questions:
- Does masquerade implicitly allow IPv4 forwarding? Is the FORWARD chain not needed if IPV4 only?
- Does WireGuard filter invalid packets, so that the rules don’t need to be so specific?
- Is working with firewalld the only option here? I tried directly adding this table, but due to the rules in firewalld table, packets accepted by this table is later rejected in firewalld table.
- Should WireGuard interface (wg-server) be added to the same zone as WAN (eth0)?
If not, how to allow forwarding between wg-server and eth0?
If yes, should I use –add-forward? Is it only between interfaces, contrary to the nft rule and the explanation on the website “if the packet is destined to the any interface in the zone home then go ahead and accept it.” I definitely do not want to allow forwarding random Internet traffic oneth0
. (Also if I add more interface/source, like OpenVPN to the zone, the --add-forward option would allow forwarding between all of them.) - For NAT, is the equivalence –add-masquerade? Is masquerade also cross-interface only? I.E. if peers connect to each other with their private IPs, their packets will not be masqueraded. Does this option also masquerade traffic from eth0 to wg-server, if I receive a malformed packet on eth0 that says destined to 10.0.0.2?
- The CVE mitigation is nice to have, any chance to replicate it?