요약

  • 사용여부 확인 : netstat -lnp | grep (포트번호)
  • 죽이기 : fuser -k -n tcp (포트번호)

상세

1) 열려있는 포트확인

  • OPEN된 모든 포트 : netstat -nap
  • 특정 PORT OPEN 여부 확인 : netstat -nap | grep (포트번호)

# OPEN된 모든 포트 리스트
    [/home/oracle]$ 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.1:6010          0.0.0.0:*               LISTEN      -
    tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      -
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -

# 1521 PORT OPEN 여부 확인

\[/home/oracle\]$ netstat -nap | grep 1521  
(Not all processes could be identified, non-owned process info  
will not be shown, you would have to be root to see it all.)  
tcp 0 0 10.0.2.15:47002 10.0.2.15:1521 ESTABLISHED 2952/ora\_lreg\_ORA19  
tcp6 0 0 :::1521 :::\* LISTEN 1585/tnslsnr  
tcp6 0 0 10.0.2.15:1521 10.0.2.15:47002 ESTABLISHED 1585/tnslsnr  
tcp6 0 0 10.0.2.15:1521 10.0.2.2:54897 ESTABLISHED 3442/oracleORA19C  
tcp6 0 0 10.0.2.15:1521 10.0.2.2:54896 ESTABLISHED 3440/oracleORA19C  
unix 2 \[ ACC \] STREAM LISTENING 27485 1585/tnslsnr /var/tmp/.oracle/sEXTPROC1521    

2-1) 포트 사용/연결프로그램 확인

  • 실행중인 프로그램의 PORT 목록 : netstat -ln
  • 특정 PORT에서 사용하는 프로그램 확인 (PID까지) : lsof -i TCP:(포트번호)
# 실행중인 프로그램의 PORT 목록
\[/home/oracle\]$ netstat -ln  
Active Internet connections (only servers)  
Proto Recv-Q Send-Q Local Address Foreign Address State  
tcp 0 0 127.0.0.1:6010 0.0.0.0:\* LISTEN  
tcp 0 0 127.0.0.1:6011 0.0.0.0:\* LISTEN

# 1521 PORT에서 사용하는 프로그램 확인 (PID까지)

\[/home/oracle\]$ lsof -i TCP:1521  
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME  
tnslsnr 1585 oracle 8u IPv6 27480 0t0 TCP \*:ncube-lm (LISTEN)  
tnslsnr 1585 oracle 14u IPv6 38386 0t0 TCP HORA19C:ncube-lm->HORA19C:47002 (ESTABLISHED)  
ora\_lreg\_ 2952 oracle 11u IPv4 38979 0t0 TCP HORA19C:47002->HORA19C:ncube-lm (ESTABLISHED)

2-2) 포트 연결프로그램 작업상태 확인

  • PID 연결프로그램 확인 : netstat -lnp | grep (PID)
  • PID 작업상태 확인 : ps auwex | grep -w (PID)
# PID:1585, 2952 연결프로그램 확인
\[/home/oracle\]$ netstat -lnp | grep 2952  
(Not all processes could be identified, non-owned process info  
will not be shown, you would have to be root to see it all.)  
udp6 0 0 ::1:48539 :::\* 2952/ora\_lreg\_ORA19  
\[/home/oracle\]$ netstat -lnp | grep 1585  
(Not all processes could be identified, non-owned process info  
will not be shown, you would have to be root to see it all.)  
tcp6 0 0 :::1521 :::\* LISTEN 1585/tnslsnr  
tcp6 0 0 :::5500 :::\* LISTEN 1585/tnslsnr  
unix 2 \[ ACC \] STREAM LISTENING 27484 1585/tnslsnr /var/tmp/.oracle/s#1585.1  
unix 2 \[ ACC \] STREAM LISTENING 27485 1585/tnslsnr /var/tmp/.oracle/sEXTPROC1521  
unix 2 \[ ACC \] STREAM LISTENING 27486 1585/tnslsnr /var/tmp/.oracle/s#1585.2

3) 프로세스 죽이기

  • fuser -k -n tcp (포트번호)

netstate 변형

  • LISTEN 되는 모든 포트 : netstat -l 또는 netstat -nap | grep LISTEN
  • 모든 서비스 동시 접속자 수 : netstat -nap | grep ESTABLISHED | wc -l
  • 웹 동시 접속자 수 : netstat -nap | grep :80 | grep ESTABLISHED | wc -l
  • 네트웍 상태를 확인 : netstat -rn
반응형

BELATED ARTICLES (관련글)

more