← Back to Blog

How to Work Out Which Port Your App Actually Needs Open

Your app works on your laptop but not on the server. Find the exact port it listens on, and the one mistake that makes firewall rules useless.

Somebody asks you to open a port for an app, and the form wants a number. You type 8080, because that is the number in the tutorial you half remember, and nothing works. Or the opposite: your app runs fine on your laptop, you move it to a server, and it goes silent. I have done both, and the fix in each case was the same: stop guessing the port and ask the machine which one the app actually holds.

A port is not a property of a server. It is a number one specific process asked the operating system for, so it could accept connections. There are two ways to find the number, and they answer different questions. From inside the machine, the kernel tells you the truth. From outside, you can only knock and listen for an answer, and a firewall can fake that answer. Start inside whenever you can.

Start inside: ask the kernel on Linux

On a modern Linux server, the command is ss -tulpn: t for TCP, u for UDP, l for listening only, p for the process holding each socket, n to skip name lookups so the output stays fast and readable. Run it with sudo, or the process column comes back empty for sockets owned by other users.

Here is what it looks like on a real machine I had open while writing this, one line only:

tcp LISTEN 0 0 127.0.0.1:8089 0.0.0.0:* users:(("php",pid=24683,fd=3))

Read it left to right. A process called php, process id 24683, is listening on TCP port 8089. That is the whole answer for that app: the port it needs open is 8089, not the 8000 or 8080 you might have guessed. The address in front of the port matters just as much, and it is the part people skip. 127.0.0.1 is the loopback address, this machine only, so that php process answers a browser on the same machine and nobody else, whatever your firewall says. To reach the world, the app has to bind to 0.0.0.0, all interfaces, or to the server's real address.

If you already suspect a port, check just that one with ss -tlnp 'sport = :8080'. The filter matches 8080 exactly, so it will not also return 8081 or 18080 the way a careless grep would. No output means nothing is listening there.

Windows and macOS: the same question, different tools

On Windows, open a terminal as administrator and run netstat -ano, then narrow it with findstr :8080. The last column is the process id, and Task Manager turns that number into a name. On macOS, lsof -nP -iTCP -sTCP:LISTEN lists every listening TCP socket with the process name beside it. Same idea in all three: find the process first, read its port second.

When you cannot get inside: knock from outside

Sometimes there is no shell. A client hands you a hostname and says the app should be up, or you are checking a server someone else manages. Then the only honest test is to connect, which is what our Port Checker does. Type the host and it attempts a real connection to the common ports, then reports each one as open, or closed or filtered. Open means something answered. Closed or filtered means the service is not reachable, whether because nothing listens there or because a firewall is in the way. We report those two together on purpose, because one knock from outside cannot honestly tell them apart.

I ran it against this site while writing: websmartools.com on port 443 comes back open, no surprise, since the whole site is served over HTTPS on 443. The check proves the port answers from the internet. It does not prove which process holds the port. Use it to confirm a firewall change landed, not to discover what an app needs.

One warning: an outside check can mislead. A firewall can refuse a connection for a port nothing listens on, and it can stay silent in front of a live one. If the outside check and the inside check disagree, trust the inside one. If the outside check disagrees with what you expected, our post on whether a closed port is your router, your ISP or your host walks through which layer is lying.

The mistake I see most: the port is open, but the app is not listening to you

Here is the scenario that eats an afternoon. You find the port, say 8089. You open 8089 in the firewall, in the cloud security group, in the router, everywhere. You test from your laptop and get nothing. Then someone runs ss on the server and the line reads 127.0.0.1:8089.

The app was never listening to the network. It was listening to itself. Most development servers default to the loopback address on purpose, so a half-finished app is not exposed while you build it, and plenty of production services keep that default because nobody changed it at deploy time. The fix is in the app's config, not the firewall: bind to 0.0.0.0 or to the server's own address, restart the app, and run ss again until the line shows 0.0.0.0:8089. Only then does the firewall rule have anything to protect.

UDP plays by different rules

Everything above is TCP, the easy case, because a listener has a state you can see. UDP has no connections and no LISTEN state, so ss -ulpn shows you sockets that exist, not proof that something answers. DNS on port 53 and many game and voice servers live here. The only real test for a UDP port is to send it the traffic it expects and see if it replies, a DNS query for a DNS server, for instance. If your app uses UDP and the TCP checks all look clean, you are probably looking in the wrong place.

The order to work in

First, get inside the machine and run the listening-sockets command for your system, and write down the port, the bind address and the process name. Second, if the bind address is 127.0.0.1 and you need the world to reach it, fix the app's config and restart, then re-check. Third, open the port in the firewall, and only that port. Fourth, verify from outside with the Port Checker, from a different network if you can, because your own network can hide problems, as our post on whether a site is really down or just blocked on your network explains. A port that is open on the server, open in the firewall and answering from outside is a solved problem.

A new post lands here every day. If there is a topic you want covered, email ask@websmartstudios.com.