How to add a static route to wireguard interface

I would like to add a static route to a wireguard interface.
I tried to do it via Luci, but the first problem is that the wg0 interface does not show up as an interface in Luci.
In another thread I have read that it needs to be added manually. So I created an interface manually.


But when I then create a static route with that interface, the route does not show up in the routing table.

Hi,

If the wireguard client is connected, you can use the following command to add the route:

ip route add 192.168.11.0/24 dev wg0

If you are able to access the router over SSH, you can set a PostUp command in the interface config file (usually /etc/wireguard/wg0.conf

You can edit the file using nano: nano /etc/wireguard/wg0.conf

you should see something like this:

[Interface]
Address = 192.168.11.0/24
Address = xxxx::1/xx
PrivateKey = lonGsTringOfRandomcHars

[Peer]
…other stuff

You want to add two lines at the bottom of the [Interface] section, like so:

[Interface]
Address = 192.168.11.0/24
Address = xxxx::1/xx
PrivateKey = lonGsTringOfRandomcHars
PostUp = ip route add 192.168.11.0/24 dev wg0
PostDown = ip route del 192.168.11.0/24 dev wg0

[Peer]
…other stuff

Save the file by pressing ctrl^s, then exit using ctrl^x. From now on, wg will automatically add your static route when the interface is activated, and automatically remove it when the interface is disabled

cheers bru

1 Like