linux检查某个端口是否被使用的命令是

如题所述

netstat -tunlp 会显示所有端口和所有对应的程序,用grep管道可以过滤出想要的关键字段.
列一下22端口占用的程序

[root@leiwan tmp]# netstat -tunlp |grep 22
tcp 0 0 0.0.0.0:42957 0.0.0.0:* LISTEN 2230/rpc.statd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2443/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2292/cupsd
tcp 0 0 :::22 :::* LISTEN 2443/sshd
tcp 0 0 ::1:631 :::* LISTEN 2292/cupsd
tcp 0 0 :::57609 :::* LISTEN 2230/rpc.statd
udp 0 0 0.0.0.0:5353 0.0.0.0:* 2211/avahi-daemon
udp 0 0 0.0.0.0:631 0.0.0.0:* 2292/cupsd
udp 0 0 0.0.0.0:37167 0.0.0.0:* 2230/rpc.statd
udp 0 0 0.0.0.0:52291 0.0.0.0:* 2211/avahi-daemon
udp 0 0 0.0.0.0:68 0.0.0.0:* 2207/dhclient
udp 0 0 0.0.0.0:710 0.0.0.0:* 2230/rpc.statd
udp 0 0 :::39834 :::* 2230/rpc.statd
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-26
骨灵鲸怪写的可以,我再根据他的基础上再做一个细化
[root@benet ~]# netstat -nlptu |awk '{print $4,$7}' | grep 80
:::80 2508/httpd
这样更直观的显示出要查询的端口以及使用这个端口的程序。
第2个回答  2012-04-24
lsof -i:xx 也可以
相似回答