zoukankan      html  css  js  c++  java
  • CentOS查看端口是否被占用

    CentOS查看端口是否被占用
    本文介绍了linux中查看某一端口是否被占用的方法,有关netstat命令的使用技巧,感兴趣的朋友可以参考下。

    使用命令:
    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
    查看某一端口的占用情况: lsof -i:端口号

    复制代码 代码示例:1 [root@www ~]# lsof -i:21
    3 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
    4 pure-ftpd 2651 root 4u IPv4 7047 TCP *:ftp (LISTEN)
    5 pure-ftpd 2651 root 5u IPv6 7048 TCP *:ftp (LISTEN)
    这里显示出21号端口正在被pure-ftpd使用,状态是listen。

  • 相关阅读:
    poj 1789 Truck History(最小生成树)
    POJ 3096 Surprising Strings(STL map string set vector)
    hdu 1412 (STL list)
    POJ 1552 Doubles (C++ STL set使用)
    poj 水题系列
    洛谷P4859 已经没有什么好害怕的了
    CF1228E Another Filling the Grid
    二项式反演
    AT [ABC177F] I hate Shortest Path Problem
    [NOI2020]制作菜品
  • 原文地址:https://www.cnblogs.com/duyinqiang/p/5696585.html
Copyright © 2011-2022 走看看