##a means all
n means not to query dns
t means tcp protocol
u means udp protocol
p means query occupied program
l means query is listening Program
#这个表示查找处于监听状态的,端口号为3306的进程
Copy after login
Copy after login
Linux method of checking port usage status and closing port
Premise: First of all, you must know that the port does not exist independently, it is attached to the process. When a process is opened, its corresponding port is opened; when the process is closed, the port is closed. If a process is opened again next time, the corresponding port will also be opened again. Don't purely understand it as closing a certain port, but you can disable a certain port.
1. You can use "netstat -anp" to check which ports are open.
(Note: Adding parameter '-n' will convert the application to port display, that is, an address in digital format, such as: nfs->2049, ftp->21, so it can be turned on Two terminals, one by one corresponding to the port number corresponding to the program)
2. Then you can use "lsof -i:$PORT" to view the program that uses the port ($PORT refers to the corresponding port Number). Or you can also check the file /etc/services to find out the service corresponding to the port.
(Note: Some ports cannot be found through netstat. A more reliable method is "sudo nmap -sT -O localhost")
3. To close a certain port port, you can:
1) Disable the port through the iptables tool, such as:
iptables -A INPUT -p tcp --dport $PORT -j DROP
iptables -A OUTPUT -p tcp --dport $PORT -j DROP
Copy after login
Copy after login
2) Or close the corresponding application , the port will be closed naturally, such as:
"kill -9 PID" (PID: process number)
For example: through "netstat -anp | grep ssh"
Display: tcp 0 127.0.0.1:2121 0.0.0.0:* LISTEN 7546/ssh
then: "kill -9 7546"