Walker News

Linux Commands To Check Network Connection

lsof vs netstat – which of these two Linux networking commands works better, if you want to find out which Linux networking program is running on or openning a TCP/IP network port? Take a look on these commands output, you might get the answer then.

Netstat is almost a generic networking command, although its functions or features might be varied across the diverse system platforms. The Linux netstat command is used to check or print the TCP/IP network activities of both active (established) and inactive (listening) ports. You can tweak the netstat command with its supported option switches for more useful TCP/IP network statistics.

lsof vs netstat - which of these two Linux networking commands works better, if you want to find out which Linux networking program is running on or openning a TCP/IP network port? Take a look on these commands output, you might get the answer then.

I used to run netstat -tulpan on both Redhat and Debian Linux servers for network-related support calls. These netstat command option switches will tell me what a networking program is doing – the TCP/IP protocol in used (TCP / UDP), number of bytes dropped, local network port and its connected port at remote server (established) or local listening port of the daemon (server), the name and process ID of the networking program.

Today, however, I couldn’t find an in-house developed daemon (which we call it XML-Server) with my favourite netstat -tulpan command!

As shown in the diagram, login with root user ID and executing command netstat -tulpan | grep 2020 shows that the network port 2020 is opened and listening for connection, but the XML-Server program is unknown. When grep network port number 389, I can see the Open-LDAP daemon as well as its associated process ID in the list. (So, I’ve login as root and only root user privilege can run netstat with -p option to print all networking utilities that are running on the Linux system!).

After googling, I learnt a new Linux command. Essentially, lsof is another great Linux command used to print or find out the system resources that are currently using or holding by Linux processes!

Now, executing lsof -i | grep 2020 or lsof -i | grep xmlserver is showing me the XML-Server daemon and its process ID. Then, I can issue kill -9 command to kill off XML-Server program as part of the troubleshooting process.

Of course, I can simple run ps -elf | grep xmlserver to get the process ID and kill it. But, what if you only know the network port but not the program name, or the network port and program are both being unknown?!

Custom Search

  1. Df And Du Command Show Different Used Disk Space – Walker News 13-07-07@23:06

    [...] this particular scenario, the lsof command (list open file command) is great to show [...]

  2. How To Setup IBM DB2 Control Center – Walker News 25-01-08@12:22

    [...] the DB2 server side configuration completed, execute either the netstat or lsof command (with root user account) should able to show the port is opened and listening for [...]

  3. MySQL Dummy Guide: How To Output SQL Results To A Log File? – Walker News 06-07-08@21:22

    [...] tee mysql command gets the SQL result output to two places at the same time, just like the tee Linux command [...]

  4. guest 13-08-09@21:52

    Another useful tool is iftop.
    iftop – display bandwidth usage on an interface by host

    It was useful to me when I wanted to know who was connected to my server via udp.

  5. G-Men 06-11-12@00:58

    you can provide the port straight to lsof with a colon … lsof -i :1234..
    If you want to monitor the port for incoming connections you can use the command “watch”.
    #watch -n3 lsof -i :1234
    This refreshes the information lsof every 3 seconds.
    Hopes it helps

2014  •  Privacy Policy