I want to install webserver-apache on a Linux platform which uses port no.80 but I am not sure whether is port is open or not, and is being used by some other application or not.
grep 80 /etc/services
is:http 80/tcp www www-http #World Wide web Http
http 80/udp www www-http #Hypertext transfer protocol
netstat -an | grep 80 | more
:It gives some IP's one of which is
IP:80 TIME_WAIT
Could you please help and tell how can i find out if port 80 is open and unused so that I can start installation.
You can use "netstat" to check whether a port is available or not. Use the netstat -anp | find "port number" command to find whether a port is occupied by an another process or not. If it is occupied by an another process, it will show the process id of that process.
Port 1024 through 49151 are not restricted, although apps that use them may have "reserved" the port via IANA registration. Port 0 is a pseudo port where an app can bind to it and the OS will search and define one within the acceptable dynamic range (49152 through 65535).
sudo netstat -anp | grep ':80 '
That should give you pid & name of the process that holds port 80
This can be achieved using the nc
command as follows:
# nc -z IP PORT
It will return TRUE if the port is already in use, or FALSE is it (i.e, available not listening currently).
I don't recommend lsof
or netstat
method as it first try to scan all running PIDs to get all bounded ports:
# time lsof -i:8888
real 0m1.194s
user 0m0.137s
sys 0m1.056s```
# time nc -z 127.0.0.1 8888
real 0m0.014s
user 0m0.011s
sys 0m0.004s
Here 8888 is an unused port. The nc
command is ~85 times faster in the above example.
$ nc -z 127.0.0.1 80 && echo "IN USE" || echo "FREE"
IN USE
$ nc -z 127.0.0.1 81 && echo "IN USE" || echo "FREE"
FREE
If you are trying with a remote IP, it is better to add a timeout to auto-exit if it is not accepting connection for the specified time.
$ nc -w 2 -z 216.58.196.174 81
Its Google's IP which is not used, so it will timeout after trying for 2 seconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With