Skip to main content
38 votes

What's the easiest way to find an unused local port?

One-liner I've put together a nice one-liner that quickly serves the purpose, allowing to grab an arbitrary number of ports in an arbitrary range (here it's divided in 4 lines for readability): comm ...
stefanobaghino's user avatar
22 votes
Accepted

reading TCP connection list from /proc

There are many misunderstandings in your approach. I'll go over them one by one. Sockets are not associated with a specific process. When a socket is created its reference count is 1. But through ...
kasperd's user avatar
  • 3,680
18 votes
Accepted

Is there documentation for /proc/net/netstat and /proc/net/snmp?

The /proc/net/* files are generated by the kernel: the entries are in net/ipv4/proc.c in the kernel source, and the entry list is found in include/uapi/linux/snmp.h. It grabs the values from various ...
ErikF's user avatar
  • 4,207
14 votes
Accepted

Why is netstat deprecated?

Found an article on deprecation from 2011. It seems like the whole net-tools package was not maintained for a while and so it was deprecated. In Debian 9 it is not even installed by default. From the ...
Nux's user avatar
  • 1,128
13 votes

How to figure out the meaning behind Recv-Q and Send-Q from netstat?

tcp 8216172 0 127.0.0.1:9503 127.0.0.1:47654 ESTABLISHED 34390/python means that process 34390 has a connection open, between port 9503 on the local host, and port 47654 on the local host, and that ...
Stephen Kitt's user avatar
11 votes
Accepted

Given a service name, get its port number?

There are two standard library calls; getservbyname(3) and getservbyport(3). These allow programs to convert a name (e.g. telnet) to a port (23), or from a port back to a name. The typical ...
Stephen Harris's user avatar
10 votes

chromium browser (pepperflashplugin) opening listening ports on 0.0.0.0:5353

To disable mDNS and SSDP you now have to set up a policy. The browser looks for a policy config file in the following directory: Google Chrome: /etc/opt/chrome/policies Chromium: /etc/chromium/...
python_nube's user avatar
9 votes

port being in use not displayed in netstat output

Just had a similar case on Ubuntu 14.04. Indeed jenkins default port (8080) is mapped to "http-alt" name in /etc/services. You can easily check this with grep 8080 /etc/services http-alt 8080/tcp ...
dmytro.poliarush's user avatar
9 votes

Incoming and outgoing traffic when NOTHING is running

Those packets you are seeing are regular multicast services (and while the process is similar to broadcast packets, they are not broadcasts per se); their output traffic in the network is also (...
Rui F Ribeiro's user avatar
8 votes
Accepted

What is this : ^[3;J^[H^[2J?

It is the output of the clear command … You ran clear. clear produced these control sequences. (They are merely in a different order on my machine.) % clear | cat -v ; echo ^[[2J^[[H^[[3J % ...
JdeBP's user avatar
  • 71.9k
7 votes

Finding the PID of the process using a specific port?

I'm working on a Yocto Linux system that has a limited set of available Linux tools. I managed to find the process of a running port using the following commands (where I find the process using port ...
Daniel Jonsson's user avatar
7 votes

What's the easiest way to find an unused local port?

This is the version I use: while port=$(shuf -n 1 -i 49152-65535) netstat -atun | grep -q "$port" do continue done echo "$port" The command shuf -n 1 -i 49152-65535 gives you a "random" port ...
pfo's user avatar
  • 73
7 votes
Accepted

What does address 224.0.0.251:5353 represent?

224.0.0.251 is Multicast DNS, and it use the port 5353 (as you noticed). Many operating systems use it to discover new devices/printers/routers with zero or nearly zero configuration. E.g. if you want ...
Giacomo Catenazzi's user avatar
5 votes
Accepted

Netstat doesn't show my machine IP as listening on port 22

You machine is listening to port 22. Here's the line: tcp6 0 0 :::22 :::* LISTEN The socket is listening for both IPv6 and IPv4 connections.
Johan Myréen's user avatar
5 votes
Accepted

what does mean 0.0.0.0:22 under the column local address of netstat command?

0.0.0.0:22 in local address column means ssh daemon listen on all local ip. So, if you have 2 IPs (say 192.168.0.10 and 90.87.65.123), your ssh daemon will listen on both IPs (and, of course on 127.0....
Renaud's user avatar
  • 181
5 votes

Port 3000 is always being hogged by grafana-server

I have been struggling to figure this out for mac. This page kept showing up. So, to help other mac users please use the following command brew services stop grafana
dev-katiyar's user avatar
5 votes
Accepted

Which interface does a specific IP address will get routed over?

ip route get is what you're looking for; maybe it's ip route show to, depending on whether you checking should be allowed to change the routing state. See man ip-route for more details.
Marcus Müller's user avatar
4 votes

What's the easiest way to find an unused local port?

If you have python lying around, I'd do this: port="$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1])')"; echo "Unused Port: $port"
MatrixManAtYrService's user avatar
4 votes

Netstat output line width limit

You can notice that the line width of the second output is short (ends at [). Is there any way so I get the proper output from netstat? Unfortunately the width of the PID/Program name column in ...
bigbear3001's user avatar
4 votes

netstat output is "ESTABLISHED -" (no program name attached). What is the issue?

Since you are using root account, you can see all processes of all users so - indicates that connection is handled by kernel. In order to handle connection you have to call listen() function with ...
mrc02_kr's user avatar
  • 2,023
4 votes

Is there documentation for /proc/net/netstat and /proc/net/snmp?

netstat -s has comments for each line
Rob P's user avatar
  • 51
4 votes
Accepted

Process appear by "netstat" but doesn't appear by "ps -a"

A simple ps shows only your own processes, not system processes or other users' processes. ps allows options to show more processes, e.g. ps ax or ps -e or ps -A. ps -a doesn't show the process ...
Bodo's user avatar
  • 6,441
4 votes

How can I verify that the port forwarding is established by checking the sockets?

There are many complementary ways of doing it: On your local machine You can run your ssh command with -v option, and there will be information about forwarding: debug1: Local connections to ...
DevilaN's user avatar
  • 2,146
4 votes
Accepted

Does `netstat` output different sockets with and without -n?

It's likely that one of the ports from the 720 list was simply removed in-between those runs; there should be no substantive difference in the number of outputs with or without -n. You're seeing ...
Jeff Schaller's user avatar
  • 68.8k
4 votes
Accepted

What do `0.0.0.0:*`, `[::]:mysql`, and `[::]:*` mean in netstat output?

0.0.0.0:* typically appears at the remote side of listening sockets, and indicates that remote address and port fields have not been filled in yet... which is logical for a socket that is listening ...
telcoM's user avatar
  • 114k
4 votes
Accepted

Why does postgresql server have a `localhost:57504` to `localhost:57504` UDP "connection"?

A little bit of digging this is the stats collector. Apparently stats are posted on local loopback (aka localhost) UDP. See here: http://www.neilconway.org/talks/hacking/ottawa/ottawa_slides.pdf . ...
Philip Couling's user avatar
4 votes

netstat cannot find opened port by iptables

There seems to be some confusion about what an 'open port' is. This is partly due to the informal way that everyone speaks about open ports. With IP tables, you open a port for access (possibly with ...
Ljm Dullaart's user avatar
  • 5,063
4 votes
Accepted

Fresh Fedora 35 - what are these active internet connections doing?

The output is truncated, that was a connection to proxy14.fedoraproject.org, probably for an automated check for updates. ss -rt would show you the full host name.
Stephen Kitt's user avatar
4 votes
Accepted

Show non-truncated usernames of users connected to sshd server in terminal?

ss does not print the username of the user connected to sshd as netstat does netstat doesn't do that, either! It just prints the cmdline of that process. No guarantees that the user that's ...
Marcus Müller's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible