Create wireguard tunnels for 2 interfaces between two routers

Hello,

I want to setup two routers in remote locations to talk with each 3 interfaces, lan, family and iot via two wireguard interfaces to each other.
Goals are

  • to be able to reach the lan-interfaces of the other router from each router and clients in lan-zones of both routers via wg0
  • to be able to reach family-clients of both routers from clients in family-zones via wg1
  • to be able to reach iot-clients of both routers from clients in family- and lan-zones of both routers via wg1. I thought it would be no good idea to connect the iot interfaces directly, but accessing them only via forwarding rules (and thus minize security breaches).
Firewall setup: For both routers I have the same following zones + forwardings defined
###################### WAN-config
config zone
	option name 'wan'
	option input 'REJECT'
	option output 'ACCEPT'
	option forward 'REJECT'
	option masq '1'
	option mtu_fix '1'
	list network 'wan6'
	list network 'wan'
###################### LAN-config
config zone
	option name 'lan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	list network 'lan'
	list network 'wg0'

config forwarding
	option src 'lan'
	option dest 'iot'

config forwarding
	option src 'lan'
	option dest 'wan'
###################### FAMILY-config
config zone
	option name 'family'
	option input 'REJECT'
	option output 'ACCEPT'
	option forward 'REJECT'
	list device 'br-family'
	list network 'family'
	list network 'wg1'

config forwarding
	option src 'family'
	option dest 'iot'

config forwarding
	option src 'family'
	option dest 'wan'
###################### IOT-config
config zone
	option name 'iot'
	option input 'REJECT'
	option output 'ACCEPT'
	option forward 'REJECT'
	list device 'br-iot'
	list network 'iot'

config forwarding
	option src 'iot'
	option dest 'wan'
##################### wireguard rules
config rule
	option name 'wireguard wg0 input'
	option src '*'
	option dest_port '27'
	option proto 'udp'
	option target 'ACCEPT'

config rule
	option name 'wireguard wg1 input'
	option src '*'
	option dest_port '28'
	option proto 'udp'
	option target 'ACCEPT'
Network/wireguard setup Router#1
config interface 'lan'
	option device 'br-lan'
	option proto 'static'
	option ipaddr '192.168.21.1'
	option netmask '255.255.255.0'
	option ip6assign '60'

config interface 'family'
	option device 'br-family'
	option proto 'static'
	option ipaddr '192.168.31.1'
	option netmask '255.255.255.0'
	option ip6assign '60'

config interface 'iot'
	option device 'br-iot'
	option proto 'static'
	option ipaddr '192.168.41.1'
	option netmask '255.255.255.0'
	option ip6assign '60'
###########################################
config interface 'wg0'
	option proto 'wireguard'
	option private_key '<privkey_wg0_Router#1>'
	option listen_port '27'
	list addresses '192.168.1.1/24'
	option ip6assign '64'

config wireguard_wg0
	option description 'Router#2_lan'
	option public_key '<pubkey_wg0_Router#2>'
	option preshared_key '<presharedkey_wg0>'
	option route_allowed_ips '1'
	option endpoint_host '<wg0.router2.mydomain.tld>'
	option endpoint_port '27'
	option persistent_keepalive '25'
	list allowed_ips '192.168.22.0/24'
	list allowed_ips '192.168.42.0/24'
	list allowed_ips '192.168.1.5/32'
###########################################
config interface 'wg1'
	option proto 'wireguard'
	option private_key '<privkey_wg1_Router#1>'
	option listen_port '28'
	list addresses '192.168.2.1/24'
	option ip6assign '64'

config wireguard_wg1
	option description 'Router#2_family'
	option public_key '<pubkey_wg1_Router#2>'
	option preshared_key '<presharedkey_wg1>'
	list allowed_ips '192.168.32.0/24'
	list allowed_ips '192.168.2.5/32'
	option route_allowed_ips '1'
	option endpoint_host '<wg1.router2.mydomain.tld>'
	option endpoint_port '28'
	option persistent_keepalive '25'
Network/wireguard setup Router#2
config interface 'lan'
	option device 'br-lan'
	option proto 'static'
	option ipaddr '192.168.22.1'
	option netmask '255.255.255.0'
	option ip6assign '64'
	list ip6class 'local'

config interface 'family'
	option device 'br-family'
	option proto 'static'
	option ipaddr '192.168.32.1'
	option netmask '255.255.255.0'
	option ip6assign '64'
	option ip6class 'local'

