Search code examples
ubuntufedoranetcatnetstat

Netstat in Fedora doesn't list simple netcat server, Ubuntu does


I'm opening a simple TCP server with netcat:

$ netcat -l -p 1234

Then I want to check if it's listed among the listening tcp connections by netstat:

$ netstat -lt

If I issue the previous commands on an Ubuntu system

$ uname -v
#65~14.04.1-Ubuntu SMP Tue Apr 19 18:57:09 UTC 2016

my server is correctly listed:

$ netstat -lt
...
tcp        0      0 *:1234                  *:*                     LISTEN
...

If I do the very same thing on a Fedora system:

$ uname -r
3.17.4-301.fc21.x86_64

in this case I can't find my server:

$ netstat -lt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:search-agent    0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN     
tcp6       0      0 [::]:search-agent       [::]:*                  LISTEN     
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN 

This problem also happens when I write a program opening a server socket, and I need to write a test to automatically check if the server is listening on the correct port (works on Ubuntu, not on Fedora). Is it possible to make this kind of check on Fedora using netstat at all?


Solution

  • Ubuntu probably has different default switches for netstat than fedora , so you are seeing "symbolic" names for ports instead of port numbers. Add switch -n to fedora netstat (IIRC) to use numeric ports.