πŸ”’ Complete Guide: Setting Up a Webserver Behind OPNsense

πŸ“˜ PURPOSE: This guide documents the entire process of exposing a webserver to the internet through an OPNsense firewall, including all the issues I faced and the solutions that worked.
🌐 IMPORTANT NOTE ABOUT DYNAMIC IPs: My public IP changed during this process, which required updating my DNS records. If you're using a dynamic DNS service, make sure your client is configured to update automatically when your IP changes.

πŸ–₯️ Part 1: Server Preparation

1.1 Set a Static IP for Your Webserver

Option A: DHCP Reservation in OPNsense (Recommended)

Find your server's MAC address:

ip a | grep link/ether

In OPNsense: Services > DHCPv4 > [LAN] > DHCP Static Mappings

Add entry with:

Option B: Static IP on Server

# Example for Ubuntu/Debian
sudo nano /etc/netplan/01-netcfg.yaml

Configure (replace with your network range):

network:
  version: 2
  ethernets:
    ens18:
      addresses:
        - 192.168.x.xxx/24
      gateway4: 192.168.x.1
      nameservers:
        addresses: [192.168.x.1, 1.1.1.1]

1.2 Verify Gateway

ip route | grep default

Should show: default via 192.168.x.1 dev [interface]

1.3 Test Local Access

From another device on your LAN:

ping 192.168.x.xxx
curl http://192.168.x.xxx

πŸ”Œ Part 2: OPNsense Configuration

2.1 Create Destination NAT (Port Forward) Rules

Navigate to Firewall > NAT > Destination Nat > Port Forward

Click Add to create a new rule

HTTP Rule (Port 80):

FieldValue
InterfaceWAN
ProtocolTCP
DestinationWAN address
Destination portHTTP (80)
Redirect target IP192.168.x.xxx
Redirect target portHTTP (80)
DescriptionWebserver HTTP

HTTPS Rule (Port 443):

FieldValue
InterfaceWAN
ProtocolTCP
DestinationWAN address
Destination portHTTPS (443)
Redirect target IP192.168.x.xxx
Redirect target portHTTPS (443)
DescriptionWebserver HTTPS
⚠️ CRITICAL STEP: For BOTH rules, scroll to the bottom and change:
FieldSet to
Firewall rulePass (NOT "Manual")
πŸ”‘ WHY? This tells OPNsense: "This NAT rule itself allows the trafficβ€”no separate WAN firewall rule needed." This bypasses any WAN rule ordering issues and was the key to getting it working.

2.3 Apply Changes

Click Apply at the bottom of the page.

πŸ” Part 3: Testing & Verification

3.1 Test Internally First

From another LAN device:

curl http://192.168.x.xxx
curl https://192.168.x.xxx

3.2 Find Your Public IP

In OPNsense: Check Interfaces > [WAN]

Or Google "what is my ip"

πŸ”„ WHAT I LEARNED: My public IP changed during this process, which meant I had to go back and update my DNS records. If you're using dynamic DNS, make sure your client updates automatically!

3.3 Test Externally

From a device NOT on your network (cellular data, friend's house):

http://[your-public-ip]
https://[your-public-ip]

3.4 Check Logs

In OPNsense: Firewall > Log Files > Live View

Look for entries showing your external IP and port 80/443 traffic.

🧠 Part 4: Common Issues & Solutions

Issue 1: "No traffic in logs" / "Packets not reaching router"

Likely CauseSolution
Firewall rule set to ManualChange to Pass in NAT rule
WAN rules stuck at bottomBypass with Pass option (no separate WAN rules needed)
CGNAT from ISPCheck if WAN IP is in 100.64.0.0/10 rangeβ€”call ISP for public IP

Issue 2: Works Internally but Not Externally

Check ThisWhat to Look For
ISP blocking portsTest with high port (8080) temporarily
NAT rule sourceShould be any (not WAN net)
Webserver firewallTemporarily disable: sudo ufw disable

Issue 3: One Port Works, One Doesn't

ScenarioFix
HTTPS works, HTTP doesn'tAdd missing floating rule or ensure both NAT rules set to Pass
HTTP works, HTTPS doesn'tCheck webserver has HTTPS configured

Issue 4: Can't Access from Internal Network Using Public IP

Enable NAT Reflection:

  1. Go to Firewall > Settings > Advanced
  2. Check Reflection for destination NAT
  3. Check Automatic outbound NAT for Reflection
  4. Apply

🚨 Part 5: Critical Lessons Learned

πŸ”‘ THE MOST IMPORTANT SETTING:

Always set "Firewall rule" to "Pass" in your Destination NAT rules. This:

πŸ“‹ Rule Order Matters

πŸ§ͺ Test Methodically

πŸ’‘ When All Else Fails

βœ… Checklist for Future Setup


πŸ“ This guide captures every hurdle I faced and the exact solutions that worked. Save it for future reference!

β€” Wapiti Labs

← Back to Projects