WireGuard Site-to-Site: Connecting Offices, VPN Clients, and Selected Networks
In the article on running WireGuard on Ubuntu, a laptop and a phone connected to a VPN server. This time there’s an entire office at each end of the tunnel. A workstation in Office A can reach a service in Office B without running WireGuard itself. Two Linux routers handle the tunnel.
We’ll use the same setup to route selected external networks through Office B’s internet connection and give employees on Office A’s VPN access to those networks. Both offices can initiate connections to the other office’s LAN and VPN pool. The selected external networks are reachable through B, so there’s no corresponding route through A.

Addresses and interfaces
| Interface | Office A | Office B |
|---|---|---|
WAN, eth0 |
192.0.2.10 |
198.51.100.20 |
LAN, eth1 |
10.10.10.0/24, gateway 10.10.10.1 |
10.20.20.0/24, gateway 10.20.20.1 |
Employee VPN, wg-users |
10.10.110.0/24 |
10.20.120.0/24 |
Inter-office tunnel, wg-office |
10.255.40.1/30 |
10.255.40.2/30 |
Each office already runs an employee VPN on the same router, with its own wg-users interface and address pool. Office B reaches the external networks 203.0.113.0/26 and 203.0.113.128/26 through eth0. The public IPs and external prefixes in the examples are reserved for documentation. Substitute your actual addresses and check that the two office subnets and VPN pools don’t overlap.
WireGuard configuration
Install the packages and generate a separate key pair on each Debian or Ubuntu router. Run the key generation commands as root during initial setup.
apt install wireguard-tools iptables-persistent
install -d -m 0700 /etc/wireguard
cd /etc/wireguard
umask 077
wg genkey | tee wg-office.key | wg pubkey > wg-office.pub
Send only wg-office.pub to the other side. Put the private key in the local /etc/wireguard/wg-office.conf and set the file permissions to 0600. The filename without .conf becomes the interface name.
Office A
[Interface]
Address = 10.255.40.1/30
ListenPort = 51820
PrivateKey = <private key of this router>
[Peer]
PublicKey = <public key of the other router>
Endpoint = 198.51.100.20:51820
AllowedIPs = 10.255.40.2/32, 10.20.20.0/24, 10.20.120.0/24, 203.0.113.0/26, 203.0.113.128/26
Office B
[Interface]
Address = 10.255.40.2/30
ListenPort = 51820
PrivateKey = <private key of this router>
[Peer]
PublicKey = <public key of the other router>
Endpoint = 192.0.2.10:51820
AllowedIPs = 10.255.40.1/32, 10.10.10.0/24, 10.10.110.0/24
Both endpoints have static addresses in this example. If A is behind NAT and only B accepts incoming connections, omit Endpoint from the peer entry for A on B. On A, keep B’s endpoint and add PersistentKeepalive = 25 to the peer entry. B learns A’s address and port from an authenticated packet. B’s inbound UDP rule needs to match the address A uses after NAT. WireGuard Quick Start
AllowedIPs serves two purposes. When sending a packet, WireGuard uses its destination address to select a peer. After decrypting an incoming packet, WireGuard checks its source address. A therefore needs the external prefixes in B’s peer entry both to send requests and to accept replies from external hosts. wg-quick automatically adds routes for those prefixes. Each office retains its local ISP as its default route, and UDP traffic between the endpoints travels over the normal WAN route. Cryptokey Routing · wg-quick(8)
Packet forwarding and iptables
On both routers, add net.ipv4.ip_forward = 1 to /etc/sysctl.d/90-office-routing.conf. Apply it with sudo sysctl --system and check it with sysctl net.ipv4.ip_forward. Without forwarding, Linux can receive packets addressed to the router itself, but it won’t pass packets between interfaces.
The incoming WireGuard UDP packet is addressed to the router and passes through INPUT. After decryption, an inner packet headed for another machine passes through FORWARD. If you test SSH on the router itself, the INPUT rules for the inner traffic still apply.
Add the following lines to the existing *filter table in /etc/iptables/rules.v4, before COMMIT and any final deny rules. The example assumes a DROP policy for FORWARD. If you already handle INVALID and ESTABLISHED,RELATED, reuse those rules. Keep the existing rules for SSH, remote-access VPN, and ordinary internet access. Check the order of existing rules, since an earlier broad ACCEPT can match packets before the narrower rules below.
Office A
-A INPUT -i eth0 -s 198.51.100.20/32 -d 192.0.2.10/32 -p udp --dport 51820 -j ACCEPT
-A FORWARD -m conntrack --ctstate INVALID -j DROP
-A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -i eth1 -o wg-office -s 10.10.10.0/24 -d 10.20.20.0/24 -j ACCEPT
-A FORWARD -i eth1 -o wg-office -s 10.10.10.0/24 -d 10.20.120.0/24 -j ACCEPT
-A FORWARD -i eth1 -o wg-office -s 10.10.10.0/24 -d 203.0.113.0/26 -j ACCEPT
-A FORWARD -i eth1 -o wg-office -s 10.10.10.0/24 -d 203.0.113.128/26 -j ACCEPT
-A FORWARD -i wg-users -o wg-office -s 10.10.110.0/24 -d 10.20.20.0/24 -j ACCEPT
-A FORWARD -i wg-users -o wg-office -s 10.10.110.0/24 -d 10.20.120.0/24 -j ACCEPT
-A FORWARD -i wg-users -o wg-office -s 10.10.110.0/24 -d 203.0.113.0/26 -j ACCEPT
-A FORWARD -i wg-users -o wg-office -s 10.10.110.0/24 -d 203.0.113.128/26 -j ACCEPT
-A FORWARD -i wg-office -o eth1 -s 10.20.20.0/24 -d 10.10.10.0/24 -j ACCEPT
-A FORWARD -i wg-office -o wg-users -s 10.20.20.0/24 -d 10.10.110.0/24 -j ACCEPT
-A FORWARD -i wg-office -o eth1 -s 10.20.120.0/24 -d 10.10.10.0/24 -j ACCEPT
-A FORWARD -i wg-office -o wg-users -s 10.20.120.0/24 -d 10.10.110.0/24 -j ACCEPT
Office B
-A INPUT -i eth0 -s 192.0.2.10/32 -d 198.51.100.20/32 -p udp --dport 51820 -j ACCEPT
-A FORWARD -m conntrack --ctstate INVALID -j DROP
-A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -i eth1 -o wg-office -s 10.20.20.0/24 -d 10.10.10.0/24 -j ACCEPT
-A FORWARD -i eth1 -o wg-office -s 10.20.20.0/24 -d 10.10.110.0/24 -j ACCEPT
-A FORWARD -i wg-users -o wg-office -s 10.20.120.0/24 -d 10.10.10.0/24 -j ACCEPT
-A FORWARD -i wg-users -o wg-office -s 10.20.120.0/24 -d 10.10.110.0/24 -j ACCEPT
-A FORWARD -i wg-office -o eth1 -s 10.10.10.0/24 -d 10.20.20.0/24 -j ACCEPT
-A FORWARD -i wg-office -o wg-users -s 10.10.10.0/24 -d 10.20.120.0/24 -j ACCEPT
-A FORWARD -i wg-office -o eth0 -s 10.10.10.0/24 -d 203.0.113.0/26 -j ACCEPT
-A FORWARD -i wg-office -o eth0 -s 10.10.10.0/24 -d 203.0.113.128/26 -j ACCEPT
-A FORWARD -i wg-office -o eth1 -s 10.10.110.0/24 -d 10.20.20.0/24 -j ACCEPT
-A FORWARD -i wg-office -o wg-users -s 10.10.110.0/24 -d 10.20.120.0/24 -j ACCEPT
-A FORWARD -i wg-office -o eth0 -s 10.10.110.0/24 -d 203.0.113.0/26 -j ACCEPT
-A FORWARD -i wg-office -o eth0 -s 10.10.110.0/24 -d 203.0.113.128/26 -j ACCEPT
If employees connect over policy-based IPsec, there may be no wg-users interface. On the relevant router, keep the source subnet match in rules for traffic from clients and replace -i wg-users with -m policy --dir in --pol ipsec --proto esp. For new connections to clients, keep the destination subnet match and replace -o wg-users with -m policy --dir out --pol ipsec --proto esp. The relevant prefixes must also be covered by the client routes and the negotiated IPsec traffic selectors. iptables-extensions(8)
1. From Office A’s LAN to Office B’s LAN

