How to close an open port in Ubuntu?
netstat
can be used to see the ports stat.
sudo netstat -lnp
To list all Listening ports Numbers with the Process responsible on each one. Terminate or kill the process to close port. (kill
, pkill
...)
Without process termination, It is not possible! . See Manually closing a port from command line. Other way you may look for a firewall solution (as isolating that port from network)
for closing open port in ubuntu you can use below command
sudo kill $(sudo lsof -t -i:3000)
in place of 3000
you can specify your port number
lsof
command will give information about file opened by process
-t : This flag specifies that lsof should produce terse output with process identifiers only and no header - e.g., so that the output may be piped to kill(1). This option selects the -w option.
-i : This flag selects the listing of files any of whose Internet address matches the address specified in i. If no address is specified, this option selects the listing of all Internet and x.25 (HP-UX) network files.
sudo ufw allow 22
sudo ufw deny 22