Technical architectural analysis, practical configuration manifests, and deployment instructions for OPNsense Firewall Archi: Packet Filter & IDS.
Installation
Management
Conceptual Definition
IP Band Definition
NAT system
- WireGuard to WAN
$$
\text{Client} \xleftrightarrow{[L3]tunnel/snat} \text{VPN Interface (Original Src)} \xrightarrow{[1]blocked} \text{WAN Interface (Dst)} \xrightarrow{[2]passed} \text{Internet}
$$
- WireGuard to LAN
$$
\text{Client} \xleftrightarrow{[L3]tunnel/snat} \text{VPN Interface (Original Src)} \xrightarrow{[L3]decrypt/forward} \text{Ghost Address (Original Dst)} \xrightarrow{[L4]dnat} \text{LAN Interface (Redirection)}
$$
- WireGuard to LAN with HAProxy (for TLS Termination)
$$
\text{Client} \xleftrightarrow{[L3]tunnel/snat} \text{VPN Interface (Original Src)} \xrightarrow{[L3]decrypt/forward} \text{VIP Interface (Original Dst)} \xleftrightarrow{[L4]socket} \text{HAProxy Plugin} \xrightarrow{[L4/L7]dnat} \text{LAN Interface (Redirection)}
$$
Common
SSH Setting
System โ Settings
- Add port forwarding
Configuration
- Interface:
WAN - Protocol:
TCP - Destination:
WAN address - Destination port range:
8120\~8120 - Destination IP redirection:
Single host or networkโ127.0.0.1/32 -
Redirect destination port:
8120 -
Test
ssh -p8120 [email protected]
DNS rebinding check
- Uncheck rebinding to access the dashboard in various ways, such as DDNS, private DNS, and IP access with NAT settings
IPv6 settings
In Korea, the ISP does not assign IPv6 DHCP, so it does not work even if it is turned on.
-
WAN gateway DHCP6 is activated, but no IP address is being assigned.
-
IPv6 configuration type of initial configuration LAN Interface: Tracking Interface = WAN
-
Configure IPv6 for the LAN interface on the DHCP service side
- DHCP Server
Masquerading for VPN to WAN
Required:
- interface
โWhat is Masquerading?โ
- Background of use
- When a WireGuard client sends a
pingto8.8.8.8, the packet’s source IP address is the client’s WireGuard internal IP address. Address(e.g.10.0.X.X). - When the packet reaches
8.8.8.8,8.8.8.8attempts to send a response packet back to10.0.- However, routers on the Internet do not know the route to
10.0.- Application result
- Masquerading replaces the source IP address of every packet leaving the
with the address.OPNsenseserver's WireGuard interface with the public/external IP of theOPNsenseserver. Temporarily โmodifyโOPNsenserecords this conversion, and when it receives a response packet from8.8.8.8, it recodes the destination IP address of this response packet back inside WireGuard of the original client. Returns it to the IP address(10.0.X.X) and passes it to the client through the tunnel.- This is the act of hiding the client's private IP address behind the server's public IP address. color="yellow_bg">It is called โmasqueradingโ
Masquerading is altering the source address. In other words, it is a type of
SNAT.(default) Firewall > NAT > Outbound:
Automatically create outbound NAT rules,Create hybrid outbound NAT rulesWhen selected, Masquerading rules are automatically created for all activated interfaces(Highlite) Firewall > Rules: Add inbound rule for interface
VPN1-
Pass rule to allow the
[1]blockedsection below.โ WireGuard to WAN
> ๐ก
$$
\text{Client} \xleftrightarrow{[L3]tunnel/snat} \text{VPN Interface (Original Src)} \xrightarrow{[1]blocked} \text{WAN Interface (Dst)} \xrightarrow{[2]passed} \text{Internet}
$$ - Firewall > Rules
- However, routers on the Internet do not know the route to
Interface
Interface > Assignment
- Enter the name you want to display in the description and add
Interface > [Interface Alias]
- WAN
- IPv4 configuration type:
DHCP - IPv6 configuration type:
DHCPv6 - LAN
- IPv4 configuration type:
Static IPv4 - IPv6 configuration type:
Tracking InterfaceorNone - IPv4 address: (Set to not overlap with other LAN DHCP bands)
- ex)
192.168.1.1/24192.168.2.1/24192.168.3.1/24
-
Assign DHCP:
โ TUN (tunnel)
โ IPv4 Configuration Type:None
โ IPv6 Configuration Type:None
Interface > Device > Bridge
Bridge refers to treating two or more L2 devices (NICs) as one interface.
If physical ports are insufficient, physical ports can be increased by abstracting the interface. (= L2 switch)
-
ex:
โ LAN1:
192.168.1.1/24โ Bridge0:192.168.1.1/24
โ LAN2:192.168.2.1/24โ Bridge0:192.168.1.1/24
โ LAN3:192.168.3.1/24โ Bridge0:192.168.1.1/24
-
Bridge registration
-
Bridge Allocation
-
Interface configuration: Static IPv4 assignment (but after cleaning up existing interface configuration to avoid conflicts)
Interface > Device > VLAN
VLAN adds virtual interfaces mainly for subnetworks (LAN).
$$
\text{VLAN Interfaces} \xrightarrow{โ802.1QโTagging} \text{LAN} \xrightarrow{Trunk} \text{AP} \xrightarrow{Segmentation} \text{Clients}
$$
- In the subnetwork, interfaces are distinguished using VLAN tagging (
802.1Q) - Use multiple subnets on LAN1, which is actually received ex:
- LAN1:
192.168.1.1/24 - LAN1_VLAN10:
192.168.10.1/24 -
LAN1_VLAN20:
192.168.20.1/24 -
VLAN definition
Interface name parent interface VLAN ID Band Allocation Use and Description LAN1 โ โ 192.168.1.0/24Network device management vlan01.010 LAN1 10 192.168.10.0/24Physics Hosts (Harvester) vlan01.020 LAN1 20 192.168.20.0/24Wireless Client (WiFi) vlan01.021 LAN1 21 192.168.21.0/24Wireless Client (Overseas VPN) vlan01.030 LAN1 30 192.168.30.0/24Internal Service (VPN Only) vlan01.040 LAN1 40 192.168.40.0/24External Service (Cloudflare Tunnel) vlan01.041 LAN1 41 192.168.41.0/24External Service (Cloudflare Proxy) -
Create VLAN
- Device: Automatically created if not entered
- Parent: Host LAN
-
VLAN tag:
2 to 4094 -
VLAN assignment
-
Interface Configuration: Static IPv4 Assignment
-
DHCP range settings
LAN1 was divided into VLANs, but the AP device AX2004M did not recognize VLAN tagging (802.1Q).
This problem can be solved when using openwrt OS.
What is MACVLAN?
MACVLAN adds a virtual interface primarily for higher-level networks (WAN).
$$
\text{ISP DHCP Server} \xrightarrow{Leasing} \text{WAN}\xleftarrow{vMAC} \text{MACVLAN Interfaces}
$$
- In the upper network, interfaces are distinguished using only
MAC Address, so each receivingWANport must have two or moreMAC Address - OPNSense is not supported by default, but since the
WANport configuration is spacious, it is not necessary if you only have an ISP modem port. (Router devices typically have one listeningWANport)
Interface > Device > VXLAN
VXLAN is building an L2 network using L3 tunneling. (L2 over L3)
Mainly used when L2 level combination is required in communication with remote locations.
- ex:
- K8s clustering of cloud infrastructure and on-prem servers, etc.
Interface > Virtual IP (VIP) > Settings
- Considering convenience and necessity, two types of virtual networks are needed.
When configuring DNAT, external access works well using Ghost IP, but without VIP, internal to external calls are not smooth. In the end, a VIP declaration is needed
Ghost Address Band: OPNSense Interface that does not exist anywhere (convenient as it does not need to be defined separately)
- When using the
Firewall > NAT > Port Forwardingfunction, you can redirect by declaring it as a destination even if there is no actual interface, so there is no need to useVIP.
VIP Band: A virtual interface recognized by OPNSense.
-
In plugins, etc., the existence of a Socket Connection is required.
-
DNS maps to the virtual address of the defined band.
-
The subnets below do not actually exist, and if you define and declare them for convenience, it is convenient for future maintenance.
- OPNSense DNAT โ VIP Net:
192.168.118.0/24 - HAProxy DNAT โ VIP Net:
192.168.119.0/24
โ Meaning of 192.168.119.3/24
โ NetMask: 255.255.255.0
โ Affiliated network range: 192.168.119.0
โ Host IP: 192.168.119.3
Firewall
Firewall > NAT > Port Forwarding
โ If the destination port is not :443, it is not automatically redirected to https.
โ This problem can be handled by redirection in HAProxy or nginx plugin
โ If you want to apply an SSL certificate for the public domain, you can use Letโs Encrypt with the ACME Client plugin.
- Basic usage:
- Select WAN interface
- Destination: WAN address
- Redirection address: application endpoint subnet (set to
/32for single server) -
Rule: Automatically maps to WAN firewall rules
-
Enforce service port security:
Firewall > Rules
- Except for special purposes, all added Optional Interfaces are allowed for inbound that originates from them.
Firewall > Aliase > GeoIP Setup
\~ opnsense team \~
In our experience, IPinfo provides much larger and more detailed data sets. If you use a different country from the list, don’t forget to increase Firewall โฃ Settings โฃ Advanced: Firewall Maximum Table Entries higher. As of this writing, the total number of items in the list is approximately 7 million.
- IPinfo GeoIP
- IPinfo GeoIPโs Setup โ OPNsense documentation
-
steps
- Create your IPinfo account: Create your IPinfo account | IPinfo.io
- Find your license key: ipinfo.io
-
Clone the API Token from my dashboard
-
OPNSense’s GeoIP settings: Insert the following into URL and apply
https://ipinfo.io/data/ipinfo_lite.csv.gz?token=
Add-ons
Common
-
DDNS Client
-
Dynamic Routing (FRR)
-
TFTP Server
os-tftp- WOL
os-wol- SMTP Server
Backup Option
- git-backup plugin
VPN Server & Client
- pre-installed
- OpenVPN
- IPSec
DHCP Server
- dhcp plugin
- (default)
LAN1Interface is set by default.
L7 (Application) Management
- DNS
- (default)
-
TLS
-
private TLS:
-
public TLS:
-
TLS Termination
-
private TLS:
-
LoadBalancer
Observability
- Logging
os-beats- Monitoring
os-node_exporter
Restore a Backup
If you set things like LAN1 incorrectly, you may lose access to the dashboard completely.
Don’t do anything like setting up a bridge like I did.
- Donโt panic and go to the equipment with a portable monitor and keyboard.
- Select
13) Restore a backupas follows to find and restore an appropriate backup copy from recent records
CLI
-
WireGuard




Leave a Reply