您的位置:首页 > 运维架构 > Linux

linux下查看端口

2016-03-22 11:21 671 查看
1.netstat -anpl

[php] view
plain copy

root@coder-671T-M:~# netstat -anpl | grep 80  

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1380/apache2      

tcp        0      0 127.0.0.1:8005          0.0.0.0:*               LISTEN      1490/java         

tcp        0      0 192.168.2.153:53487     91.189.90.217:80        ESTABLISHED 3346/http         

tcp        0      0 192.168.2.153:50971     218.249.165.46:80       TIME_WAIT   -                 

tcp        0      0 192.168.2.153:40482     91.189.88.33:80         TIME_WAIT   -                 

tcp        0      0 192.168.2.153:48410     91.189.92.179:80        TIME_WAIT   -                 

tcp        0      0 192.168.2.153:37050     123.129.214.98:80       ESTABLISHED 3350/http         

tcp        0      0 192.168.2.153:40484     91.189.88.33:80         ESTABLISHED 3347/http         

tcp        1      0 192.168.2.153:40477     91.189.88.33:80         CLOSE_WAIT  3348/http         

tcp        0    190 192.168.2.153:36346     91.189.92.167:80        LAST_ACK    -                 

tcp        0      1 192.168.2.153:57367     91.189.92.166:80        SYN_SENT    3349/http         

unix  3      [ ]         流        已连接     15380    1138/X              @/tmp/.X11-unix/X0  

unix  3      [ ]         流        已连接     11180    1933/dbus-daemon    @/tmp/dbus-UXsB7wqFp6  

unix  3      [ ]         流        已连接     10807    1872/gnome-session  @/tmp/.ICE-unix/1872  

unix  3      [ ]         流        已连接     10804    1933/dbus-daemon    @/tmp/dbus-UXsB7wqFp6  

unix  3      [ ]         流        已连接     10802    1933/dbus-daemon    @/tmp/dbus-UXsB7wqFp6  

unix  3      [ ]         流        已连接     10801    1933/dbus-daemon    @/tmp/dbus-UXsB7wqFp6  

unix  3      [ ]         流        已连接     10800    1138/X              @/tmp/.X11-unix/X0  

unix  3      [ ]         流        已连接     10180    1925/dbus-daemon    @/tmp/dbus-QCJgSbaeRf  

unix  3      [ ]         流        已连接     10480    1925/dbus-daemon      

unix  2      [ ]         流        已连接     9794     1802/colord           

unix  3      [ ]         流        已连接     9793     1802/colord           

unix  3      [ ]         流        已连接     9792     1802/colord           

unix  3      [ ]         流        已连接     9195     1802/colord           

unix  3      [ ]         流        已连接     7080     864/dbus-daemon       

2.lsof -i:80

[plain] view
plain copy

root@coder-671T-M:~# lsof -i:80  

COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME  

apache2 1380     root    3u  IPv4   8025      0t0  TCP *:www (LISTEN)  

apache2 1417 www-data    3u  IPv4   8025      0t0  TCP *:www (LISTEN)  

apache2 1418 www-data    3u  IPv4   8025      0t0  TCP *:www (LISTEN)  

apache2 1419 www-data    3u  IPv4   8025      0t0  TCP *:www (LISTEN)  

apache2 1420 www-data    3u  IPv4   8025      0t0  TCP *:www (LISTEN)  

apache2 1421 www-data    3u  IPv4   8025      0t0  TCP *:www (LISTEN)  

chrome  2474     root   60u  IPv4  34989      0t0  TCP coder-671T-M.local:38499->117.79.157.242:www (ESTABLISHED)  

chrome  2474     root   64u  IPv4  34990      0t0  TCP coder-671T-M.local:38500->117.79.157.242:www (ESTABLISHED)  

apache2 3301 www-data    3u  IPv4   8025      0t0  TCP *:www (LISTEN)  

http    3346     root    3u  IPv4  34869      0t0  TCP coder-671T-M.local:53487->germanium.canonical.com:www (CLOSE_WAIT)  

http    3347     root    3u  IPv4  34899      0t0  TCP coder-671T-M.local:40484->scandium.canonical.com:www (CLOSE_WAIT)  

