OPNsense Router
Two isometric office buildings with server racks link to firewall appliances joined by a glowing padlocked tunnel, showing a site-to-site VPN on a dark background.
Networking

OPNsense WireGuard Site-to-Site Tunnel Setup

Set up a WireGuard site-to-site tunnel on two OPNsense firewalls, allow trusted clients to reach a remote NAS, and verify that IoT stays isolated.

By OPNsense Router Editorial · · 8 min read

An OPNsense WireGuard site-to-site tunnel can let Site A’s trusted clients open Site B’s NAS over HTTPS. Route the two trusted subnets through WireGuard, allow only the NAS connection across the tunnel, and block IoT access to the internal networks. Each site keeps its own WAN for internet traffic.

If you’re still choosing a protocol, see WireGuard vs OpenVPN vs IPsec on OPNsense.

Topology

At each site, connect the OPNsense LAN-side port to port 1 of a managed switch such as the UniFi Pro 24 PoE. Connect the access point to port 2. Each OPNsense WAN connects to its local ISP.

Use tagged VLANs 1 and 20 on the OPNsense uplink. On port 2, use untagged VLAN 1 for AP management and tag VLAN 20 for the IoT SSID. Use untagged access ports 3 and 4 for VLANs 1 and 20, respectively. OPNsense VLAN setup guide.

VLAN plan

Use five non-overlapping subnets in this example. The two trusted subnets and the WireGuard transfer subnet must also avoid overlapping networks already routed at either site. The VLAN IDs can repeat because WireGuard routes between IP networks. OPNsense’s site-to-site guide and routing table guide.

Site and networkVLANExample subnetExample DHCP rangeLocal gateway
A trusted110.10.10.0/2410.10.10.100–10.10.10.19910.10.10.1
A IoT2010.10.20.0/2410.10.20.100–10.10.20.19910.10.20.1
B trusted110.20.10.0/2410.20.10.100–10.20.10.19910.20.10.1
B IoT2010.20.20.0/2410.20.20.100–10.20.20.19910.20.20.1

Give the NAS the fixed address 10.20.10.20 and default gateway 10.20.10.1. The transfer subnet 10.2.2.0/24 uses the two static instance addresses below. This example uses IPv4. If you also route IPv6 between sites or VLANs, apply equivalent IPv6 filtering. OPNsense’s dual-stack setup note.

Configure instances, peers and routes

Each OPNsense firewall acts as a WireGuard VPN gateway. Its WireGuard instance listens as a server and can also initiate a connection to the other site. WireGuard moved into OPNsense core in 24.1. OPNsense VPN reference and 24.1 release notes.

Start with two reachable public IPv4 WANs. Under VPN → WireGuard → Instances, add an instance on each firewall and turn on advanced mode. Use the gear button to generate a separate keypair on each instance. Save and apply, and copy only the public key to the other site. OPNsense site-to-site guide, 26.7.10 menu and 26.7.10 instance form.

Instance fieldSite ASite B
EnabledCheckedChecked
Namewg-site-awg-site-b
Public and private keysGenerate a local keypairGenerate a separate local keypair
Listen port5182051820
Tunnel address10.2.2.1/2410.2.2.2/24
MTU1420, or 1412 on PPPoE1420, or 1412 on PPPoE
DNS serversBlankBlank
Disable routesUncheckedUnchecked

Under VPN → WireGuard → Peers, add the opposite site and attach it using the peer’s Instances field. Save and apply. Leave global activation until the firewall rules are in place. 26.7.10 menu and 26.7.10 peer form.

Peer fieldOn Site AOn Site B
EnabledCheckedChecked
Namepeer-bpeer-a
Public keyB’s instance public keyA’s instance public key
Pre-shared keyBlankBlank
Allowed IPs10.2.2.2/32, 10.20.10.0/2410.2.2.1/32, 10.10.10.0/24
Endpoint addressB’s public WAN IPv4A’s public WAN IPv4
Endpoint port5182051820
Instanceswg-site-awg-site-b

