WireGuard AllowedIPs Calculator

Use the following form when you need to calculate complex AllowedIPs settings for a WireGuard peer, by subtracting the “disallowed” IP address blocks from the “allowed” IP address blocks:

AllowedIPs =

For example, say you wanted to route everything in the block of IP addresses through a WireGuard peer — except you also wanted to exclude the smaller block from it. In the Allowed IPs field, input; in the Disallowed IPs field, input; and click the Calculate button. This is the result you’ll get (which is what you enter into your WireGuard config):

AllowedIPs =,,,,,,,,,,,,,,,

Or as another example, say you wanted to route everything but the standard private, local, or link-scoped IP address blocks through a WireGuard peer. In the Allowed IPs field, input, ::/0; in the Disallowed IPs field, input,,,,,,, fc00::/7, fe80::/10; and click the Calculate button. This is the result you’ll get:

AllowedIPs =,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ::/1, 8000::/2, c000::/3, e000::/4, f000::/5, f800::/6, fe00::/9, fec0::/10, ff00::/8


You use the AllowedIPs setting of WireGuard to configure which blocks of IP addresses should be routed through which remote WireGuard peers. If you want to access everything through a peer, configure its AllowedIPs setting to the following:

AllowedIPs =, ::/0

This indicates to WireGuard that all IPv4 addresses ( and all IPv6 addresses (::/0) should be routed through the peer. Note that you can specify multiple blocks of addresses on the same line, separated by commas, like above; or you can specify them individually on separate lines, like below:

AllowedIPs =
AllowedIPs = ::/0

If you want to access just a single block of IP addresses through a WireGuard peer, like say a block of IP addresses at a remote site that range from to, you’d set the AllowedIPs for it to the following:

AllowedIPs =

But what if you want the inverse, where you want everything except a single block (or two or three specific blocks) to be routed through a WireGuard peer? In many cases, you have subtract the exceptions from the block of allowed addresses, and set AllowedIPs to the resulting (often long) list of blocks.

For example, say you want to route all Internet traffic through a WireGuard peer, except that you don’t want to route the traffic of your internal networks through it, which use various subnets within the private-use block. To make that happen with the AllowedIPs setting, you’d have to configure the peer with the following AllowedIPs:

AllowedIPs =,,,,,,,

That’s the list of blocks you get when you subtract from — conceptually you might express it like the following:

AllowedIPs = +, -

Or another way of expressing it might be:

AllowedIPs =
DisallowedIPs =

A Better Alternative

As you can see, subtracting one block of IP address from another block can result in a painfully long list of blocks to add to the AllowedIPs setting. On some platforms, like mobile phones, you don’t have any other options — but on Linux, you have some powerful routing tools available that can simplify the situation.

In most cases, you can simply add a route to your main routing table to “subtract” a block of IP addresses from those routed via the WireGuard tunnel. And you may even find that the necessary route already exists — in which case you don’t have to do anything at all.

For example, say you want to route everything in the block to a WireGuard peer, except for Instead of subtracting from with the above calculator, and setting the peer’s AllowedIPs to the result, just set the peer’s AllowedIPs to the full block. Outside of WireGuard, add an explicit route for to your main routing table. Because has a longer prefix length than (/24 vs /8), the Linux routing engine will automatically use the route for over the route for

In fact, you may find that you have the necessary route for the exceptional block already set up — run the command ip route show table main (or just ip route, which by default lists the routes of your main routing table) on the host to see what (IPv4) routes you have already:

$ ip route show table main
default via dev eth0 proto dhcp metric 1000 dev wg0 scope link dev eth0 proto kernel scope link src metric 100

If do you see a route listed for your exceptional block ( in our example), you won’t have to add anything. If you don’t see it listed, however, you’ll have to add the route yourself. Fortunately, this easy — you just need to know the IP address of the gateway for the block, and the network interface to get there. Often, this will be the same as your default gateway (the line beginning with default in the above listing).

The simplest way to do this is to add the following ip route add and ip route del commands to the PreUp and PostDown scripts in your WireGuard config. To add a route for the block with as the gateway using the eth0 interface, add the following PreUp and PostDown settings to the [Interface] section of your WireGuard config:

PrivateKey = ...
PreUp = ip route add via dev eth0
PostDown = ip route del via dev eth0

PublicKey = ...
AllowedIPs =

Note that you can have multiple PreUp and PostDown lines in your config (similar to AllowedIPs). Multiple PreUp or PostDown lines are equivalent to a single PreUp or PostDown line joined together by semicolons.

Also note that the ip route commands above apply only to IPv4 addresses — for IPv6 addresses, you have to add the -6 flag (eg ip -6 route show table main).