Linux查看端口号命令
1.查看所有端口命令
// 1.使用netstat命令
netstat -tuln;
// 2.使用ss命令,常用命令
ss -tuln;
2.查看指定程序端口命令
// 2.ps命令,myapp代表你要查询的程序
ps aux | grep myapp;
3.查看指定端口命令
// 1.使用netstat命令查看端口号,netstat -tuln | grep <端口号>;,以3306为例
netstat -tuln | grep 3306;
// 2.使用ss命令查看端口号,ss -tuln | grep <端口号>;,以3306为例
ss -tuln | grep 3306;
// 3.使用lsof命令查看端口号,lsof -i :<端口号>;,以3306为例
lsof -i :3306;
// 4.使用fuser命令查看端口号,fuser <端口号>/tcp;,以3306为例
fuser 3306/tcp;
// 5.使用nmap命令查看端口号,nmap -p <端口号> localhost;,以3306为例
nmap -p 3306 localhost;
4.开放端口命令
// 5.使用firewall命令开放端口,firewall-cmd --add-port=<端口号>/<协议> --permanent;
//以3306为例
firewall-cmd --add-port=3306/tcp --permanent;
firewall-cmd --reload
5.关闭端口命令
firewall-cmd --remove-port=3306/tcp --permanent;
firewall-cmd --reload
6.终止端口命令(谨慎使用)
//1.通过pid杀死进程
lsof -i :3306;
kill <进程ID>
//2.使用 fuser 命令:
fuser -k 3306/tcp
//3.使用 killall 命令:
killall myapp