iptrace 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-iptrace
핵심 정리
- 네트워크 인터페이스에서 오가는 IP 패킷을 잡아 파일(LogFile)에 남기는 데몬입니다. 결과 파일은
ipreport로 읽기 쉽게 바꿔 봅니다. - 시작:
startsrc -s iptrace -a "-i en0 -s 10.1.1.20 -b /tmp/ipt.out", 중지:stopsrc -s iptrace. 명령줄에서 바로 시작했으면kill -15 PID로 멈춥니다. - 필터:
-i(인터페이스),-s·-d(출발지·목적지 호스트,-b면 양방향),-p(포트),-P(프로토콜),-a(ARP 제외),-e(무차별 모드). -B(BPF 사용)와-S 크기(패킷당 저장 길이, 기본 80바이트),-T(tcpdump 형식, Wireshark로 열 수 있음),-L 크기(파일 크기 제한)를 함께 많이 씁니다.- 결과 파일을 NFS에 두면 데몬이 멈출 수 있습니다.
kill -9로 끝냈으면iptrace -u로 커널 확장을 내립니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (6.1에서 -Q(필터된 시스템 추적)·-V(소켓 디버그)와 WPAR에서 -B를 쓸 수 없다는 안내가 더해짐) |
| 원문 | IBM Commands Reference — 5.3 Volume 3, 6.1 Volume 3 |
| 파일 | /usr/sbin/iptrace, /etc/protocols, /etc/services |
| 관련 명령어 | ipreport, tcpdump, startsrc, stopsrc, trace |
목적
인터넷 프로토콜의 인터페이스 수준 패킷 추적을 제공합니다.
영어 원문
Provides interface-level packet tracing for Internet protocols.
구문
/usr/sbin/iptrace [ -a ] [ -b ] [ -e ] [ -u ] [ -P Protocol_list ] [ -i Interface ] [ -p Port_list ]
[ -s Host [ -b ] ] [ -d Host ] [ -L Log_size ] [ -B ] [ -Q [ -V ] ] [ -T ]
[ -S snap_length ] LogFile
-Q와 -V는 6.1 구문에만 있습니다.
설명
/usr/sbin/iptrace 데몬은 구성된 인터페이스에서 받은 인터넷 패킷을 기록합니다. 명령 플래그로 필터를 주어 특정 조건에 맞는 패킷만 추적합니다. 패킷은 iptrace 데몬을 시작한 로컬 호스트와 원격 호스트 사이의 것만 추적합니다.
시스템 자원 제어기(SRC) 없이 명령줄에서 시작했으면 kill -15로 멈춰야 합니다. 다른 방법으로 멈추면 iptrace가 올린 커널 확장이 메모리에 남습니다.
LogFile 매개변수는 결과를 보낼 파일 이름입니다. 이 파일을 형식화하려면 ipreport를 실행합니다. ipreport가 TRACING DROPPED xxxx PACKETS 메시지를 보여 줄 수 있는데, 이는 패킷 크기가 소켓 수신 버퍼보다 커서 iptrace가 잡지 못한 패킷 수일 뿐, 시스템이 패킷을 버렸다는 뜻이 아닙니다.
참고:
- LogFile은 NFS로 마운트한 파일 시스템에 두지 않습니다. 그러면
iptrace가 멈출 수 있고, 데몬을 끝내지 못해 시스템을 다시 시작해야 할 수도 있습니다. kill -9로 끝냈으면iptrace -u로 bpf 커널 확장을 내리거나 재부팅해야 합니다. 바쁜 시스템에서는 커널 확장이 패킷을 처리하느라 바빠iptrace -u를 여러 번 해야 할 수도 있습니다.iptrace는srcmstr도 지원하며 명령줄에서도 시작하고 멈출 수 있습니다. 명령줄에서 시작했으면kill -9로 멈출 수 있습니다.
영어 원문
The /usr/sbin/iptrace daemon records Internet packets received from configured interfaces. Command flags provide a filter so that the daemon traces only packets that meeting specific criteria. Packets are traced only between the local host on which the iptrace daemon is started and the remote host.
If the iptrace process was started from a command line without the System Resource Controller (SRC), it must be stopped with the kill -15 command. The kernel extension that is loaded by the iptrace daemon remains active in memory if iptrace is stopped in any other way.
The LogFile parameter specifies the name of a file to which the results of the iptrace command are sent. To format this file, run the ipreport command. The ipreport command might display the message TRACING DROPPED xxxx PACKETS. This count of dropped packets indicates only the number of packets that the iptrace command was unable to grab because of a large packet, the size of which exceeded the socket-receive buffer size. This message does NOT mean that the packets are being dropped by the system.
Note:
The file that is specified by the LogFile parameter must not exist on an NFS-mounted file system. Specifying an output file on an NFS-mounted file system can cause the iptrace daemon to hang. In this case, you might not be able to kill the iptrace daemon, thus, requiring that you restart the system.
If iptrace is killed with kill -9, it is required that you issue iptrace -u to unload the bpf kernel extensions or simply reboot. Sometimes, on a busy system, it is required that you issue iptrace -u multiple times because of the possibility that the kernel extension used by iptrace is busy processing packets.
The iptrace command supports srcmstr as well and can be started and stopped from the command line. If started from the command line, it can be stopped by using the kill -9 command.
플래그
| 플래그 | 설명 |
|---|---|
-a |
ARP 패킷을 빼고 기록합니다. |
-b |
-d나 -s를 양방향 모드로 바꿉니다. |
-B |
패킷을 잡는 데 BPF를 씁니다. (6.1) WPAR 안에서 -B를 쓰면 오류가 납니다. |
-d Host |
목적지가 Host인 패킷을 기록합니다. Host는 호스트 이름이나 점 10진수 IP 주소입니다. -b와 함께 쓰면 그 호스트로 가고 오는 패킷을 모두 기록합니다. |
-e |
지원하는 네트워크 어댑터에서 무차별(promiscuous) 모드를 켭니다. |
-i Interface |
그 인터페이스에서 받은 패킷을 기록합니다. |
-L Log_size |
시작할 때와 LogFile이 약 Log_size 바이트가 될 때마다 LogFile을 LogFile.old로 복사하며 기록합니다. |
-P Protocol_list |
쉼표로 나눈 프로토콜 목록의 패킷을 기록합니다. 10진수나 /etc/protocols의 이름을 씁니다. |
-p Port_list |
쉼표로 나눈 포트 목록의 패킷을 기록합니다. 10진수나 /etc/services의 이름을 씁니다. |
-Q |
기록한 패킷에 대해 필터된 시스템 추적을 켭니다. 켜면 AIX trace 데몬이 네트워크 통신 하위 시스템 관련 이벤트를 기록합니다. 패킷은 BPF로 잡습니다. 6.1부터 |
-s Host |
출발지가 Host인 패킷을 기록합니다. -b와 함께 쓰면 그 호스트로 가고 오는 패킷을 모두 기록합니다. |
-S snap_length |
-B(BPF)로 실행할 때 패킷마다 실제로 잡을 길이. 예: iptrace -S 1500 /tmp/iptrace.dump는 1500바이트까지 잡습니다. 기본 80바이트. |
-T |
tcpdump와 호환되는 덤프 파일을 만듭니다. ipreport -T나 tcpdump -r로 읽습니다. |
-u |
시작할 때 올린 커널 확장을 내립니다. |
-V |
소켓에 소켓 디버그 플래그(SO_DEBUG)와 추적 수준을 정합니다. -Q와 함께 써야 합니다. 6.1부터 |
영어 원문
-a— Suppresses ARP packets.-b— Changes the-dor-sflags to bidirectional mode.-B— Uses BPF for packet capture. The iptrace command when used along with the -B option returns error if the command is run inside the WPAR.-dHost — Records packets that are headed for the destination host-specified by the Host variable. The Host variable can be a host name or an IP address in dotted decimal format. If used with the-bflag, the-dflag records packets both going to and coming from the host-specified by the Host variable.-e— Enables promiscuous mode on network adapters that support this function.-iInterface — Records packets received on the interface that is specified by the Interface variable.-LLog_size— This option causes iptrace to log data in such a way that theLogFileis copied toLogFile.oldat the start and also every time it becomes approximatelyLog_sizebytes long.-PProtocol_list— Records packets that use the protocol that is specified by theProtocol_listvariable which is a comma-separated list of protocols. The Protocols can be a decimal number or name from the /etc/protocols file.-pPort_list— Records packets that use the port number that is specified by thePort_listvariable which is a comma-separated list of ports. ThePort_listvariable can be a decimal number or name from the /etc/services file.-Q— Enables filtered system tracing for the recorded packets. After the tracing feature is enabled, the AIX trace daemon is run to record the selected system events that are related to the network communication subsystem. Note: The tracing feature uses Berkeley Packet Filter (BPF) for packet capture.-sHost — Records packets that come from the source that is host-specified by the Host variable. The Host variable can be a host name or an IP address in dotted decimal format. If used with the-bflag, the-sflag records packets both going to and coming from the host that is specified by the Host variable.-Ssnap_length— Specifies the snap size (how much of each packet is actually captured from the wire) when you run the iptrace daemon with the-Bflag (the bpf support). The commandiptrace -S 1500 /tmp/iptrace.dumplimits captured packet size to 1500 bytes. The default is 80 bytes.-T— Creates a tcpdump compatible dump file. To read the output, use ipreport -T or tcpdump -r.-u— Unloads the kernel extension that was loaded by the iptrace daemon at startup.-V— Sets the socket debug flag (theSO_DEBUGsocket option) and trace level on sockets. This flag must be used along with the-Qflag.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 데몬이 성공적으로 실행됨 |
| 1 | 인터페이스를 찾지 못함, pcap_open_live·pcap_datalink·pcap_lookupnet·pcap_loop 서브루틴 실패, 호스트 이름을 찾지 못함, 주소 형식이 틀림, WPAR가 작업을 허락하지 않음(6.1), setpri·fopen·fstat 실패, 링크 유형을 찾을 때 인터페이스를 모름 |
| 2 | 추적 파일에 대한 fread 실패 |
| 5 | 소켓 생성 실패, 지정한 파일이 이미 있지만 추적 파일이 아님 |
| 9 | 프로토콜이 /etc/protocols에 없음, 서비스가 /etc/services에 없음, 추적 확장(netintf)을 올리거나 내리지 못함 |
영어 원문
The command returns the following exit values:
- 0 — The daemon has run successfully.
1
No interfaces were found.
The
pcap_open_livesubroutine failed.The
pcap_datalinksubroutine failed.The
pcap_lookupnetsubroutine failed.The
pcap_loopsubroutine failed.The hostname was not found.
The address was formed incorrectly.
The WPAR did not permit the operation.
The setpri subroutine failed.
The fopen subroutine failed.
The fstat subroutine failed.
The interface is unknown when the daemon looks up the link type.
2 The fread subroutine on a trace file failed. 5
Socket creation failed.
The specified file already exists, but the file is not a trace file.
9
The protocol is not in the /etc/protocols file.
The service is not in the /etc/services file.
The daemon failed to load trace extension (netintf).
The daemon failed to unload trace extension.
보안
RBAC 사용자와 Trusted AIX 사용자는 주의하세요. 이 명령은 특권 작업을 할 수 있으며, 특권 작업은 특권 사용자만 할 수 있습니다. 특권과 권한 목록은 lssecattr 명령이나 getcmdattr 하위 명령으로 봅니다(6.1 문서에만 있음).
영어 원문
Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.
예제
| 명령 | 하는 일 |
|---|---|
startsrc -s iptrace -a "/tmp/nettrace" |
SRC로 iptrace를 시작 |
stopsrc -s iptrace |
SRC로 iptrace를 멈춤 |
iptrace /tmp/nettrace |
모든 인터페이스에서 로컬 호스트와 다른 모든 호스트 사이의 패킷을 /tmp/nettrace에 기록 |
iptrace -i en0 -p telnet -s airmail /tmp/telnet.trace |
en0에서 원격 호스트 airmail로부터 telnet 포트로 받은 패킷을 기록 |
iptrace -i en0 -s airmail -b /tmp/telnet.trace |
en0에서 원격 호스트 airmail과 주고받은 패킷을 양방향으로 기록 |
자주 쓰는 형태:
startsrc -s iptrace -a "-i en0 -d 10.1.1.20 -b -B -S 1500 -T /tmp/ipt.pcap"
# ... 문제 재현 ...
stopsrc -s iptrace
ipreport -nrs /tmp/ipt.pcap > /tmp/ipt.txt # 사람이 읽을 보고서(-T 파일이면 ipreport -T)
tcpdump -nr /tmp/ipt.pcap | head # tcpdump로 읽기
영어 원문
- To start the iptrace daemon with the System Resource Controller (SRC), enter the following command:
startsrc -s iptrace -a "/tmp/nettrace"
To stop the iptrace daemon with SRC enter the following command: stopsrc -s iptrace
- To record packets that come in and go out to any host on every interface, enter the command in the following format:
iptrace /tmp/nettrace
The recorded packets are received on and sent from the local host. All packet flow between the local host and all other hosts on any interface is recorded. The trace information is placed into the /tmp/nettrace file.
- To record packets that are received on an interface from a specific remote host, enter the command in the following format:
iptrace -i en0 -p telnet -s airmail /tmp/telnet.trace
The packets to be recorded are received on the en0 interface, from remote host airmail, over the telnet port. The trace information is placed into the /tmp/telnet.trace file.
- To record packets that come in and go out from a specific remote host, enter the command in the following format:
iptrace -i en0 -s airmail -b /tmp/telnet.trace
The packets to be recorded are received on the en0 interface, from remote host airmail. The trace information is placed into the /tmp/telnet.trace file.
Related reference:
- ipreport Command
Related information:
- protocols command
- sodebug command
- trace Daemon
리눅스(GNU)와 다른 점
리눅스에는 iptrace 데몬이 없고 tcpdump -i eth0 -s 0 -w /tmp/cap.pcap host 10.1.1.20 and port 22처럼 tcpdump(또는 tshark)로 잡습니다. 필터는 BPF 식으로 주며, 결과는 tcpdump -r이나 Wireshark로 봅니다. AIX에서도 iptrace -T나 tcpdump로 pcap 파일을 만들면 Wireshark로 함께 분석할 수 있습니다.