/
netstat 로 사용중인 포트 확인
netstat 로 사용중인 포트 확인
최신 리눅스 배포판은 netstat 대신 ss 명령어 사용을 권장하고 있습니다.
netstat 는 네트워크 관련한 정보를 보는 유틸리티로 오래전부터 Unix 계열의 운영체제에서 사용되어 왔으며 현재 리슨중인 포트, 모든 내외부/연결 정보등을 확인할 수 있습니다.
사용법
사용중인 모든 소켓 보기
-a, --all 옵션을 사용하면 사용중인 모든 포트를 나열합니다.
$ sudo netstat -a Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:hostmon 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN tcp6 0 0 [::]:hostmon [::]:* LISTEN tcp6 0 0 [::]:ssh [::]:* LISTEN udp 0 0 0.0.0.0:hostmon 0.0.0.0:* udp 0 0 localhost:323 0.0.0.0:* udp 0 0 ip-127-0-0-53.ap:domain 0.0.0.0:* udp 0 0 ip-172-31-23-247:bootpc 0.0.0.0:* udp6 0 0 [::]:hostmon [::]:* udp6 0 0 localhost:323 [::]:* Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 19709 /run/dbus/system_bus_socket unix 2 [ ACC ] STREAM LISTENING 21522 /var/lib/sss/pipes/nss
listening 소켓
-l, --listening 옵션을 사용하면 listening 중인 모든 TCP/UDP/Unix Domain socket을 표시합니다.
$ sudo netstat -l Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:hostmon 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN tcp6 0 0 [::]:hostmon [::]:* LISTEN tcp6 0 0 [::]:ssh [::]:* LISTEN udp 0 0 0.0.0.0:hostmon 0.0.0.0:* udp 0 0 localhost:323 0.0.0.0:* udp 0 0 ip-127-0-0-53.ap:domain 0.0.0.0:* udp 0 0 ip-172-31-23-247:bootpc 0.0.0.0:* udp6 0 0 [::]:hostmon [::]:* udp6 0 0 localhost:323 [::]:* Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 19709 /run/dbus/system_bus_socket unix 2 [ ACC ] STREAM LISTENING 21522 /var/lib/sss/pipes/nss unix 2 [ ACC ] SEQPACKET LISTENING 18498 /run/systemd/coredump
listening TCP 소켓
-t, –tcp 옵션은 listening 중인 TCP 소켓만 표시합니다.
$ sudo netstat -t Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 96 ip-172-31-23-247.ap:ssh 1.2.3.4:50186 ESTABLISHED
listening 소켓 정보 상세 보기
여러 옵션을 조합해서 listening 중인 모든 소켓에 대한 상세 정보를 볼수 있으며 옵션에 대한 설명은 하단을 참고하세요.
$ sudo netstat -antup 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:5355 0.0.0.0:* LISTEN 848/systemd-resolve tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 980/sshd tcp 0 96 172.31.23.247:22 1.1.1.1:50186 ESTABLISHED 30037/sshd: ec2-use tcp6 0 0 :::5355 :::* LISTEN 848/systemd-resolve tcp6 0 0 :::22 :::* LISTEN 980/sshd udp 0 0 0.0.0.0:5355 0.0.0.0:* 848/systemd-resolve udp 0 0 127.0.0.1:323 0.0.0.0:* 677/chronyd udp 0 0 127.0.0.53:53 0.0.0.0:* 848/systemd-resolve udp 0 0 172.31.23.247:68 0.0.0.0:* 774/NetworkManager udp6 0 0 :::5355 :::* 848/systemd-resolve udp6 0 0 ::1:323 :::* 677/chronyd
정보 갱신해서 보기
-c, --continuous 옵션을 사용하면 종료되지 않고 계속 정보를 갱신하면서 표시합니다.
$ netstat -c
routing 정보 보기
-r, --route 옵션으로 현재 시스템의 커널 라우팅 정보를 볼 수 있습니다.
$ sudo netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 172.31.16.1 0.0.0.0 UG 0 0 0 eth0 172.31.16.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
주요 옵션
옵션 | 의미 | |
---|---|---|
-a | 모든 소켓 표시 | |
-t | TCP socket 만 표시 | |
-u | UDP socket 만 표시 | |
-n | 호스트, 포트 번호 등의 이름 확인을 하지 않고 숫자로 표시 | |
-p | 소켓을 사용하고 있는 프로세스의 ID 표시 | |
-r | 라우팅 테이블 표시 | |
-l | 연결 대기 상태인 소켓만 표시 |
같이 보기
Ref
, multiple selections available,
Related content
보안 프로세스와 문화
보안 프로세스와 문화
Read with this
linux netstat 명령어 사용법
linux netstat 명령어 사용법
More like this
logwatch
logwatch
Read with this
linux socket 상태를 조회하는 ss(socket statistics) 명령어 사용법
linux socket 상태를 조회하는 ss(socket statistics) 명령어 사용법
More like this
ubuntu netplan 으로 고정 ip 설정하기(static ip config)
ubuntu netplan 으로 고정 ip 설정하기(static ip config)
More like this
nslookup 명령어 사용법 및 예제 정리
nslookup 명령어 사용법 및 예제 정리
More like this