Technical architectural analysis, practical configuration manifests, and deployment instructions for WireGuard VPN on OPNsense: Server & Peer.
System Required:
- Required to reliably request a VPN instance endpoint from an external network
Server in OPNSense
Create instance and enable
- WG Instance / Peers
- CIDR:
10.0.X.X/24 - Instance:
10.0.X.X/24(instance address is10.0.X.X, peer addresses are assigned sequentially)
Create instance
- Tunnel band: ex)
10.0.X.X/24
Enable
Create peer
It is recommended to create as many peers as the number of clients. (User:Peer = 1:1, Peer:Instance = 1:N)
Create manually (only when necessary)
- Generating private and public keys
mkdir wg-mgnt-peer1
cd wg-mgnt-peer1/
#wg genkey > privatekey
#cat privatekey
#cat privatekey | wg pubkey > publickey
#cat publickey
wg genkey | tee privatekey | wg pubkey > publickey
- Information actually stored
- Allowed peering IP ranges
- Public key
- Instance Mapping
- keepalive
- No need to store this information for peer configuration
- Endpoint address
- Endpoint port
Created with peer generator
For mobile devices, register with QR on the screen
- The endpoint is the Listen Port of the instance
- Name definition
- Definition of allowed IPs: Must contain the same band as the instance. ex)
10.0.X.X/24 - KeepAlive:
25 - Caution:
- Must proceed with client registration.
-
Private keys cannot be viewed after this screen
-
Click the Apply button
Client
Installation
Config
interface: Client tunnel settings (not saved on the server. For defining client configuration)Address: IP range to be used by the tunnelDNS: Private DNS to use on the client sidepeer: Connection configuration information with peerAllowedIPs: VPN Tunneling RangeEndpoint: VPN instance endpoint- Sample
[Interface]
PrivateKey = <secret>
Address = 10.0.X.X/32
DNS = 192.168.118.53
[Peer]
PublicKey = <secret>
#AllowedIPs = 0.0.0.0/0
AllowedIPs = 10.0.X.X/24, 118.37.2.0/24, 192.168.118.0/24
Endpoint = <ddns>:41821
PersistentKeepalive = 25
Mobile
- Use QR in WireGuard App
PC
Understanding AllowedIPs
-
A tunnel is used when the IP of the destination traffic requested by the client is in Allowed.
-
All:
0.0.0.0/0โ DNS query may not be possible when tunneling all traffic, so declare
DNS = 8.8.8.8, 1.1.1.1inInterface. -
VPN band (required):
10.0.X.X/24 -
WAN Band (check my settings):
118.37.2.0/24
-
All:
-
Copy the config on the peer generator side to configure the tunnel
Issues
Add port forwarding
- WAN Interface: WireGuard Instance
- If configured as above,
WAN address: 41821forwarding is required -
Note
โ Configuration
โ Interface:WAN
โ Protocol:UDP
โ Destination:WAN address
โ Destination port range:41821\~41821
โ Destination IP redirection:Single host or networkโ127.0.0.1/32
โ Destination port redirection:41821
Check status
Feature: WAN Service Port Security (Dest WAN)
-
Add interface
- Note:
- Since it is a tunnel interface, just enable the IPv4 configuration type to None.
-
Client Setup
- Allow VPN bandwidth and WAN bandwidth
AllowedIP = 10.0.X.X/24, 118.37.2.0/24
- VPN Interface: Service Port
All ports other than the WireGuard Instance are not exposed to the WAN.
- AS-IS port forwarding policy:
- Interface:
WAN - From:
any - Destination:
WAN address - Destination IP redirection:
Single host or network
- Interface:
-
TO-BE Port Forwarding Policy (Dest WAN):
- Interface:
VPN1 - Source:
VPN1 net - Destination:
WAN address - Destination IP redirection:
Single host or network
Example)
- Interface:
Feature: WAN Service Port Security (Dest New Subnet) (for DNS)
Arbitrarily define a new NAT band.
- If you use the existing
192.168.1.0/24, when accessing from the internal wifi, the DHCP internal network is given priority and access becomes impossible. - In the case of a mobile phone, it was able to connect even if it was connected to WiFi, but I wasted quite a bit of time on this issue. I think they probably used LTE because priority access to the internal network was not possible.
- In my case, I defined the band
192.168.118.0/24.
Advantages
- IP can be divided, eliminating insignificant ports.
- Private DNS binding becomes possible.
- SSL configuration becomes possible.
Disadvantages
-
Cumbersome compared to WAN.
-
Client Setup
- VPN band, WAN band, new subnet allowed
AllowedIP = 10.0.X.X/24, 118.37.2.0/24, 192.168.118.0/24
- VPN Interface: Service Port
-
Port Forwarding Policy (Dest new Subnet):
- Interface:
VPN1 - Source:
VPN1 net - Destination: Freely configured within the range
192.168.118.1 to 192.168.118.255(single host) - Destination IP redirection:
Single host or network
Example)
- Interface:
-
DNS Setup
-
SSL Setup
CLI




Leave a Reply