根據tcpdump
,我的伺服器收到以下 TCP 封包:
12:52:29.603233 00:19:e2:9e:df:f0
00:16:3e:6a:25:3f, ethertype IPv4 (0x0800), length 74: 10.10.10.65.38869
192.168.215.82.22: Flags [S], seq 567054335, win 5840, options [mss 1460,sackOK,TS val 2096335479 ecr 0,nop,wscale 0], length 0
如上所示,它是發送到 TCP 連接埠 22 的 TCP SYN 封包,在我的例子中,該連接埠監聽sshd
.我想看看這個 TCP 封包是否到達了sshd
進程。我想一種選擇是sshd
在調試模式下重新啟動。但是,是否有其他聰明的工具/方法來查看偵聽 TCP 連接埠的進程是否收到訊息?對於 TCP SYN 封包,我猜是核心 TCP/IP 堆疊將發送 TCP SYN+ACK 而不是sshd
?
答案1
但是,是否有其他聰明的工具/方法來查看偵聽 TCP 連接埠的進程是否收到訊息?
您可以strace
與 一起使用-e trace=network
。這是它在接受 TCP 連線、接收 HTTP 請求、發送 HTTP 回應和關閉連線時列印的內容:
$ strace -v -f -e trace=network -p `cat logs/my_server.pid`
Process 2361 attached with 44 threads - interrupt to quit
[pid 2422] accept(11, {sa_family=AF_INET, sin_port=htons(56289), sin_addr=inet_addr("172.30.1.60")}, [16]) = 14
[pid 2422] getsockname(14, {sa_family=AF_INET, sin_port=htons(7754), sin_addr=inet_addr("172.30.1.60")}, [16]) = 0
[pid 2422] setsockopt(14, SOL_TCP, TCP_NODELAY, [1], 4) = 0
[pid 2422] setsockopt(14, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
[pid 2422] getsockopt(14, SOL_SOCKET, SO_OOBINLINE, [515004615020773376], [4]) = 0
[pid 2388] recvfrom(14, "GET /OPEN_", 10, MSG_PEEK, NULL, NULL) = 10
[pid 2388] recvfrom(14, "GET /OPEN_SESSION?LOGIN=HAS_ADMI"..., 4096, 0, NULL, NULL) = 246
[pid 2388] sendto(14, "HTTP/1.1 200 OK\r\nServer: MY_SER"..., 192, 0, NULL, 0) = 192
[pid 2388] sendto(14, "<?xml version='1.0' encoding = '"..., 680, 0, NULL, 0) = 680
[pid 2361] --- SIGIO (I/O possible) @ 0 (0) ---
[pid 2388] recvfrom(14, "", 4096, 0, NULL, NULL) = 0
[pid 2388] shutdown(14, 2 /* send and receive */) = 0