Reference · Network exposure
Open-port self-audit: what listens on your computer and what the internet can reach
List every listening port with ss -tulpn, lsof -i -P -n and Get-NetTCPConnection -State Listen, read 0.0.0.0 against 127.0.0.1, check ufw status numbered and Windows firewall rules, then test your public IP from outside.
| Target artifact | Every TCP and UDP port the computer listens on, and the firewall and router rules that decide whether other machines can reach it. |
|---|---|
| Default behaviour | Programs open listening ports as they need them. A port on 0.0.0.0, :: or * listens on every interface, and the internet can reach it when a public address or a router port forward leads to it and no firewall stops it. |
| Safe state | Only services you meant to offer listen on network addresses, everything else on 127.0.0.1; the inbound firewall default is deny; no router port forwards you did not create; a test from outside reaches only the ports you meant to publish. |
| Check on Linux | sudo ss -tulpn |
| Check on macOS | sudo lsof -nP -iTCP -sTCP:LISTEN |
| Check on Windows | Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess | Sort-Object LocalPort |
| Check from another device | Test-NetConnection -ComputerName PUBLIC_IP -Port PORT in PowerShell, or nc -vz -w 5 PUBLIC_IP PORT, from a different network |
| Fix | bind each service you do not need on the network to 127.0.0.1 or stop it, then make the inbound default deny, for example sudo ufw default deny incoming on Ubuntu |
Step 1: list what listens
Linux
sudo ss -tulpn-t and -u show TCP and UDP, -l only listening sockets, -p the program that owns each one, and -n numbers instead of names. Without sudo, the program column is empty for other users' services.
macOS
sudo lsof -nP -iTCP -sTCP:LISTEN
sudo lsof -nP -iUDP-n and -P print addresses and port numbers instead of names, which is faster and clearer. lsof -i -P -n without the filters lists every network connection, listening or not.
Windows
Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess, @{ Name = 'Process'; Expression = { (Get-Process -Id $_.OwningProcess).ProcessName } } | Sort-Object LocalPort
Get-NetUDPEndpoint | Select-Object LocalAddress, LocalPort, OwningProcess | Sort-Object LocalPortWindows normally shows some system services, such as file sharing on port 445, unless its Server service is turned off, and remote procedure calls on port 135. What matters is whether the firewall lets anyone reach them, which Step 3 checks.
Step 2: read the addresses
| Local address | Who can connect |
|---|---|
127.0.0.1, ::1 | This computer only |
0.0.0.0, ::, [::], * | Any network the computer is on, subject to the firewall |
A specific address, such as 192.168.1.20 or a public address | Anyone who can reach that address |
For each port on a network address, ask whether you meant to offer that service, and to whom. If not, set it to 127.0.0.1 in the program's settings, or stop it.
Step 3: check the firewall
Ubuntu with UFW
sudo ufw status verbose
sudo ufw status numberedThe verbose output should include Default: deny (incoming). In the numbered list, delete an ALLOW rule you did not mean with sudo ufw delete RULE_NUMBER. Ports published by Docker are not covered by these rules; see Docker published ports.
Windows Defender Firewall
Get-NetFirewallProfile -PolicyStore ActiveStore | Select-Object Name, Enabled, DefaultInboundAction
Get-NetFirewallRule -Direction Inbound -Action Allow -Enabled True | Select-Object DisplayName, Profile | Sort-Object DisplayNameEvery profile should be enabled. -PolicyStore ActiveStore reads the settings in force, Group Policy included; without it, the command reads only the locally stored settings. The second command lists the inbound rules that let traffic in; look for programs and ports you do not recognize, especially on the Public profile.
macOS
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstateThe macOS firewall is off until you turn it on in System Settings. It decides per application rather than per port.
Step 4: test from outside
A listening port and a firewall rule describe what should happen; a test from outside shows what does.
- Find your public address: on the router's status page at home, or in the hosting provider's control panel for a server.
- Look at the router's port forwarding and UPnP pages. UPnP lets programs open ports on the router by themselves; turn it off unless something you rely on needs it. The checks for the router itself are on Home router check, and those for a NAS behind it on Synology and QNAP NAS on the internet.
- From a different network, for example a phone's hotspot, test each port you care about:
Test-NetConnection -ComputerName PUBLIC_IP -Port 3389nc -vz -w 5 PUBLIC_IP 3389TcpTestSucceeded : True, or a line ending in "succeeded!" from nc, means the port is reachable from the internet. Test from outside your own network: a test of your public address from inside it can pass or fail for reasons that have nothing to do with the internet.
Note IPv6
A router's address sharing hides IPv4 devices behind one public address, but with IPv6 each device can have its own public address. If a service listens on :: and the router's IPv6 firewall allows inbound traffic, it can be reachable directly. Check the router's IPv6 firewall setting, and test the computer's IPv6 address as well.
Related guides and lookups
Sources
- Microsoft Learn: Get-NetTCPConnection
- Microsoft Learn: Test-NetConnection
- Microsoft Learn: Get-NetFirewallProfile
- Microsoft Learn: Windows Firewall rules and precedence
- Debian manual: ufw
- Docker: packet filtering and firewalls
- CISA: #StopRansomware guide, on exposed services and scanning internet-facing devices