TCP DUMP 명령어 예
# tcpdump -i eth0 => 인터페이스 eth0 을 보여줌
# tcpdump -w tcpdump.log => 결과를 파일로 저장, txt 가 아닌 bin 형식으로 저장됨
# tcpdump -r tcpdump.log => 저장한 파일을 읽음
# tcpdump -i eth0 -c 10 => 카운터 10개만 보여줌
# tcpdump -i eth0 tcp port 80 => tcp 80 포트로 통신하는 패킷 보여줌
# tcpdump -i eth0 src 192.168.0.1 => source ip 가 192.168.0.1인 패킷 보여줌
# tcpdump -i eth0 dst 192.168.0.1 => destination ip 가 192.168.0.1인 패킷 보여줌
※ eth0의 경우, RHEL 8 에서는 없어서 enp0s8로 해야 로깅이 가능했다.
* and 옵션으로 여러가지 조건의 조합 가능
# tcpdump -i eth0 src 192.168.0.1 and tcp port 80 => source ip 가 192.168.0.1이면서 tcp port 80 인 패킷 보여줌
# tcpdump -w tcpdump.log -i eth0 dst xxx.xx.xx.xx and udp and port 514 => 목적이 ip가 xxx.xx.xx.xx인 곳으로 514포트를 사용하는 udp 패킷을 tcpdump.log 파일에 저장(!)
# tcpdump -r tcpdump.log => dump파일을 읽을때 -r 옵션
# tcpdump -i eth0 dst 192.168.0.1 => dest ip 가 192.168.0.1인 패킷 보여줌
# tcpdump host 192.168.0.1 => host 를 지정하면, 이 ip 로 들어오거가 나가는 양방향 패킷 모두 보여줌
# tcpdump src 192.168.0.1 => host 중에서 src 가 192.168.0.1인것 만 지정
# tcpdump dst 192.168.0.1 => host 중에서 dst 가 192.168.0.1인것 만 지정
# tcpdump net 192.168.0.1/24 => CIDR 포맷으로 지정할 수 있다.
# tcpdump tcp => TCP 인것만
# tcpdump udp => UDP 인것만
# tcpdump port 3389 => 포트 양뱡항으로 3389인 것.
# tcpdump src port 3389 => src 포트가 3389인 것.
# tcpdump dst port 3389 => dst 포트가 3389인 것.
* combine : and ( && ) , or ( || ) , not ( ! ) 으로 여러가지를 조합해서 사용 가능
# tcpdump udp and src port 53 => UDP 이고 src 포트가 53 인 것
# tcpdump src x.x.x.x and not dst port 22 => src ip 가 x.x.x.x 이고 dst 포트가 22 가 아닌 것
* grouping : ( )
# tcpdump ‘src x.x.x.x and ( dst port 3389 or 22 )’ => src ip 가 x.x.x.x 이고 ( dst 포트가 3389 또는 22 ) 인 것 ==> 여기서는 ‘ ‘ 가 반드시 있어야 한다.
[Example]
sudo tcpdump -i enp0s8 -c 100 port 8080
인터페이스: enp0s8
대상 포트: 8080
즉, 8080으로 들어오거나 나가는 모든 TCP 트래픽만 캡처
[app@test1 ~]$ sudo tcpdump -i enp0s8 -c 100 port 8080
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s8, link-type EN10MB (Ethernet), capture size 262144 bytes
10:53:57.696350 IP test1.webcache > 192.168.56.1.17601: Flags [F.], seq 3349399248, ack 2439197378, win 229, length 0
10:53:57.698232 IP 192.168.56.1.17601 > test1.webcache: Flags [.], ack 1, win 255, length 0
10:54:03.075030 IP 192.168.56.1.17601 > test1.webcache: Flags [F.], seq 1, ack 1, win 255, length 0
10:54:03.075076 IP test1.webcache > 192.168.56.1.17601: Flags [.], ack 2, win 229, length 0
10:54:03.075224 IP 192.168.56.1.5701 > test1.webcache: Flags [S], seq 2861259927, win 65535, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
10:54:03.075256 IP test1.webcache > 192.168.56.1.5701: Flags [S.], seq 3493199992, ack 2861259928, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
10:54:03.075584 IP 192.168.56.1.39052 > test1.webcache: Flags [P.], seq 364677200:364677761, ack 3354378389, win 254, length 561: HTTP: GET /test/ HTTP/1.1
10:54:03.075613 IP test1.webcache > 192.168.56.1.39052: Flags [.], ack 561, win 254, length 0
10:54:03.075764 IP 192.168.56.1.5701 > test1.webcache: Flags [.], ack 1, win 255, length 0
10:54:03.106389 IP test1.webcache > 192.168.56.1.39052: Flags [P.], seq 1:67, ack 561, win 254, length 66: HTTP: HTTP/1.1 304 Not Modified
10:54:03.146769 IP 192.168.56.1.39052 > test1.webcache: Flags [.], ack 67, win 254, length 0
10:54:48.076898 IP 192.168.56.1.5701 > test1.webcache: Flags [.], seq 0:1, ack 1, win 255, length 1: HTTP
10:54:48.076954 IP test1.webcache > 192.168.56.1.5701: Flags [.], ack 1, win 229, options [nop,nop,sack 1 {0:1}], length 0
10:54:48.107511 IP 192.168.56.1.39052 > test1.webcache: Flags [.], seq 560:561, ack 67, win 254, length 1: HTTP
10:54:48.107561 IP test1.webcache > 192.168.56.1.39052: Flags [.], ack 561, win 254, options [nop,nop,sack 1 {560:561}], length 0
10:55:03.163525 IP test1.webcache > 192.168.56.1.39052: Flags [F.], seq 67, ack 561, win 254, length 0
10:55:03.164545 IP 192.168.56.1.39052 > test1.webcache: Flags [.], ack 68, win 254, length 0
10:55:03.195396 IP test1.webcache > 192.168.56.1.5701: Flags [F.], seq 1, ack 1, win 229, length 0
10:55:03.195721 IP 192.168.56.1.5701 > test1.webcache: Flags [.], ack 2, win 255, length 0
10:55:13.291070 IP 192.168.56.1.5701 > test1.webcache: Flags [F.], seq 1, ack 2, win 255, length 0
10:55:13.291187 IP test1.webcache > 192.168.56.1.5701: Flags [.], ack 2, win 229, length 0
10:55:13.291307 IP 192.168.56.1.39052 > test1.webcache: Flags [F.], seq 561, ack 68, win 254, length 0
10:55:13.291319 IP test1.webcache > 192.168.56.1.39052: Flags [.], ack 562, win 254, length 0
test1.webcache
→ /etc/services에 등록된 8080 포트 별칭 이름
1. 처음 나오는 FIN 패킷들 (기존 연결 종료)
makefile
코드 복사
10:53:57.696350 IP test1.webcache > 192.168.56.1.17601: Flags [F.]
10:53:57.698232 IP 192.168.56.1.17601 > test1.webcache: Flags [.]
[F.] = FIN + ACK
기존에 열려 있던 HTTP 연결을 정상 종료하는 과정
전혀 문제 없음, keep-alive 세션 정리로 흔히 보임
2. 새로운 TCP 연결 시작 (3-way handshake)
makefile
코드 복사
10:54:03.075224 IP 192.168.56.1.5701 > test1.webcache: Flags [S]
10:54:03.075256 IP test1.webcache > 192.168.56.1.5701: Flags [S.]
10:54:03.075764 IP 192.168.56.1.5701 > test1.webcache: Flags [.]
이 3줄이 바로 TCP 기본 절차 👇
SYN: 클라이언트 → 서버 (연결 요청)
SYN+ACK: 서버 → 클라이언트 (수락)
ACK: 클라이언트 → 서버 (확정)
>> 8080 포트는 정상적으로 LISTEN 중!
3. 실제 HTTP 요청 (핵심)
makefile
코드 복사
10:54:03.075584 IP 192.168.56.1.39052 > test1.webcache: Flags [P.], length 561
HTTP: GET /test/ HTTP/1.1
여기서 중요한 포인트 👇
192.168.56.1 → 클라이언트 (브라우저 / curl / 테스트 툴)
GET /test/ HTTP/1.1
[P.] = 데이터 즉시 전달
요청이 서버(8080)까지 실제로 도달함
4. 서버의 HTTP 응답
makefile
코드 복사
10:54:03.106389 IP test1.webcache > 192.168.56.1.39052
HTTP: HTTP/1.1 304 Not Modified
🔹 HTTP 304 의미
요청한 /test/ 리소스가 이전에 받은 것과 동일,
캐시된 걸 그대로 써도 됨
즉, 서버는 정상 응답
에러 ❌
WAS 문제 ❌
👉 브라우저 캐시 정책에 따른 정상 동작
5. 전체 흐름 한 줄 요약
bash
코드 복사
기존 HTTP 연결 종료
→ 새 TCP 연결 수립
→ GET /test/ 요청
→ 서버가 304 Not Modified 응답
→ 정상 ACK
아주 교과서적인 정상 흐름이야.
6. 만약 “페이지가 안 보인다”면 의심 포인트
tcpdump 상에서는 네트워크 문제 없음이 확실함.
그럼 다음은 여기야 👇
✔ 브라우저 캐시
강력 새로고침: Ctrl + F5
개발자도구 → Disable cache
✔ WAS 로그
304는 애플리케이션 로직 문제일 가능성
If-Modified-Since / ETag 처리 확인
✔ 프록시 / WebCache
Apache, Nginx, Squid, OHS 앞단 캐시 설정
mod_cache, Expires, Cache-Control
7. 디버깅용 tcpdump 추천 조합
bash
코드 복사
sudo tcpdump -i enp0s8 -nn -vv -A port 8080
-A : HTTP 헤더/본문(텍스트) 확인
-vv : TCP 옵션까지 상세 출력
✅ 결론
8080 포트 열려 있음
TCP 연결 정상
HTTP 요청 정상 도달
서버 응답 정상(304)
이 상태면 네트워크/방화벽/WAS 리스닝 문제는 배제해도 돼.
'OS > LINUX [UNIX]' 카테고리의 다른 글
| TCP DUMP(2) (0) | 2026.03.09 |
|---|---|
| Rocky Linux9 IP 변경 법 (0) | 2026.03.05 |
| High CPU 현상 시 사용하는 perf 명령어 (2) | 2025.06.30 |
| [Solaris] dtrace 사용 (0) | 2024.07.18 |
| 시그널 모음 (0) | 2024.05.20 |