웹관련자료(web)/linux & server

ubuntu 18.04 LTS 에서 자주 사용하는 netstat 명령

2pie 2022. 2. 4. 15:03
반응형

많이 사용하는 옵션(netstat --help)

        -r, --route              display routing table (라이팅 테이블)
        -i, --interfaces         display interface table(인터페이스 테이블)
        -s, --statistics         display networking statistics (like SNMP)(네크워크 통계)

        -n, --numeric            don't resolve names(PORT 넘버)
        --numeric-hosts          don't resolve host names
        --numeric-ports          don't resolve port names
        --numeric-users          don't resolve user names
        -p, --programs           display PID/Program name for sockets(PID/프로그램 이름)

        -l, --listening          display listening server sockets(대기중인 서버 소켓)
        -a, --all                display all sockets (default: connected)(모든 소켓)

#자주 사용하는 netstat

$ netstat -nap : 연결을 대기중인 목록과 프로그램 목록

ubuntu@ubuntu:~$ netstat -nap
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -
tcp        0     64 192.168.10.47:22        192.168.10.1:49826      ESTABLISHED -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 ::1:631                 :::*                    LISTEN      -
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -
udp        0      0 0.0.0.0:49056           0.0.0.0:*                           -
udp        0      0 127.0.0.53:53           0.0.0.0:*                           -
udp        0      0 0.0.0.0:68              0.0.0.0:*                           -
udp        0      0 0.0.0.0:631             0.0.0.0:*                           -
udp6       0      0 :::5353                 :::*                                -
udp6       0      0 :::53834                :::*                                -
raw6       0      0 :::58                   :::*                    7           -
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name     Path
unix  2      [ ]         DGRAM                    26110    -                    /run/systemd/journal/syslog
unix  24     [ ]         DGRAM                    26112    -                    /run/systemd/journal/dev-log
unix  2      [ ACC ]     STREAM     LISTENING     26116    -                    /run/systemd/journal/stdout
unix  9      [ ]         DGRAM                    26118    -                    /run/systemd/journal/socket
unix  2      [ ]         DGRAM                    51014    4266/systemd    

 

$ netstat -an | grep PORT : 지정된 PORT가 사용중인지 정보확인

$ netstat -an | grep 22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0     64 192.168.10.47:22        192.168.10.1:49826      ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN
unix  2      [ ACC ]     STREAM     LISTENING     51022    /run/user/1000/bus
unix  2      [ ACC ]     STREAM     LISTENING     41722    /tmp/.X11-unix/X1024
unix  2      [ ACC ]     STREAM     LISTENING     52259    @/tmp/dbus-myKR69iedh
unix  3      [ ]         STREAM     CONNECTED     62280    @/tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     55122
unix  3      [ ]         STREAM     CONNECTED     28922    /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     52229
unix  3      [ ]         STREAM     CONNECTED     62279

 

$ netstat -ntlp : TCP 에서 리스링중인 PORT & PROGRAM 정보

$ netstat -ntlp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 ::1:631                 :::*                    LISTEN      -

 

반응형