The workstation at 10.10.10.25 sends a packet for 10.20.20.30 to its gateway in A. A forwards it through wg-office, and B sends it out over eth1. The host in B sees 10.10.10.25 as the source address and returns the reply through its gateway in B. A new connection from B to A follows the reverse path and has its own forwarding rules. The two office networks can communicate without NAT.
In this setup, each WireGuard router is also the gateway for its LAN. If a different device is the gateway, add routes there for the remote LAN and VPN pool via the local WireGuard router’s LAN address. On A’s gateway, route the selected external prefixes the same way. For TCP access, the destination hosts must allow the relevant ports from the remote subnets.
2. From Office A to selected networks through Office B

A packet from 10.10.10.25 to 203.0.113.10 enters wg-office on A and leaves on eth0 at B. The external host usually has no route back to the sender’s private address. B rewrites the source to its WAN address. The reply arrives at B, conntrack restores the original client address as the destination, and B sends the packet back through the tunnel to A.
In Office B’s /etc/iptables/rules.v4, add these lines to the *nat table before its COMMIT and before any general NAT rule that would match the same traffic. If there’s no NAT table in the file, create a *nat block with a :POSTROUTING ACCEPT [0:0] declaration and a closing COMMIT.
-A POSTROUTING -o eth0 -s 10.10.10.0/24 -d 203.0.113.0/26 -j SNAT --to-source 198.51.100.20
-A POSTROUTING -o eth0 -s 10.10.10.0/24 -d 203.0.113.128/26 -j SNAT --to-source 198.51.100.20
-A POSTROUTING -o eth0 -s 10.10.110.0/24 -d 203.0.113.0/26 -j SNAT --to-source 198.51.100.20
-A POSTROUTING -o eth0 -s 10.10.110.0/24 -d 203.0.113.128/26 -j SNAT --to-source 198.51.100.20
For a dynamic WAN address, replace -j SNAT --to-source 198.51.100.20 with -j MASQUERADE, keeping the interface and subnet matches. If the selected networks are private and you can add routes back to A’s LAN and VPN pool via B, you can do without source NAT. Using one NAT rule per source and destination makes it clear which flows use B’s address. The rules leave initiation on the office side. SNAT and MASQUERADE
3. From Office A’s VPN to selected networks through Office B

