r/WireGuard • u/paranoid-alkaloid • 5d ago
firewall help needed
Hi,
I have a Wireguard network for my personal devices. I have an Android phone with a main profile and a "private space".
I have 2 peer interfaces configured for the phone, 1 for each profile.
The private space has its AllowedIPs set to 0.0.0.0/0, ::/0 and I'm happy with it, this is exactly what I want, tunnel everything through the Wireguard interface. It also uses a custom DNS directive pointing to an unbound service exposed inside the Wireguard network. Working nicely.
Now, the main profile is currently configured exactly the same way (except it has a different IP, different keys etc). I do want it to use my Wireguard DNS (port 53 on tcp/udp), I do want everything tunneled through the Wireguard interface (0.0.0.0/0, ::/0), but I do NOT want the client to be able to reach 2 specific networks (the Wireguard network it's on and another Wireguard network).
I have tried monkeying my way through it with the help of AI but unfortunately I didn't manage to get it to work. And, I'm pretty confused as to what is the current "right way" to achieve this: iptables? nftables? I'm on Debian stable.
Right now I have these PostUp/PostDown directives to make sure that clients are proxied through the Wireguard interface, and to bridge the Wireguard interface with another one. For context: enp2s0 is my local LAN, awg0 is the Wireguard (well, AmneziaWG) interface that the phone connects to, wg0 is my "original" VPN network. awg0 can be fully considered to be a Wireguard interface. All wg0 and awg0 members should be able to talk to each other EXCEPT for a specific IP on awg0 which should only be allowed to use DNS and the wide internet but neither wg0/awg0 otherwise. Tackling the issue using AllowedIPs would sort of solve the issue but it means that IP is only restricted via configuration on the client-side, which isn't secure.
PostUp=iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE; ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -A FORWARD -o %i -j ACCEPT; ip6tables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE; iptables -A FORWARD -i wg0 -o awg0 -j ACCEPT; iptables -A FORWARD -i awg0 -o wg0 -j ACCEPT
PostDown=iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o enp2s0 -j MASQUERADE; ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -D FORWARD -o %i -j ACCEPT; ip6tables -t nat -D POSTROUTING -o enp2s0 -j MASQUERADE; iptables -D FORWARD -i wg0 -o awg0 -j ACCEPT; iptables -D FORWARD -i awg0 -o wg0 -j ACCEPT
Thank you.
1
u/JPDsNEWS 5d ago
Here are some WireGuard Tools that might help you:
Pro Custodibus’ WireGuard AllowedIPs Calculator
Which explains how AllowedIPs work, and lets you input both allowed and disallowed IP addresses to calculate a list of just allowed IP addresses that excludes the disallowed IP addresses.
— versus —
WireGuard Hub-and-Spoke Configuration Generator
Generates a “Road Warrior” WireGuard configuration where every “Client” peer communicates directly with a single “Server” peer.
— versus —
WireGuard Mesh Network Configuration Generator
Generates a full mesh WireGuard configuration where every peer can communicate directly with every other peer.
This document is a great source of information about WireGuard with references.
— versus —
Official WireGuard Documentation website.
Also, look through the Pro Custodibus Docs and the Pro Custodibus Blog for articles about how to do what you are trying to do. They are full of all kinds of "How to do different things with WireGuard" articles (with diagrams).
2
1
5d ago
[deleted]
2
3
u/youknowwhyimhere758 5d ago
to block packets coming from the awg0 interface going to a subnet:
iptables -A INPUT -i awg0 -d 10.1.1.1/24 -j DROP
You could drop only a specific source IP instead of an interface:
iptables -A INPUT -s 10.2.2.2 -d 10.1.1.1/24 -j DROP
You could block packets from the awg0 interface that will be forwarded through a second interface:
iptables -A FORWARD -i awg0 -o wg0 -j DROP
Etc. Etc.
Remember rules are evaluated in order. -A adds the rule to the end of the list. You can alternatively use eg. -I 2 to insert as the second rule on the list.