netstat和ss命令查看系统端口信息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了netstat和ss命令查看系统端口信息相关的知识,希望对你有一定的参考价值。
netstat 和ss都命令可以查询系统启动的端口信息(端口启动就有,没启动就为空)
-n以数字格式显示端口号
-t显示TCP连接的端口
-u显示UDP连接的端口
-l显示服务正在监听的端口信息,如httpd启动后,会一直监听80端口
-p显示监听端口的服务名称是什么(也就是程序名称)
1.netstat 查看
[root@web1 test]# netstat -ntulp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3722/nginx: master
2.ss 查看
[root@web1 test]# ss -ntulp |grep 80
tcp LISTEN 0 128 *:80 *:* users:(("nginx",pid=3992,fd=6),("nginx",pid=3722,fd=6))
3、也可以用长选项--help查看更多的选项
[root@web1 test]# netstat --help
usage: netstat [-vWeenNcCF] [<Af>] -r netstat -V|--version|-h|--help
netstat [-vWnNcaeol] [<Socket> ...]
netstat [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] [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
-W, --wide dont truncate IP addresses
-n, --numeric dont resolve names
--numeric-hosts dont resolve host names
--numeric-ports dont resolve port names
--numeric-users dont resolve user names
-N, --symbolic resolve hardware names
-e, --extend display other/more information
-p, --programs display PID/Program name for sockets
-o, --timers display timers
-c, --continuous continuous listing
-l, --listening display listening server sockets
-a, --all display all sockets (default: connected)
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
-Z, --context display SELinux security context for sockets
<Socket>=-t|--tcp -u|--udp -U|--udplite -S|--sctp -w|--raw
-x|--unix --ax25 --ipx --netrom
<AF>=Use -6|-4 or -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)
4、ss也一样可以用长选项--help来查看更多选项
[root@web1 test]# ss --help
Usage: ss [ OPTIONS ]
ss [ OPTIONS ] [ FILTER ]
-h, --help this message
-V, --version output version information
-n, --numeric dont resolve service names
-r, --resolve resolve host names
-a, --all display all sockets
-l, --listening display listening sockets
-o, --options show timer information
-e, --extended show detailed socket information
-m, --memory show socket memory usage
-p, --processes show process using socket
-i, --info show internal TCP information
-s, --summary show socket usage summary
-b, --bpf show bpf filter socket information
-E, --events continually display sockets as they are destroyed
-Z, --context display process SELinux security contexts
-z, --contexts display process and socket SELinux security contexts
-N, --net switch to the specified network namespace name
-4, --ipv4 display only IP version 4 sockets
-6, --ipv6 display only IP version 6 sockets
-0, --packet display PACKET sockets
-t, --tcp display only TCP sockets
-S, --sctp display only SCTP sockets
-u, --udp display only UDP sockets
-d, --dccp display only DCCP sockets
-w, --raw display only RAW sockets
-x, --unix display only Unix domain sockets
--vsock display only vsock sockets
-f, --family=FAMILY display sockets of type FAMILY
FAMILY := inet|inet6|link|unix|netlink|vsock|help
-K, --kill forcibly close sockets, display what was closed
-H, --no-header Suppress header line
-A, --query=QUERY, --socket=QUERY
QUERY := all|inet|tcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink|vsock_stream|vsock_dgram[,QUERY]
-D, --diag=FILE Dump raw information about TCP sockets to FILE
-F, --filter=FILE read filter information from FILE
FILTER := [ state STATE-FILTER ] [ EXPRESSION ]
STATE-FILTER := all|connected|synchronized|bucket|big|TCP-STATES
TCP-STATES := established|syn-sent|syn-recv|fin-wait-1,2|time-wait|closed|close-wait|last-ack|listen|closing
connected := established|syn-sent|syn-recv|fin-wait-1,2|time-wait|close-wait|last-ack|closing
synchronized := established|syn-recv|fin-wait-1,2|time-wait|close-wait|last-ack|closing
bucket := syn-recv|time-wait
big := established|syn-sent|fin-wait-1,2|closed|close-wait|last-ack|listen|closing
[root@web1 test]#
以上是关于netstat和ss命令查看系统端口信息的主要内容,如果未能解决你的问题,请参考以下文章