일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- 뚝섬유원지
- Python
- GitHub
- Grafana
- 중식
- 소모임
- 하체
- Run The Bridge
- 맛집
- 정보처리기사
- 오답노트
- 대구
- 유산소
- 10km
- zabbix
- 러닝
- 2021
- 한강
- 달리기
- 대전
- Kubernetes
- docker
- 성수대교
- Podman
- 자전거
- Linux
- 힐링
- Shell
- 건대입구역
- DSEC
- Today
- Total
Run The Bridge
tshark 란? 본문
0. 들어가기에 앞서
상어가 피 냄새를 맡고 사냥감에 다가오듯이, 네트워크 패킷 냄새를 맡고 다가온다고 해서 wireshark
wireshark는 네트워크 패킷의 흐름도를 캡처할 수 있어서 특정 호스트로부터 네트워크 패킷 흐름을 확인할 때 매우 유용하게 사용될 수 있다.
이러한 wireshark는 비단 윈도우뿐만 아니라 linux에서도 사용할 수 있는데 다음 명령을 통해 설치할 수 있다.
yum -y install wireshark gnome-wireshark
근데 이 명령은 linux의 runlevel이 5부터인 GUI 환경에서 지원하므로 runlevel이 3인 multi-user에서는 지원되지 않는다.
참고로 나의 runlevel 확인 방법과 바꾸는 방법은 다음과 같다.
root@p-iskim-master ~ # runlevel
N 3
root@p-iskim-master ~ # systemctl get-default
multi-user.target
바꾸는 방법은 set을 사용한다.
root@p-iskim-master ~ # systemctl set-default
anaconda.target getty-pre.target iprutils.target nss-lookup.target rescue.target shutdown.target system-update.target
basic.target getty.target kexec.target nss-user-lookup.target rpc_pipefs.target sigpwr.target time-sync.target
bluetooth.target graphical.target local-fs-pre.target paths.target rpcbind.target sleep.target timers.target
ceph-fuse.target halt.target local-fs.target poweroff.target runlevel0.target slices.target umount.target
cryptsetup-pre.target hibernate.target machines.target printer.target runlevel1.target smartcard.target virt-guest-shutdown.target
cryptsetup.target hybrid-sleep.target multi-user.target rdma-hw.target runlevel2.target sockets.target
ctrl-alt-del.target initrd-fs.target network-online.target reboot.target runlevel3.target sound.target
default.target initrd-root-fs.target network-pre.target remote-cryptsetup.target runlevel4.target suspend.target
emergency.target initrd-switch-root.target network.target remote-fs-pre.target runlevel5.target swap.target
final.target initrd.target nfs-client.target remote-fs.target runlevel6.target sysinit.target
1. tshark 사용법
tshark 관련해서 help를 치면 많은 명령어들이 있는데 'Capture interface'쪽을 보면 될 것 같다.
Capture interface:
-i <interface> name or idx of interface (def: first non-loopback)
-f <capture filter> packet filter in libpcap filter syntax
-s <snaplen> packet snapshot length (def: 262144)
-p don't capture in promiscuous mode
-I capture in monitor mode, if available
-B <buffer size> size of kernel buffer (def: 4MB)
-y <link type> link layer type (def: first appropriate)
-D print list of interfaces and exit
-L print list of link-layer types of iface and exit
그리고 추가로 'Processing'쪽을 보면 패킷처리 관련해서 설명이 되어 있다.
Processing:
-2 perform a two-pass analysis
-R <read filter> packet Read filter in Wireshark display filter syntax
-Y <display filter> packet displaY filter in Wireshark display filter syntax
-n disable all name resolutions (def: all enabled)
-N <name resolve flags> enable specific name resolution(s): "mnNtC"
-d <layer_type>==<selector>,<decode_as_protocol> ...
"Decode As", see the man page for details
Example: tcp.port==8888,http
-H <hosts file> read a list of entries from a hosts file, which will
then be written to a capture file. (Implies -W n)
-Y 옵션쪽이 wireshark 문법에 맞게 화면에 출력해주는 옵션이다.
추가로 '-V' 옵션으로 wireshark에 있는 상세정보를 한 번에 볼 수 있다.
-V add output of packet tree (Packet Details)
전체적인 문법은 wireshark와 완벽히 똑같으므로, wireshark 명령에 대해 검색 후 사용하면 된다.
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=kdi0373&logNo=220331471223
[wireshark] 01. 와이어샤크 필터 명령어
<와이어샤크 필터 명령어> ● TCP 출발지나 목적지 포트 번호로 검색 : tcp.port == 1004 ● TC...
blog.naver.com
2. tshark 사용법
가장 기본적으로 ping 테스트를 해서 icmp 패킷을 캡처해본다.
우선 2대의 Host-only VM을 세팅해놓고 다른 방해 없이 Ping만 잡아본다.
한쪽에서 129번 호스트로 핑을 요청하고 129번 호스트에서는 tshark로 핑을 잡아본다.
[root@localhost ~]# ping 192.168.131.129
PING 192.168.131.129 (192.168.131.129) 56(84) bytes of data.
64 bytes from 192.168.131.129: icmp_seq=1 ttl=64 time=0.404 ms
64 bytes from 192.168.131.129: icmp_seq=2 ttl=64 time=0.512 ms
64 bytes from 192.168.131.129: icmp_seq=3 ttl=64 time=0.650 ms
icmp 패킷은 호스트로 요청이 들어오기 때문에 'ifconfig', 'ip addr'같은 명령어로 나의 인터페이스 이름을 알아둔다.
tshark -i ens32 -Y 'icmp' # ens32 인터페이스의 icmp 패킷 검색
root@localhost ~ # tshark -i ens32 -Y 'icmp'
Running as user "root" and group "root". This could be dangerous.
Capturing on 'ens32'
2 0.759106630 192.168.131.128 -> 192.168.131.129 ICMP 98 Echo (ping) request id=0x16c2, seq=60/15360, ttl=64
3 0.759145690 192.168.131.129 -> 192.168.131.128 ICMP 98 Echo (ping) reply id=0x16c2, seq=60/15360, ttl=64 (request in 2)
8 1.782704305 192.168.131.128 -> 192.168.131.129 ICMP 98 Echo (ping) request id=0x16c2, seq=61/15616, ttl=64
9 1.782748493 192.168.131.129 -> 192.168.131.128 ICMP 98 Echo (ping) reply id=0x16c2, seq=61/15616, ttl=64 (request in 8)
15 2.806902173 192.168.131.128 -> 192.168.131.129 ICMP 98 Echo (ping) request id=0x16c2, seq=62/15872, ttl=64
16 2.806945687 192.168.131.129 -> 192.168.131.128 ICMP 98 Echo (ping) reply id=0x16c2, seq=62/15872, ttl=64 (request in 15)
정상적으로 패킷을 잘 잡아내는 것을 볼 수 있다.
이해를 돕기 위해 gif 파일을 한 번 확인해보자.
3. tshark 응용
kubernetes상에서 패킷의 흐름도를 확인하는 것도 매우 괜찮은 방법이다.
신기한 건, k8s에서는 각 pod마다 interface를 생성해서 만들기 때문에 packet 캡처하기 여간 어려운 게 아니다.
그래서 전체 캡처를 돌리고 특정 IP에 대해 filter를 걸어주어야 한다.
기본적인 kubernetes packet flow라는데... tshark로 직접 잡기는 어려워 보인다.
pod → 터널링용 NIC (tunl0) → SNAT → 노드 IP → 다른 노드 IP → NAT → 터널NIC → pod
다른 노드 IP 이후에 터널 NIC를 통과하는 패킷이 잡히지 않는다. ㅠㅠ 조금 더 연구해보는 걸로...
4. 유용한 명령어
tshark에서는 '-i' 옵션 뒤에 특정 interface를 지정해주는데 전체 인터페이스를 검색하고 싶으면 any를 주면 된다.
tshark -i any
또한 tshark에서 쓸 수 있는 인터페이스를 검색하려면 'tshark -D'를 입력하면 전체 인터페이스를 검색할 수 있다.
tshark -D
1. cali67773289179
2. virbr0
3. tunl0
4. calic0e2eacd0e2
5. calie0f0189162c
6. nflog
7. nfqueue
8. cali2a6da095619
9. calif4bc74304ef
10. cali4e62912f23c
11. calie5f4bba887e
12. cali5d374320207
13. calidde5f9301e4
14. calife5b979336e
15. cali6d209be76e2
16. cali6cad3f93ca9
17. cali22a0c9cb867
18. caliefb36ef2322
19. cali36b462b3164
20. cali39d0ef6406f
21. calid42da43975f
22. cali51e8b30d5ec
23. calide68cbf6199
24. ens192
25. calic440f455693
26. calie514bf4f651
27. califb1844b8de6
28. calid6551c56d00
29. cali9228f7175f1
30. cali83269a0539f
31. any
32. lo (Loopback)
-i 뒤에 인터페이스 이름 대신 숫자를 넣어도 된다.
감사합니다.
'Cloud > Linux' 카테고리의 다른 글
사용자의 입력을 받아 총 글자 수와 입력 문자 수 Count (0) | 2022.03.22 |
---|---|
linux disk pv, vg, lv 설정 (2) | 2022.03.21 |
lsof 란? (0) | 2022.03.07 |
podman 4.0.0 install (2) | 2022.03.07 |
알마 리눅스, 로키 리눅스 (0) | 2022.03.04 |