http    3348     root    3u  IPv4  34865      0t0  TCP coder-671T-M.local:40477->scandium.canonical.com:www (CLOSE_WAIT)  

http    3349     root    3u  IPv4  34154      0t0  TCP coder-671T-M.local:36354->bignay.canonical.com:www (ESTABLISHED)  

http    3350     root    3u  IPv4  34871      0t0  TCP coder-671T-M.local:37050->123.129.214.98:www (ESTABLISHED)  

root@coder-671T-M:~#   

netstat的help信息

[plain] view
plain copy

root@coder-671T-M:~# netstat --help  

usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}  

       netstat [-vWnNcaeol] [<Socket> ...]  

       netstat { [-vWeenNac] -i | [-cWnNe] -M | -s }  

  

        -r, --route              显示路由表  

        -i, --interfaces         display interface table  

        -g, --groups             display multicast group memberships  

        -s, --statistics         display networking statistics (like SNMP)  

        -M, --masquerade         display masqueraded connections  

  

        -v, --verbose            显示详细信息  

        -W, --wide               don't truncate IP addresses  

        -n, --numeric            不解析名称  

        --numeric-hosts          不解析主机名  

        --numeric-ports          忽略端口名称  

        --numeric-users          忽略用户名  

        -N, --symbolic           resolve hardware names  

        -e, --extend             显示更多信息  

        -p, --programs           display PID/Program name for sockets  

        -c, --continuous         continuous listing  

  

        -l, --listening          display listening server sockets  

        -a, --all, --listening   display all sockets (default: connected)  

        -o, --timers             display timers  

        -F, --fib                display Forwarding Information Base (default)  

        -C, --cache              display routing cache instead of FIB  

  

  <Socket>={-t|--tcp} {-u|--udp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom  

  <AF>=Use '-6|-4' or '-A <af>' or '--<af>';默认: inet  

  列出所有支持的协议:  

    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)   

    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)   

    x25 (CCITT X.25)   

lsof的help信息

[php] view
plain copy

root@coder-671T-M:~# lsof --help  

lsof: illegal option character: -  

lsof: illegal option character: e  

lsof: no process ID specified  

lsof 4.81  

 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/  

 latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ  

 latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man  

 usage: [-?abhlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]]  

 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]  

[+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]  

Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.  

  -?|-h list help          -a AND selections (OR)     -b avoid kernel blocks  

  -c c  cmd c ^c /c/[bix]  +c w  COMMAND width (9)       

  +d s  dir s files        -d s  select by FD set     +D D  dir D tree *SLOW?*  

                           -i select IPv[46] files    -l list UID numbers  

  -n no host names         -N select NFS files        -o list file offset  

  -O avoid overhead *RISK  -P no port names           -R list paRent PID  

  -s list file size        -t terse listing           -T disable TCP/TPI info  

  -U select Unix socket    -v list version info       -V verbose search  

  +|-w  Warnings (+)       -X skip TCP&UDP* files     -- end option scan  

  +f|-f  +filesystem or -file names     +|-f[gG] flaGs   

  -F [f] select fields; -F? for help    

  +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)  

                                        +m [m] use|create mount supplement  

  +|-M   portMap registration (-)       -o o   o 0t offset digits (8)  

  -p s   exclude(^)|select PIDs         -S [t] t second stat timeout (15)  

  -T qs TCP/TPI Q,St (s) info  

  -g [s] exclude(^)|select and print process group IDs  

  -i i   select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]  

  +|-r [t[m<fmt>]] repeat every t seconds (15);  + until no files, - forever.  

       An optional suffix to t is m<fmt>; m must separate t from <fmt> and  

      <fmt> is an strftime(3) format for the marker line.  

  -s p:s  exclude(^)|select protocol (p = TCP|UDP) states by name(s).  

  -u s   exclude(^)|select login|UID set s  

  -x [fl] cross over +d|+D File systems or symbolic Links  

  names  select named files or files on named file systems  

Anyone can list all files; /dev warnings disabled; kernel ID check disabled.  

root@coder-671T-M:~#   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: