CentOS下netstat查看正在监听的端口
[root@pa137 ~]# netstat --help usage: netstat [-veenNcCF] [<Af>] -r netstat {-V|--version|-h|--help} netstat [-vnNcaeol] [<Socket> ...] netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [delay] -r, --route display routing table -I, --interfaces=[<Iface>] display interface table for <Iface> -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 be verbose -n, --numeric don't resolve names --numeric-hosts don't resolve host names --numeric-ports don't resolve port names --numeric-users don't resolve user names -N, --symbolic resolve hardware names -e, --extend display other/more information -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 -T, --notrim stop trimming long addresses -Z, --context display SELinux security context for sockets <Iface>: Name of interface to monitor/list. <Socket>={-t|--tcp} {-u|--udp} {-S|--sctp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom <AF>=Use '-A <af>' or '--<af>'; default: inet List of possible address families (which support routing): inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25) netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP) x25 (CCITT X.25) 显示正在监听的tcp端口: -l表示监听 -t表示tcp -p表示显示程序名 -n表示部将ip和端口转换成域名和服务名 -u表示udp [root@pa137 ~]# netstat -tlnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2493/portmap tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2776/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2808/sendmail: acce tcp 0 0 0.0.0.0:1020 0.0.0.0:* LISTEN 2534/rpc.statd tcp 0 0 :::3306 :::* LISTEN 15681/mysqld tcp 0 0 :::22 :::* LISTEN 2767/sshd [root@pa137 ~]# [root@pa137 ~]# netstat -atnp Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2493/portmap tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2776/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2808/sendmail: acce tcp 0 0 0.0.0.0:1020 0.0.0.0:* LISTEN 2534/rpc.statd tcp 0 0 :::3306 :::* LISTEN 15681/mysqld tcp 0 0 :::22 :::* LISTEN 2767/sshd tcp 0 0 ::ffff:192.168.1.137:22 ::ffff:192.168.31.101:49223 ESTABLISHED 3110/2 tcp 0 260 ::ffff:192.168.1.137:22 ::ffff:192.168.31.101:49712 ESTABLISHED 3438/4 tcp 0 0 ::ffff:192.168.1.137:22 ::ffff:192.168.31.102:1039 ESTABLISHED 3151/3 [root@pa137 ~]# netstat -aunp Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 0 0 0.0.0.0:33716 0.0.0.0:* 2915/avahi-daemon: udp 0 0 0.0.0.0:5353 0.0.0.0:* 2915/avahi-daemon: udp 0 0 0.0.0.0:111 0.0.0.0:* 2493/portmap udp 0 0 0.0.0.0:1014 0.0.0.0:* 2534/rpc.statd udp 0 0 0.0.0.0:631 0.0.0.0:* 2776/cupsd udp 0 0 0.0.0.0:1017 0.0.0.0:* 2534/rpc.statd udp 0 0 :::5353 :::* 2915/avahi-daemon: udp 0 0 :::54269 :::* 2915/avahi-daemon: [root@pa137 ~]# 功能说明:Netstat用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。 语 法:netstat[-acCeFghilMnNoprstuvVwx][-A<网络类型>][--ip] 补充说明:利用netstat指令可让你得知整个Linux系统的网络情况。 参 数: -a或–all 显示所有连线中的Socket。 -A<网络类型>或–<网络类型> 列出该网络类型连线中的相关地址。 -c或–continuous 持续列出网络状态。 -C或–cache 显示路由器配置的快取信息。 -e或–extend 显示网络其他相关信息。 -F或–fib 显示FIB。 -g或–groups 显示多重广播功能群组组员名单。 -h或–help 在线帮助。 -i或–interfaces 显示网络界面信息表单。 -l或–listening 显示监控中的服务器的Socket。 -M或–masquerade 显示伪装的网络连线。 -n或–numeric 直接使用IP地址,而不通过域名服务器。 -N或–netlink或–symbolic 显示网络硬件外围设备的符号连接名称。 -o或–timers 显示计时器。 -p或–programs 显示正在使用Socket的程序识别码和程序名称。 -r或–route 显示Routing Table。 -s或–statistice 显示网络工作信息统计表。 -t或–tcp 显示TCP传输协议的连线状况。 -u或–udp 显示UDP传输协议的连线状况。 -v或–verbose 显示指令执行过程。 -V或–version 显示版本信息。 -w或–raw 显示RAW传输协议的连线状况。 -x或–unix 此参数的效果和指定”-A unix”参数相同。 –ip或–inet 此参数的效果和指定”-A inet”参数相同 netstat的一些常用选项 ·netstat–s 本选项能够按照各个协议分别显示其统计数据。如果我们的应用程序(如Web浏览器)运行速度比较慢,或者不能显示Web页之类的数据,那么我们就可以用本选项来查看一下所显示的信息。我们需要仔细查看统计数据的各行,找到出错的关键字,进而确定问题所在。 ·netstat–e 本选项用于显示关于以太网的统计数据。它列出的项目包括传送的数据报的总字节数、错误数、删除数、数据报的数量和广播的数量。这些统计数据既有发送的数据报数量,也有接收的数据报数量。这个选项可以用来统计一些基本的网络流量)。 ·netstat–r 本选项可以显示关于路由表的信息,类似于后面所讲使用route print命令时看到的 信息。除了显示有效路由外,还显示当前有效的连接。 ·netstat–a 本选项显示一个所有的有效连接信息列表,包括已建立的连接(ESTABLISHED),也包括监听连接请(LISTENING)的那些连接。 ·netstat–n 显示所有已建立的有效连接。