After activation, open System → Routes → Status. A should show 10.20.10.0/24 through its WireGuard interface and B should show 10.10.10.0/24 through its WireGuard interface. Both have 10.2.2.0/24 on the tunnel. OPNsense installs the remote LAN routes from Allowed IPs. Keep the default route on each site’s WAN. OPNsense VPN reference and routing table guide.

Allowed IPs determines which peer gets outbound packets and which source addresses it may send back. Leave both IoT subnets and 0.0.0.0/0 out. Check Firewall → NAT → Source NAT (Outbound) for rules that translate traffic between the trusted LANs. Keep normal WAN NAT and preserve the original LAN addresses inside the tunnel. WireGuard manual and OPNsense NAT reference.

Firewall rules

Under Firewall → Aliases, create a network alias called INTERNALS on each firewall. Include the four LAN subnets and 10.2.2.0/24. The example assumes this is the only tunnel in the WireGuard group. OPNsense alias reference.

Under Firewall → Rules, use direction In, version IPv4, Quick enabled, and source port Any. Keep scoped DHCP and local administration permits above the internal blocks, then place general internet permits below them. On each interface, apply these rules in the listed order. OPNsense firewall rules guide.

InterfaceActionSourceDestinationProtocol and destination port
A WANPassB’s public WAN IPv4A’s WAN IPv4UDP 51820
B WANPassA’s public WAN IPv4B’s WAN IPv4UDP 51820
A trusted, B trusted, A IoT and B IoTPassThat interface’s subnetIts local gateway IPTCP/UDP 53
A trusted onlyPass, with Gateway set to default10.10.10.0/2410.20.10.20/32TCP 443
A trusted, B trusted, A IoT and B IoTBlock, with Log enabled on IoTThat interface’s subnetINTERNALSAny
B WireGuard groupPass10.10.10.0/2410.20.10.20/32TCP 443
B WireGuard group, below its passBlockAnyAnyAny
A WireGuard groupBlockAnyAnyAny

The NAS must listen on TCP 443 and accept A’s trusted subnet in its host firewall, if enabled. Keep the pass rules stateful so HTTPS replies can return. Check floating and group rules for earlier broad passes that would override the LAN blocks. After changing policy, remove any affected states under Firewall → Diagnostics → States. OPNsense firewall rules and states.

Apply the firewall rules before activating WireGuard. On 26.7.10, open VPN → WireGuard → Instances on both sites. Select Enable WireGuard below the tabs and click Apply. The site-to-site guide lists this step under VPN → WireGuard → Settings. OPNsense site-to-site guide, 26.7.10 menu, 26.7.10 global settings form and 26.7.10 setup screen.

DNS and discovery

Point clients at their local gateway for DNS. On both firewalls, open Services → Unbound DNS → Overrides and add an A record with Host nas, Domain site-b.example, and IP 10.20.10.20. Check Access Lists if a local subnet cannot query Unbound. Use the NAS’s actual certificate name in place of the example if it differs. OPNsense Unbound reference and Mozilla’s certificate guide.

Bonjour uses link-local multicast DNS, so use the DNS name for cross-site access. IGMP snooping manages multicast forwarding on the local switch. Multicast DNS in RFC 6762 and IGMP snooping in RFC 4541.

CGNAT, dynamic WANs and MTU

If A has a changing WAN address or sits behind NAT, make A the initiator and use B as the reachable responder. Replace the two WAN rules above with the responder’s rule below. If B is the initiator, swap the WAN roles and keep the same tunnel IPs, Allowed IPs and NAS rules. OPNsense site-to-site guide.

SettingInitiatorReachable responder
Peer endpoint address and portResponder’s public IPv4 or DNS name, port 51820Leave address and port blank
Peer keepalive interval25 seconds to maintain an idle NAT or firewall mappingLeave blank
WAN rule for this tunnelOutbound initiation and stateful repliesPass inbound IPv4 UDP 51820 to the responder’s WAN address. Use the initiator’s public IPv4 as source if fixed, or Any if it changes

