2014年11月11日 星期二

tcpdump

tcpdump 透過 libpcap,使用 kernel 裡或 userspace 的 BPF 虛擬機器進行封包擷取工作,並將封包加以解釋後輸出。

指令格式
tcpdump [參數] [過濾表示式]
其中參數以「-」開頭,可能接著參數值,剩下的為過濾表示式。

執行 tcpdump,網卡原本只收 MAC 定址符合和廣播的封包,會進入 "promiscuous" 模式改接收所有的封包,處理額外的封包會用掉一些處理器效能。

參數

  • -s0:擷取整個封包,而不是只有前 68 byte。
  • -n:不解析主機名稱、MAC 位址,可加快處理,避免錯過封包。
  • -i:指定要等待的網卡界面
  • -w:結果存到 pcap 檔 
  • -d: 
  • -dd:
  • -ddd:
範例
  • tcpdump # 全抓
  • tcpdump -i eth0
  • tcpdump -r in.pcap #讀取檔案
  • tcpdump -i eth0 -G 3600 -w 'file.pcap' # 每小時 rotating
  • tcpdump -i eth0 -C 100 -w capture # 每 100MB 換檔案
  • tcpdump -s0 -n -i ethX -w /tmp/$(hostname)-$(date +"%Y-%m-%d-%H-%M-%S").pcap host <ip-address>
  • tcpdump 'udp port 20000 or (ip[6:2] & 0x1fff) != 0' # 抓 udp port 20000 和所有 fragment offset 不為 0 的封包 (有些 Linux 版本反順序傳送 IP fragments,讓最後 fragment 先收到而能更正確預測 reassembled 後的封包大小。)

遠端 tcpdump

參考

  1. BPF - the forgotten bytecode
測試網路連線
  • ping
  • traceroute 或 mtr
  • route -n 或 ip route
  • ip addr list 或 ifconfig
  • arp -an 或 cat /proc/net/arp
測試遠端通訊埠
  • nc (netcat)
  • wget 或 curl
  • nmap
檢查 link 狀態
  • dmesg | egrep “eth|em” 或 cat /var/log/messages
  • ip link show
  • mii-tool eth0 (deprecated , doesn't work on Gigabit NICs)
  • ethtool eth0 (net-tools 提供)
  • cat /sys/class/net/eth0/operstate
  • lsof (list open file)
查詢封包 loss
  • ifconfig
  • ethtool -S
    • 加大 buffer 大小:ethtool -g eth0 或 ethtool -G eth0 rx 4096
  • netstat -s
  • dropwatch
  • sar -n NDEV (每秒有多少錯)
調整 TCP socket buffer:/etc/sysctl.conf
  • net.ipv4.tcp_rmem = 4096 87380 4194304
  • net.ipv4.tcp_wmem = 4096 87380 4194304
socket 統計
  • ss -t -a:顯示所有 TCP socket
  • ss -it:socket 內部資訊
中斷負載平衡及 multiqueue:cat /proc/interrupts
offloading:ethtool -k eth0

沒有留言:

張貼留言

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...