Troubleshoot port conflicts Linux

Troubleshoot port conflicts Linux

Troubeshoot port conflicts Linux

Port conflicts can happen on any OS, you just have to know the correct tools to troublshoot them. on UNIX/Linux systems you want to use netstat, and lsof to diagnose your port issues.

let’s say we are having a conflict with port 30365, and we were unsure what application was using it.

Netstat:

the netstat tool shows communications of ports on the localhost. To understand the full usage, check out man netstat.

For the purpose of this example, we want to check if 30365 is ALREADY listening, or being used. We can verify that there is a TCP port 30365 being used.

if you do netstat -a, you can also see if there’s established connections to that port from another host

so in this example, there are two sessions “established” from “web2” to “tomcat1” on that port.

Ok, this narrows it down a bit further, but let’s say we had MANY web or tomcat, or other application instances, how would you narrow it down to a specific application, or process?

LSOF:

this part can only be run as root, you may not get any results if ran as a standard user.

the basic syntax is “lsof -i :port-number

so in the above example, we can see that TCP port 30365 is listening for the command “java” with the particular PID that created it, as well as the service account, or account that that port is running as.

Additional Considerations:

What if the port does not show up in netstat or lsof?  Perhaps the application is improperly closing the socket, and it’s actually still open, but there’s no process associated with it. The only resolution for this scenario is to reboot the UNIX/Linux system to free the original port.

That’s it!

Hosted Linux Servers at www.zwiegnet.com/go

Leave a Reply

Your email address will not be published. Required fields are marked *