当前位置首页 > Linux知识

linux如何查看端口被谁占用

阅读次数:219 次  来源:admin  发布时间:

1、查看端口是否被占用

[guosong@alice48 main]$ netstat -nlp|grep 6184 
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:6184 0.0.0.0:* LISTEN 32429/python26
man netstat 
  --numeric , -n
       Show numerical addresses instead of trying to determine symbolic host, port or user names.
   -l, --listening
       Show only listening sockets.  (These are omitted by default.)

   -p, --program
       Show the PID and name of the program to which each socket belongs.

加了-p参数,可以看到PID

或者通过lsof查看对应的PID

[guosong@alice48 main]$ lsof -i tcp:6184
COMMAND    PID    USER   FD   TYPE     DEVICE SIZE NODE NAME
python26 32429 guosong   39u  IPv4 2261894200       TCP *:6184 (LISTEN)
       -i [i]   This option 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.
                [46][protocol][@hostname|hostaddr][:service|port]

                where:
                     46 specifies the IP version, IPv4 or IPv6
                          that applies to the following address.
                          ’6’ may be be specified only if the UNIX
                          dialect supports IPv6.  If neither ’4’ nor
                          ’6’ is specified, the following address
                          applies to all IP versions.
                     protocol is a protocol name - TCP or UDP.

2、查看命令路径

获取到PID后,通过ps查看进程命令

[guosong@alice48 main]$ ps aux |grep 32429
guosong   3737  0.0  0.0  61160   744 pts/31   S+   16:22   0:00 grep 32429
guosong  32429  0.6  0.1 234940 20860 pts/31   S    16:14   0:03 python26 api_main.py
[guosong@alice48 ~]$ readlink /proc/32429/exe 
/usr/bin/python26

通过readlink也只是知道这是个python26的脚本,至于后面api_main.py的绝对路径应该怎么找呢??

[guosong@alice48 32429]$ readlink /proc/32429/cwd
/usr/home/guosong/mysqlapi/main

http://www.blogjava.net/kxx129/archive/2013/05/13/399206.html

linux如何查看端口被谁占用

上一篇:Linux下Samba服务的安装与配置
下一篇:(转)Apache启动过程