Both the sites have the same local network (192.168.1.0/24).
This is a problem -- if you have 192.168.1.2 (say Device A1) in Site A wanting to connect to 192.168.1.3 (say Device B1) in Site B, 192.168.1.2 will think 192.168.1.3 is on its own local network and can connect to it directly (whereas it actually needs to route through the WireGuard servers). You need to rearrange your subnets so that they don't collide -- for example, use 192.168.1.0/25 for Site A and 192.168.1.128/25 for Site B.
When both the WireGuard servers are up and running, can I connect each server to the other WireGuard server as a WireGuard client so I can connect both the sites?
Yes -- technically WireGuard doesn't have distinct "server" or "client" roles -- both sides are equally capable of sending/receiving/routing traffic from the other.
When both the sites are connected with WireGuard, can I access Site A devices from Site B or vice versa?
Yes -- provided you fix the routing problem of both sites using the same local network of 192.168.1.0/24. Once you do that, you just have to:
- configure the router in each site to route packets for the other site through the site's own WireGuard server; and
- configure each site's WireGuard server to route packets for the other site through the other site's WireGuard server.
For example, say you use 192.168.1.0/25 for Site A and 192.168.1.128/25 for Site B; and assign 192.168.1.2 to Device A1 and 192.168.1.130 to Device B1; and assign 192.168.1.10 to WireGuard Server 1 and 192.168.1.140 to WireGuard Server 2. For Site A you'd:
- configure Router R-A to route 192.168.1.128/25 (Site B LAN) via 192.168.1.10 (WireGuard Server 1)
- configure WireGuard Server 1 to route 192.168.1.128/25 (Site B LAN) via its WireGuard interface to WireGuard Server 2 -- WireGuard will do this automatically for you if set
AllowedIPs = 192.168.1.128/25
in the [Peer]
section for WireGuard Server 2 in the WireGuard config on WireGuard Server 1
And correspondingly, for Site B you'd:
- configure Router R-B to route 192.168.1.0/25 (Site A LAN) via 192.168.1.140 (WireGuard Server 2)
- configure WireGuard Server 2 to route 192.168.1.0/25 (Site A LAN) via its WireGuard interface to WireGuard Server 1 -- WireGuard will do this automatically for you if set
AllowedIPs = 192.168.1.0/25
in the [Peer]
section for WireGuard Server 1 in the WireGuard config on WireGuard Server 2
With that it place, when Device A1 (192.168.1.2) tries to connect to Device B1 (192.168.1.130), it sends those packets to Router R-A, which forwards them to WireGuard Server 1, which forwards them through the WireGuard tunnel to WireGuard Server 2, which forwards them to Device B1. When Device B1 sends packets back to Device A1, it sends those packets to Router R-B, which forwards them to WireGuard Server 2, which forwards them through the WireGuard tunnel to WireGuard Server 1, which forwards them to Device A1.
This site-to-site configuration tutorial walks through a complete example of this scenario.
If I can connect to any of the WireGuard servers from an external WireGuard client, can I access the devices on both sites?
Yes (again provided you fix the routing problem of both sites using the same local network of 192.168.1.0/24). I would suggest using a separate WireGuard interface on your WireGuard servers for external clients, to make it easy to apply different routing and firewall rules for those clients. You might use wg0
for the site-to-site connection, and wg1
for the point-to-site (external client) connections.
In order to route packets from the external clients within each site, you can either have the WireGuard servers SNAT (aka masquerade) the packets, so that the source address of each packet is rewritten to the LAN address of the WireGuard server to which the external client is connected; or simply configure each site's router with routes for the external WireGuard networks themselves.
This point-to-site configuration tutorial walks through an example of a scenario where you use SNAT/masquerading; but for your scenario, it'd probably be more straightforward to just add routes to your routers for the external WireGuard networks, like:
- configure the router in each site to route packets for both external WireGuard networks through the site's own WireGuard server; and
- configure the site's WireGuard server to route packets for the other site's external WireGuard network through its WireGuard connection to the other site; and
- configure each external WireGuard client to route packets for both sites through the WireGuard server to which it's connected
For example, say you've set up a site-to-site connection as described above, connecting Site A (192.168.1.0/25) with Site B (192.168.1.128/25) through WireGuard Server 1 and WireGuard Server 2. Now you're going to use the 10.0.1.0/24 subnet for the WireGuard network of external clients that connect to WireGuard Server 1, and the 10.0.2.0/24 subnet for the WireGuard network of external clients that connect to WireGuard Server 2. (Those subnets are completely arbitrary -- you can choose whatever you want, as long as they don't collide with any of your other internal networks.)
For Site A you'd:
- configure Router R-A to also route 10.0.1.0/24 and 10.0.2.0/24 via 192.168.1.10 (WireGuard Server 1)
- configure WireGuard Server 1 to route 10.0.2.0/24 via its WireGuard interface to WireGuard Server 2 -- do this by setting
AllowedIPs = 192.168.1.128/25, 10.0.2.0/24
in the [Peer]
section for WireGuard Server 2 in the WireGuard config on WireGuard Server 1
- configure each external client of WireGuard Server 1 to route 192.168.1.0/25 and 192.168.1.128/25 via its WireGuard interface to WireGuard Server 1 -- do this by setting
AllowedIPs = 192.168.1.0/25, 192.168.1.128/25
in the [Peer]
section for WireGuard Server 1 in the WireGuard config of the external client (or in this case, since together both subnets add up to 192.168.1.0/24, you could simply set AllowedIPs = 192.168.1.0/24
).
And correspondingly, for Site B, you'd:
- configure Router R-B to also route 10.0.1.0/24 and 10.0.2.0/24 via 192.168.1.140 (WireGuard Server 2)
- configure WireGuard Server 2 to route 10.0.1.0/24 via its WireGuard interface to WireGuard Server 1 -- do this by setting
AllowedIPs = 192.168.1.0/25, 10.0.1.0/24
in the [Peer]
section for WireGuard Server 1 in the WireGuard config on WireGuard Server 2
- configure each external client of WireGuard Server 2 to route 192.168.1.0/25 and 192.168.1.128/25 via its WireGuard interface to WireGuard Server 2 -- do this by setting
AllowedIPs = 192.168.1.0/25, 192.168.1.128/25
in the [Peer]
section for WireGuard Server 2 in the WireGuard config of the external client (or in this case, since together both subnets add up to 192.168.1.0/24, you could simply set AllowedIPs = 192.168.1.0/24
).
For each external client of WireGuard Server 1, you'd choose an IP address from the 10.0.1.0/24 subnet for the external client. For example, say you chose 10.0.1.100 for external client WC. You'd set Address = 10.0.1.100/32
in the [Interface]
section of the WireGuard config for the interface of this client that connects to WireGuard Server 1. And you'd set AllowedIPs = 10.0.1.100/32
in the [Peer]
section for the client in the WireGuard config on WireGuard Server 1.
With that it place, when external client WC (10.0.1.100) tries to connect to Device B1 (192.168.1.130), it sends those packets through the external WireGuard tunnel to WireGuard Server 1, which forwards them through the site-to-site WireGuard tunnel to WireGuard Server 2, which forwards them to Device B1. When Device B1 sends packets back to external client WC, it sends those packets to Router R-B, which forwards them to WireGuard Server 2, which forwards them through the site-to-site WireGuard tunnel to WireGuard Server 1, which forwards them through the external WireGuard tunnel to external client WC.
192.168.1.0/24
to192.168.2.0/24
. Also, this scriptwireguard-site-to-site.sh
might help you with the Wireguard config andiptables
rules. I explained that linked script in this longer Answer. Great visual diagram!