You are on page 1of 2

Get a list of Open Ports in Linux about:reader?url=http://superuser.com/questions...

superuser.com

Get a list of Open Ports in Linux


The following command will work on any Unix which outputs in the
same format as Ubuntu / Debian - where the local address is in the
column 4 and the output includes a 2 line header at the top. If either
of those numbers is different, tweak the awk command below.

If you want IPv4 only:

netstat -lnt | awk 'NR>2{print $4}' | grep -E


'0.0.0.0:' | sed 's/.*://' | sort -n | uniq

If you want IPv6 only:

netstat -lnt | awk 'NR>2{print $4}' | grep -E


':::' | sed 's/.*://' | sort -n | uniq

If you want both together:

netstat -lnt | awk 'NR>2{print $4}' | grep -E


'(0.0.0.0:|:::)' | sed 's/.*://' | sort -n | uniq

The command outputs a list of port numbers that are listening on all

1 of 2 08/19/2016 05:18 PM
Get a list of Open Ports in Linux about:reader?url=http://superuser.com/questions...

interfaces. If you want to list all ports that are listening on localhost
interface, then use something like this:

netstat -lnt | awk 'NR>2{print $4}' | grep -E


'(127.0.0.1:|::1:)' | sed 's/.*://' | sort -n |
uniq

2 of 2 08/19/2016 05:18 PM

You might also like