내 인터페이스에서 몇 개의 서비스가 수신되고 있는지 확인해야 합니다(ipv4만 해당, localhost는 아님).
$ ifconfig
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.129.56.137 netmask 255.255.0.0 broadcast 10.129.255.255
inet6 dead:beef::250:56ff:feb9:8c07 prefixlen 64 scopeid 0x0<global>
inet6 fe80::250:56ff:feb9:8c07 prefixlen 64 scopeid 0x20<link>
ether 00:50:56:b9:8c:07 txqueuelen 1000 (Ethernet)
RX packets 3644 bytes 330312 (330.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3198 bytes 679711 (679.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 15304 bytes 895847 (895.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 15304 bytes 895847 (895.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
$ nmap 10.129.56.137
Starting Nmap 7.60 ( https://nmap.org ) at 2020-12-05 05:23 UTC
Nmap scan report for 10.129.56.137
Host is up (0.000086s latency).
Not shown: 991 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
80/tcp open http
110/tcp open pop3
139/tcp open netbios-ssn
143/tcp open imap
445/tcp open microsoft-ds
993/tcp open imaps
995/tcp open pop3s
Nmap done: 1 IP address (1 host up) scanned in 10.57 seconds
답은 9인 줄 알았는데, 정답을 찾는 방법이 분명 있을 거에요. 미리 건배하세요!
답변1
man netstat에서:
이 프로그램은 대부분 구식입니다. netstat의 대체는 ss입니다.
현 시점에서는 이것이 최선의 선택이라고 생각합니다.
ss -l -4 | grep -v "127\.0\.0" | grep "LISTEN" | wc -l
어디:
- -엘: 청취 서비스만 표시
- -4: IPv4만 표시
- -grep -v "127.0.0": 모든 localhost 결과 제외
- -grep "듣기": 청취 서비스에 대해서만 필터링 개선
- 화장실-l: 통계 결과
답변2
netstat -tunleep4 | grep -v "127\.0\.0"
답변3
netstat -ln4 | grep LISTEN | grep -v 127 | wc -l
설명하다:
netstat
-l, --listening display listening server sockets
-n, --numeric don't resolve names
-4
--protocol=family, -A
Specifies the address families (perhaps better described as low level protocols) for which connections are to be
shown. family is a comma (',') separated list of address family keywords like inet, inet6, unix, ipx, ax25, netrom,
econet, ddp, and bluetooth. This has the same effect as using the --inet|-4, --inet6|-6, --unix|-x, --ipx, --ax25,
--netrom, --ddp, and --bluetooth options.
The address family inet (Iv4) includes raw, udp, udplite and tcp protocol sockets.
The address family bluetooth (Iv4) includes l2cap and rfcomm protocol sockets.
grep LISTEN - LISTEN
단어만 포함하는 줄
grep -v 127 - 줄이 없습니다.127
wc -l - 결과의 행 수를 계산합니다.
여기에 시각적 설명 -https://explainshell.com/explain?cmd=netstat+-ln4+%7C+grep+LISTEN+%7C+grep+-v+127+%7C+wc+-l
답변4
netstat -tnl | grep ":.*[1-9]" | grep -v "127.0.0.1" | wc -l