config interface 'iot'
	option device 'br-iot'
	option proto 'static'
	option ipaddr '192.168.42.1'
	option netmask '255.255.255.0'
	option ip6assign '64'
###########################################
config interface 'wg0'
	option proto 'wireguard'
	option private_key '<privkey_wg0_Router#2>'
	option listen_port '27'
	list addresses '192.168.1.5/24'
	option ip6assign '64'
	option ip6class 'local'

config wireguard_wg0
	option description 'Router#1_lan'
	option public_key '<pubkey_wg0_Router#1>'
	option preshared_key '<presharedkey_wg0>'
	list allowed_ips '192.168.21.0/24'
	list allowed_ips '192.168.41.0/24'
	list allowed_ips '192.168.1.1/32'
	option route_allowed_ips '1'
	option endpoint_host '<wg0.router1.mydomain.tld>'
	option endpoint_port '27'
	option persistent_keepalive '25'
###########################################
config interface 'wg1'
	option proto 'wireguard'
	option private_key '<privkey_wg1_Router#2>'
	option listen_port '28'
	list addresses '192.168.2.5/24'
	option ip6assign '64'
	option ip6class 'local'

config wireguard_wg1
	option description 'Router#1_family'
	option public_key '<pubkey_wg1_Router#2>'
	option preshared_key '<presharedkey_wg1>'
	list allowed_ips '192.168.31.0/24'
	list allowed_ips '192.168.2.1/32'
	option route_allowed_ips '1'
	option endpoint_host '<wg1.router1.mydomain.tld>'
	option endpoint_port '28'
	option persistent_keepalive '25'

The tunnel on wg0 works: I can reach the lan- + iot-interfaces of the other router from both routers.

The tunnel for wg1 gets established, so part of this config is correct as well.
But when I try to use the wg1-tunnel and move the rows list allowed_ips '192.168.41.0/24'/list allowed_ips '192.168.42.0/24' from wg0 to wg1, I cannot reach iot-clients of the other router from family-clients (and also no more from lan-clients, see second question below). So something with this setup is borked, but I seem to be unable to spot the issue.
Could someone help to correct the setup the second tunnel (wg1)?

Plus second question: Is it somehow possible to set a static route that enables from both interfaces lan AND family on router#1 to reach iot on router#2 and vice versa?
Could something like


work with PBR?

Thanks - at least for reading,
ssdnvv

I'm fairly positive you don't need to use multiple WireGuard connections. It is possible to route multiple subnets in a single WireGuard tunnel. If both sides are set up with identical subnets with the WireGuard interface in its own firewall zone, you should be able to just forward between the WireGuard zone and the respective subnet zones on either side.

1 Like

This kind of setup is often referred to as a site-to-site setup.

This will work with just one tunnel between the two sites.

I would delete wg1 and keep wg0

Just add the missing subnet 192.168.31.0/24 on router 2 and 192.168.32.0/24 on router 1 to the allowed IPs that should give you routing to all subnets of the other side.

See my notes how I have done this: WireGuard Server Setup Guide

The restriction of access is done with the firewall for this you have to setup a separate zone for your wg0 interface with the same settings as the lan zone (also covered in my notes).

With forwarding rules you allow access to the different interfaces

Note that the local lan clients might have their own local firewall which will not allow access from other subnets so you often have to tweak that local firewall or use the workaround as described n my notes

But you are nearly there :slight_smile:

2 Likes

Thanks alot for this very comprehensive document :slight_smile:
First question:


the last row should read list server '/lan5/192.168.5.1', right?
And with my setup I would have to list each subnet's server (like 192.168.31.1/41.1/41.1 (for router#2))?

Second question how do I actually now setup the following routing with at the same time making sure that family clients cannot access lan resources on the other router? (this is not answered by the document or maybe I missed it)

  • /router#1/lan <-> wg0 <-> /router#2/lan
  • /router#1/lan -> wg0 -> /router#2/iot
  • /router#1/iot <- wg0 <- /router#2/lan
  • /router#1/family <-> wg0 <-> /router#2/family
  • /router#1/family -> wg0 -> /router#2/iot
  • /router#1/iot <- wg0 <- /router#2/family

You should not need to set up any special routing. The Wireguard interfaces create routes themselves once "route allowed IPs" is set, covering all the subnets you "allow" to go to the other end. The rest is handled by the firewall on either side, forwarding between the WireGuard firewall zone and the ones the respective subnets are in. It also handles which subnets can forward between each other, just like on a local machine.