The responder learns the address and port from authenticated WireGuard traffic. If it sits behind an upstream router you control, manually forward UDP 51820 on that router to the responder’s OPNsense WAN address. Leave UPnP disabled. WireGuard manual, OPNsense port-forward reference and Ubiquiti’s UPnP guide.

A WAN address in 100.64.0.0/10 is in the shared range reserved for carrier-grade NAT. If neither site can receive inbound UDP, arrange a reachable public endpoint. If a configured endpoint hostname changes, use System → Settings → Cron to schedule Renew DNS for WireGuard on stale connections. RFC 6598 and OPNsense’s endpoint guidance.

For IPv4 TCP, set Max mss under Firewall → Settings → Normalization on the WireGuard group at both sites. Match any direction, protocol, source and destination. Subtract at least 40 bytes from the tunnel MTU, giving 1380 or lower at MTU 1420. OPNsense’s MSS clamping example.

Things to test before you call it done

CheckWhat to doExpected result
HTTPS from A trustedOpen https://nas.site-b.example/ in a browser, substituting your NAS hostnameThe NAS login page loads with a certificate trusted by the client
Handshake on both firewallsAfter the HTTPS attempt, open VPN → WireGuard → Status (called Diagnostics in the site-to-site guide) and find the peerHandshake Age shows a recent handshake. Sent and Received increase during traffic
IoT isolation at both sitesFrom a device on each IoT VLAN, open the same NAS URL and then https://10.20.10.20/. In Firewall → Log Files → Live View, filter for the IoT client’s address and destination 10.20.10.20The login page stays unreachable, and each local firewall logs a block to TCP 443
Local internet egressIn System → Routes → Status, check the default route on both firewallsEach firewall’s default route still uses its local WAN

A certificate warning during the IoT check means the browser reached a TLS service. Verify the firewall block in the log. Mozilla’s certificate guide, OPNsense WireGuard status reference, 26.7.10 Status screen, firewall logging guide and routing table guide.

For an optional throughput check, temporarily duplicate the NAS pass rules on A trusted and B’s WireGuard group with destination TCP 5201 above the blocks. Allow that port from A trusted in the NAS host firewall and run the server on the NAS if it has iperf3. OPNsense firewall rules and ESnet’s iperf3 manual.

iperf3 -s -B 10.20.10.20

Run these from A trusted to measure both directions.

iperf3 -c 10.20.10.20 -t 10
iperf3 -c 10.20.10.20 -t 10 -R

Stop iperf3 and remove the temporary permissions when finished. If the handshake or HTTPS checks fail, see OPNsense WireGuard troubleshooting.

Evidence and limits. The configuration is based on the OPNsense site-to-site and firewall documentation at revision bf5be04, with WireGuard controls checked against the 26.7.10 source. The example was not run in a lab.

Sources

  1. OPNsense WireGuard Site-to-Site Setup
  2. OPNsense Virtual Private Networking
  3. OPNsense 24.1 Release Notes
  4. OPNsense VLAN and LAGG Setup
  5. Ubiquiti Pro 24 PoE Specifications
  6. OPNsense Routes
  7. OPNsense Firewall Rules
  8. OPNsense Firewall Aliases
  9. OPNsense Network Address Translation
  10. OPNsense 26.7.10 WireGuard Menu
  11. OPNsense 26.7.10 WireGuard Global Settings Form
  12. OPNsense 26.7.10 WireGuard Setup Screen
  13. OPNsense 26.7.10 WireGuard Instance Form
  14. OPNsense 26.7.10 WireGuard Peer Form
  15. OPNsense 26.7.10 WireGuard Status Screen
  16. OPNsense Firewall Log Files
  17. OPNsense Unbound DNS
  18. RFC 6762 Multicast DNS
  19. RFC 4541 IGMP and MLD Snooping Switches
  20. RFC 6598 IANA-Reserved IPv4 Prefix for Shared Address Space
  21. WireGuard wg(8) Manual
  22. Ubiquiti UniFi Gateway UPnP
  23. Mozilla Secure Website Certificate
  24. ESnet Invoking iperf3

Related