Wireguard works even without setting a tunnel IP address, i.e. it's enough to set the AllowedIPs, endpoint addresses, private and public keys.
In the docs of OpnSense, there is the following warning:
Note: The tunnel address must be in CIDR notation and must be a unique IP and subnet for your network. [..] Do not use a tunnel address that is a /32 (IPv4) or a /128 (IPv6)
and pfSense has a likely explanation:
Note: Routes are not automatically created in the system routing table. Routes for networks other than the tunnel network itself must be configured separately using static or dynamic routes.
Searching on the internet does not yield many explanations:
- Reddit: Confusion about subnet masks
- Reddit: Help on /24 and /32 when using as a VPN Server
- Reddit: differences between /8, /16 etc... What they are used for?
The subnet does not seem to have any functionality, we did some testing:
- It's not related to local traffic routing, i.e. routing to a second connected peer works with and without a subnet which contains both peers.
- it's not related to "staying on the interface" vs passing through the kernel. In both cases we could control the traffic using firewall rules.
So, what is the purpose of the subnet mask in the tunnel ip?