리눅스 운영체제에서 간혹 포트 감시를 해야 하는 경우가 있습니다.
특히 나 TCP나 UDP 포트에 대해 감시를 해야 하는 경우가 있다.
이럴 경우 netstat 혹은 ss 명령어를 사용하게 됩니다.
 TCP, UDP 포트를 리스닝 하는 프로그램이나 프로세스에 대해서 확인하는 방법 입니다.
ss 명령어를 사용하는 경우
[root@testora ~]# ss -tulpn
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 127.0.0.1:916 *:* users:((“rpc.statd”,1588,5))
udp UNCONN 0 0 *:802 *:* users:((“rpcbind”,1475,7))
udp UNCONN 0 0 *:111 *:* users:((“rpcbind”,1475,6))
udp UNCONN 0 0 *:13303 *:* users:((“rpc.statd”,1588,8))
udp UNCONN 0 0 52.33.171.180:123 *:* users:((“ntpd”,1959,19))
tcp LISTEN 0 128 :::111 :::* users:((“rpcbind”,1475,11))
tcp LISTEN 0 128 *:111 *:* users:((“rpcbind”,1475,8))
tcp LISTEN 0 128 :::1521 :::* users:((“tnslsnr”,2827,12))
tcp LISTEN 0 32 *:21 *:* users:((“vsftpd”,1974,3))
tcp LISTEN 0 128 :::22 :::* users:((“sshd”,29428,4))
tcp LISTEN 0 128 *:22 *:* users:((“sshd”,29428,3))
tcp LISTEN 0 100 127.0.0.1:25 *:* users:((“master”,2420,12))
tcp LISTEN 0 128 :::5500 :::* users:((“tnslsnr”,2827,19))
tcp LISTEN 0 128 *:63132 *:* users:((“rpc.statd”,1588
netstat 명령어를 사용하는 경우
[root@testora ~]# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2016 0.0.0.0:* LISTEN 19084/oraagent.bin
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1475/rpcbind
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 1974/vsftpd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 29428/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2420/master
udp 0 0 ::1:59862 :::* 3035/ora_d000_testd
udp 0 0 :::23526 :::* 2987/ora_pmon_testd
udp 0 0 :::111 :::* 1475/rpcbind
udp 0 0 ::1:20986 :::* 2483/ohasd.bin
udp 0 0 fe80::ea11:32ff:fe81:ecb:123 :::* 1959/ntpd
udp 0 0 ::1:123 :::* 1959/ntpd
udp 0 0 :::123 :::* 1959/ntpd
[root@testora ~]#
ss와 netstat 명령어에서 사용한 옵션의 기능은 아래와 같습니다.
-t : TCP 포트를 확인
-u : UDP 포트를 확인
-l : 리스닝하고 있는 소켓을 보여줌
-n : 포트 넘버를 보여줌
-p : 프로세스나 프로그램명을 보여줌
#. 명령어를 통해 실시간 모니터링을 하는 방법
실시간 모니터링에는 watch 란 명령어를 사용 합니다.
명령어는 위에 사용한 명령어 앞에 watch 명령어를 사용해 주면 됩니다.
watch ss -tulpn
or
watch netstat -tulpn
터미널 전체 화면으로 아래와 같은 결과가 2초마다 리프레시 됩니다.
#. watch 와 ss 명령어를 같이 사용한 경우
Every 2.0s: ss -tulpn
Wed Feb 5 14:46:40 2020
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 127.0.0.1:916 *:* users:((“rpc.statd”,1588,5))
udp UNCONN 0 0 *:802 *:* users:((“rpcbind”,1475,7))
udp UNCONN 0 0 *:111 *:* users:((“rpcbind”,1475,6))
udp UNCONN 0 0 *:13303 *:* users:((“rpc.statd”,1588,8))
udp UNCONN 0 0 52.33.171.180:123 *:* users:((“ntpd”,1959,19))
udp UNCONN 0 0 127.0.0.1:123 *:* users:((“ntpd”,1959,18))
udp UNCONN 0 0 *:123 *:* users:((“ntpd”,1959,16))
tcp LISTEN 0 128 *:111 *:* users:((“rpcbind”,1475,8))
tcp LISTEN 0 128 :::1521 :::* users:((“tnslsnr”,2827,12))
tcp LISTEN 0 32 *:21 *:* users:((“vsftpd”,1974,3))
tcp LISTEN 0 128 :::22 :::* users:((“sshd”,29428,4))
tcp LISTEN 0 128 *:22 *:* users:((“sshd”,29428,3))
tcp LISTEN 0 100 127.0.0.1:25 *:* users:((“master”,2420,12))
tcp LISTEN 0 128 :::5500 :::* users:((“tnslsnr”,2827,19))
tcp LISTEN 0 128 *:63132 *:* users:((“rpc.statd”,1588,9))
#. watch와 netstat 명령어를 같이 사용한 경우
Every 2.0s: netstat -tulpn
Wed Feb 5 14:49:04 2020
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2016 0.0.0.0:* LISTEN 19084/oraagent.bin
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1475/rpcbind
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 1974/vsftpd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 29428/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2420/master
tcp 0 0 0.0.0.0:63132 0.0.0.0:* LISTEN 1588/rpc.statd
tcp 0 0 :::13982 :::* LISTEN 3035/ora_d000_testd
udp 0 0 :::802 :::* 1475/rpcbind
udp 0 0 ::1:47535 :::* 3039/ora_s000_testd
udp 0 0 :::55602 :::* 1588/rpc.statd
udp 0 0 ::1:19397 :::* 2915/asm_lreg_+ASM
udp 0 0 ::1:59862 :::* 3035/ora_d000_testd
udp 0 0 :::23526 :::* 2987/ora_pmon_testd
udp 0 0 :::111 :::* 1475/rpcbind
udp 0 0 ::1:20986 :::* 2483/ohasd.bin
udp 0 0 fe80::ea11:32ff:fe81:ecb:123 :::* 1959/ntpd
udp 0 0 ::1:123 :::* 1959/ntpd
udp 0 0 :::123 :::* 1959/ntpd

By haisins

오라클 DBA 박용석 입니다. haisins@gmail.com 으로 문의 주세요.

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다