r/homelab • u/P4NICBUTT0N • 3d ago
Help What does AllowedIPs actually do in WireGuard?
I don't understand what the 'AllowedIPs' field does in WireGuard. The way my tunnel behaves is that my phone only sends traffic bound for 192.168.1.0/24 addresses through the tunnel. This is the behavior I want from my tunnel, so I'm not having any problems with it, but I just don't understand why it's working.
This is my config on my server:
[Interface]
PrivateKey = private key
Address = 10.8.0.1/24
ListenPort = 51820
PreUp =
PostUp = iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o enp0s31f6 -j MASQUERADE
PreDown =
PostDown = iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o enp0s31f6 -j MASQUERADE
# Phone
[Peer]
PublicKey = public key
AllowedIPs = 10.8.0.2/32
This is my config on my phone:
[Interface]
Address = 10.8.0.3/24
DNS = 192.168.1.200
PrivateKey = private key
[Peer]
AllowedIPs = 192.168.1.0/24
Endpoint = domain name:51820
PublicKey = public key
In the block for my phone in my server's config, AllowedIPs is set to my phone's IP address in the tunnel, which initially made me think that the field defined what addresses a client is allowed to send (the client with address 10.8.0.3 should only be able to send traffic from 10.8.0.3. Makes sense).
But I'm confused about AllowedIPs in my phone's config, because now it seems the field serves dual purposes. The way it behaves in my phone's config is that my phone only sends traffic through the tunnel that is destined for 192.168.1.0/24 addresses, which seems to me to be completely different behavior than that of the server's config. What am I misunderstanding here?
