OPNsense Forum

English Forums => General Discussion => Topic started by: Forceflow on December 21, 2024, 01:04:06 PM

Title: NAT Outbound rules, static ports and game consoles
Post by: Forceflow on December 21, 2024, 01:04:06 PM
Hey everyone,

I'm trying to replace my old trusty Edgemax Edgerouter ERP-5 (because Unifi does not care about these Edgerouters any more, it seems) with a new shiny OPNSense device from Protectli. It's going well, but I've got one thing that puzzles me. First, my network topology:

(internet) -> ISP modem/router (192.168.0.1) -> OPNsense with static WAN IP (192.168.0.220) -> My LAN and all my devices (192.168.1.x)


There is just one thing that's bugging me: I'm an avid gamer, and when I use my Edgerouter, all my consoles / PC games report NAT type 2 (moderate). When I use my new OPNSense box, that reverts to NAT type 3 (strict).

The initial reaction would be: just start configuring UPNP, but here's the thing: on my Edgerouter I could get to NAT Type 2 without having to resort to UPNP (simply not configured), and I'd like to replicate that exact behavior. I want a baseline to start from that is identical to what i had :).

I figured out it probably has something to do with outbound NAT rules, and the port selection. OPNSense, by default, randomizes the outbound port during the translation, for security reasons, if I am correct. I think my Edgerouter, by default, uses static ports mapping for outbound NAT (no randomization) for EVERY LAN CLIENT, and that makes everything "just work" to get to NAT Type 2.

In order to replicate this behavior in OPNSense, I've set Outbound NAT to Hybrid mode, copied the default auto-generated outbound rule to this section and just enabled the static port setting. For all traffic and clients, because most of the clients on my network use some online game functionality (laptops, consoles, ...). This change does indeed result in all consoles and game PC's reporting NAT Type 2 / Moderate behavior. Hurray.

Here's my questions:

Thank you for reading this, and happy holidays to you all.

Title: Re: NAT Outbound rules, static ports and game consoles
Post by: Seimus on December 21, 2024, 01:22:38 PM
You are basically correct,

Out of the BOX the NAT rules on OPNsense use static port only for IPSEC. All other traffic doesn't use this feature. This is as well the reason why you see a lower grade of NAT type reported by the console services.

Personally I would avoid uPnP as it opens ports per need per application/host, it can wreck havoc and from essence something that opens ports as it likes is never good security wise.

In a small network setup chance that two ports would collide in regards of Static port feature is low. Yet it can occur. You can create a NAT rule to only match a specific Alias, e.g devices that that will hit the NAT rule with static port turned on.

Overall I rather prefer static port NAT rule than uPnP.

Regards,
S.
Title: Re: NAT Outbound rules, static ports and game consoles
Post by: Forceflow on December 21, 2024, 01:28:33 PM
Thank you. And the reason I did not encounter any problems with the Edgerouter setup is because I don't have, let's say, two XBOXes trying to play on the same game server at the same time, right?

Because the problem technically would occur when you have this situation:

(XBOX 1) 192.168.1.240:12345 -> (map to WAN IP, keep port) WAN IP:12345 -> (same XBOX GAME SERVER IP)
(XBOX 2) 192.168.1.241:12345 -> (map to WAN IP, keep port) WAN IP:12345 -> (same XBOX GAME SERVER IP)

And then there is ambiguity of what to do with return packets.
Title: Re: NAT Outbound rules, static ports and game consoles
Post by: Seimus on December 21, 2024, 01:48:53 PM
Correct,

The Static port, prevents PNAT of the source port

https://docs.opnsense.org/manual/nat.html

QuoteStatic-port
Prevents pf(4) from modifying the source port on TCP and UDP packets.

But keep in mind usually the the Source ports of the Source IP are dynamic, So even for two different hosts in LAN to choose the same Source port is very low. There are services that need a specific Source port to Specific Destination port. But for Service like online gaming, multiplayer etc. this usually is not the case.

That is as well the reason why Of the shelf routers run with Static port option hardcoded.

Regards,
S.

Title: Re: NAT Outbound rules, static ports and game consoles
Post by: Forceflow on December 21, 2024, 01:57:30 PM
True, most devices to port randomization themselves, but it seems some (P2P, I think?) game clients and consoles really only work on specific ports, that they need a specific reply to.

Anyway, I'm glad my diagnosis seems correct - I've learned A LOT about NAT in the past days. That's what you get from upgrading to enterprise solutions, I guess.
Title: Re: NAT Outbound rules, static ports and game consoles
Post by: Bob.Dig on December 21, 2024, 05:01:08 PM
Quote from: Seimus on December 21, 2024, 01:22:38 PMOverall I rather prefer static port NAT rule than uPnP.
I would do both for a game-centric subnet. :)
Title: Re: NAT Outbound rules, static ports and game consoles
Post by: Forceflow on December 21, 2024, 07:16:14 PM
Quote from: Bob.Dig on December 21, 2024, 05:01:08 PM
Quote from: Seimus on December 21, 2024, 01:22:38 PMOverall I rather prefer static port NAT rule than uPnP.
I would do both for a game-centric subnet. :)
Doesn't that conflict with eachother? Or is UPNP just inbound port forwarding, and nothing to do with the outbound NAT?
Title: Re: NAT Outbound rules, static ports and game consoles
Post by: Seimus on December 21, 2024, 09:15:07 PM
uPnP tends to open ports (Port forwarding If I am not wrong), and that it is its major benefit as well negative.
Back in the past there was some goofy behavior caused by uPnP like not closing the ports etc. (you can search thru the forum). But for some time I didnt heard anything weird about it.

uPnP plugin offers you certain configuration in OPNsense, like specify which host can use it.

By using "game-centric subnet" is that if you use VLAN isolation and have a specific network/VLAN just for game devices you can potentially limit the cascade of impact in case you miss-configure uPnP.

Anyway, if you do not require uPnP just configure the NAT in Port-static mode. As mention that should work without problems.

Regards,
S.