There are several tools in Linux that can help detect the NAT (Network Address Translation) type of your network.
However, detecting the exact NAT type (such as “strict,” “moderate,” or “open”) as it is often categorized in gaming consoles isn’t always straightforward on Linux. Still, some tools can help you determine whether you’re behind a NAT, and what kind of NAT is in use.
Tools to Detect NAT Type on Linux
STUN (Session Traversal Utilities for NAT)
- STUN is a protocol used to discover the presence and type of NAT.
- STUN client tools can help you determine whether you are behind a NAT and the behavior of that NAT (e.g., full-cone, restricted-cone, or symmetric NAT).
Install and Use STUN client:
sudo apt install stun-client
Usage:
stun stunserver.org
This command will give you information about your public IP and whether your internal IP is being translated, which indicates NAT is in place.
Example output:
STUN client version 0.97
Primary: Independent Mapping, Independent Filter, preserves ports, no hairpin
Return value is 0x000013
- The result will describe the type of NAT, like Independent Mapping, which may correspond to a less strict NAT type.
You can also use third party’s servers to detect your NAT type:
stun stun.l.google.com:19302
stun stun.stunprotocol.org:3478
stun global.stun.twilio.com:3478
UPnP (Universal Plug and Play)
- Many routers that support NAT also support UPnP to dynamically open ports.
- MiniUPnP is a tool you can use to test whether UPnP is enabled, which is useful in determining NAT behavior.
Install MiniUPnP:
sudo apt install miniupnpc
Usage:
upnpc -s
This will provide information about your NAT setup, and whether port forwarding is enabled (indicating that UPnP is working, which generally means an “open” NAT type).