I would like to see what ports are open on my machine, e.g. what ports my machine is listening on. E.g. port 80 if I have installed a web server, and so on.
Is there any command for this?
I would like to see what ports are open on my machine, e.g. what ports my machine is listening on. E.g. port 80 if I have installed a web server, and so on.
Is there any command for this?
I've always used this:
If the
netstat
command is not available, install it with:nmap (install)
Nmap ("Network Mapper") is a free and open source utility for network exploration or security auditing.
Use
nmap 192.168.1.33
for internal PC ornmap external IP address
.More information
man nmap
.Zenmap is the official GUI frontend.
Other good ways to find out what ports are listenting and what your firewall rules are:
sudo netstat -tulpn
sudo ufw status
To list open ports use the
netstat
command.For example:
In the above example three services are bound to the loopback address.
IPv4 services bound to the loopback address "127.0.0.1" are only available on the local machine. The equivalent loopback address for IPv6 is "::1". The IPv4 address "0.0.0.0" means "any IP address", which would mean that other machines could potentially connect to any of the locally configured network interfaces on the specific port.
Another method is to use the
lsof
command:For more details see
man netstat
orman lsof
.This is enough to show that there is a process listening on IP address
0.0.0.0
(needed so it will reply to any request) on port 80 (standard web server port number). In my case this shows it is the web serverlighttpd
If you later want to make sure that the only thing you allow through your firewall is port 80 I often use ShieldsUp from www.grc.com to perform a firewall test.
sudo iptables -L
will list the port rules for your pc. Note that if you are using ufw or shorewall firewalls the output maybe be hard to read. In that case rather usesudo ufw status
for example.This is not very useful on its own as even if a port is open access will still be denied if there is no process listening on that port.
If you are looking for continuous monitoring of ports for server machines or local I think you can also use graphical version of nmap i.e Zenmap for more detailed version
Zenmap is the official graphical user interface (GUI) for the Nmap Security Scanner.
Supports available (Linux, Windows, Mac OS X, BSD, etc.)
Have a look to this tool view:
In latest Linux distro, most probably you won't find
netstat
command anymore.However, if you want to use it, go ahead and install it with
sudo apt install net-tools
command.Fyi, netstat is obsolete (refer to the man page), so you should use
ss
intead ofnetstat
.E.g.
Description
ss: Print: network connections routing tables interface statistics masquerade connections multicast memberships
assuming u wanna check port 3000:
netstat -na | grep 3000