2 Likes

Correct thanks for reporting :+1:

As already noted by @takimata the routing should already in place if you have set the Allowed IPs and enabled Route Allowed IPs.
You can check with from command line:

ip route show

If you do this on router1 you would see that there are routes for the subnets of the other side (which you have placed in the allowed IPs) to route via the WG interface.

A route is just a route but along this routes are doors (=firewall) those are closed by default so you have to open up the doors (=firewall) to let traffic pass.
These doors are one way so you can have traffic go out but not go in (return traffic is always allowed)

An example (see also WireGuard Server Setup Guide)
You have a client on router1-lan trying to connect to router2-lan
The route is already there so if your router1-lan client (e.g. 192.168.31.X) tries to route e.g.to 192.168.32.X) traffic will be directed to the WG interface. But to allow this by the firewall on router1 you have to create a forward rule (remember my advice to place the wg0 interface on its own firewall zone lets call that wgserver)
router1 /etc/config/firewall:

config forwarding
	# to give your LAN client access to WG clients needed for site-to-site setup
	option src 'lan'
	option dest 'wgserver'

Now traffic will pass to the WG interface, WireGuard has its own cryptokey routing which I will not discuss here but with the destination address and the right wg public key traffic is allowed)

From the WG interface on router 2 traffic must then pass to the router2-lan so you again need a forwarding rule but now from wgserver zone **to ** lan zone:
router2 /etc/config/firewall:

config forwarding
	# to give WG clients access to your LAN clients 
	# if you want more fine grained control remove this and make a traffic rule see below
	option src 'wgserver'
	option dest 'lan'

Now clients from router1-lan can connect to clients on router2-lan but not the other way around.
If you want that then also make the reverse rules (reversing src and dest) and you have bidirectional traffic possible.

For IoT you might want only one way traffic so you only make the rules in one direction

If you cannot get it going and need help please post configs again from both router1 and router2:

cat /etc/config/network
cat /etc/config/firewall
ip route show
1 Like

I maybe answered unclear (sorry for that), the routing is understood and works (thanks!).

But what does not work yet is the segregation of the networks.
With setting up the following firewall rules on both routers

##################################### Wireguard ###
config zone
	option name 'wg0'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	list network 'wg0'

config forwarding
	option src 'lan'
	option dest 'wg0'

config forwarding
	option src 'wg0'
	option dest 'lan'

config forwarding
	option src 'family'
	option dest 'wg0'

config forwarding
	option src 'wg0'
	option dest 'family'

config forwarding
	option src 'wg0'
	option dest 'iot'

config forwarding
	option src 'wg0'
	option dest 'wan'
	
config rule
	option name 'wireguard input wg0'
	option src 'wan'
	option dest_port '27'
	option proto 'udp'
	option target 'ACCEPT'

I can now access luci of the respective remote router from family, which I need to prevent :slight_smile:
So how do I restrict
family -> wg -> lan?

Remove this and family can no longer reach out to the other side:

But if you want some clients on family to reach some clients on the other side then you can make a traffic rule (also an example in my guide :slight_smile: )

But this is not what I wanted to achieve.
I need segregation between lan and family with at the same time allowing the local family subnet to access the full remote family subnet.

edit: Maybe it is anyways better to no be able to reach iot from lan.
So what I really want to get up an running is

  • /router#1/lan <-> wg <-> /router#2/lan
  • /router#1/family <-> wg <-> /router#2/family
  • /router#1/family -> wg -> /router#2/iot
  • /router#1/iot <- wg <- /router#2/family
  • /router#1/lan <-!-> wg <-> /router#2/family
  • /router#1/family <-> wg <-!-> /router#2/lan

As said you make a traffic rule something like this (instead of the general forward rule from family to wg0) this should restrict access to only the family subnet
(actually the source subnet is probably redundant but you can use that to restrict access form only certain family clients if you wish)

config rule
	option src 'family'
	option dest 'wg0'
	option name 'familytofamily'
	list proto 'all'
	list src_ip '192.168.31.0/24'
	list dest_ip '192.168.32.0/24'
	option target 'ACCEPT'

I hope you get the idea.

Got it. Thanks, that solves the topic! (I actually needed 3 of those rules - family 1->family2, family2->family1 and family1->iot2 (and vice versa on the second router))

1 Like