An employee gets the address 10.10.110.10. With split tunneling, add both external prefixes, B’s LAN, and B’s VPN pool to the AllowedIPs for peer A on the employee’s device. An existing full IPv4 tunnel already includes these destinations in 0.0.0.0/0. On VPN server A, the employee’s peer entry keeps AllowedIPs = 10.10.110.10/32.
The packet now passes through wg-users and then wg-office. B sees 10.10.110.10 as the source and applies the SNAT rule for the VPN pool on the way out. On the return path, the restored destination 10.10.110.10 matches B’s route to 10.10.110.0/24. A delivers the reply to its VPN client.
Add 10.10.10.0/24 and 10.10.110.0/24 to B’s split-tunnel clients for access to A’s LAN and VPN pool. A LAN host can initiate a connection to a VPN client in the other office if the client’s firewall allows the port. The selected external prefixes stay on B’s side and need no route through A on B’s clients.
Loading and testing the rules
Before loading the rules, make a copy of the working file and keep console access to the router available. iptables-restore replaces the tables defined in the file. The --test option validates rule loading. SSH and application connectivity still need a live check.
sudo sh -c 'iptables-restore --test < /etc/iptables/rules.v4'
sudo sh -c 'iptables-restore < /etc/iptables/rules.v4'
sudo systemctl enable netfilter-persistent
sudo systemctl enable --now wg-quick@wg-office
Keep IPv6 rules in /etc/iptables/rules.v6. For IPv6 transit, add IPv6 addresses and prefixes to the WireGuard configurations, set net.ipv6.conf.all.forwarding = 1, and test and load the rules with ip6tables-restore. If the WAN learns its route from Router Advertisements, check accept_ra and keep rules for the required ICMPv6 traffic. The example’s IPv4 SNAT applies only to IPv4. For instance, a service with an AAAA record can still be reached via the ordinary IPv6 route if you’ve configured selected routes only for IPv4. Linux kernel IP sysctl documentation · iptables-restore(8)
Check the setup in this order.
- On A, run
ip -4 route get 10.20.20.30,ip -4 route get 203.0.113.10, andip -4 route get 198.51.100.20. The first two destinations should go throughwg-office, and the third through the WAN. On B, check the routes to A’s LAN and VPN pool. - From LAN workstations, test an allowed TCP service in the opposite office in both directions. After each attempt, use
sudo wg show wg-officeto check the latest handshake and traffic counters. Then repeat the TCP test from a VPN client in each office. - From A’s LAN and VPN, test an actual host in one of the selected external prefixes. On B, trace that flow with
tcpdump -ni wg-office host 203.0.113.10andtcpdump -ni eth0 host 203.0.113.10, substituting the test host’s address. On the tunnel interface, the source should be the client’s address in A. On the WAN, it should be B’s WAN address. On A, check that a destination outside the selected prefixes still goes through the local ISP.
If the handshake succeeds but TCP fails, follow the request to the destination interface and check where the reply goes. That shows where to look next: the route, the FORWARD chain, the destination host, or the SNAT rule at the exit router.
Only registered users can leave a comment.
Sign in or register to leave a comment.