In some projects, there are requirements for network layer security, and only necessary network ports are allowed to be opened, so R&D is required to know the specific role of each open port.
The following content is reproduced from other articles and is only a summary:
Everyone knows that the port does not exist independently, it is dependent on the process. When a process is opened, then its corresponding port is opened, and when the process is closed, the port is also closed. If a certain process is opened again next time, the corresponding port will be opened again. Don't just understand it as shutting down a port, but you can disable a port.
View port:
netstat -antp
busybox netstat -antp
注:加t参数,可以使之打印端口对应的进程
Another way to view the port corresponding process:
lsof -i:xxx
注:lsof是一个单独命令
下载源码:https://download.csdn.net/download/oneonone/3738045
相关文档:https://blog.csdn.net/weixin_33857230/article/details/92130771
Close port
There are two ways to close the port: disable the port/kill the corresponding process
【iptable】
sudo iptables -A INPUT -p tcp --dport $PORT -j DROP"
sudo iptables -A OUTPUT -p tcp --dport $PORT -j DROP"
【kill】
kill -9 PID" (PID:进程号)