AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 466584
Accepted
Artem S. Tashkinov
Artem S. Tashkinov
Asked: 2018-09-04 06:56:13 +0800 CST2018-09-04 06:56:13 +0800 CST 2018-09-04 06:56:13 +0800 CST

tcpdump/tshark:只查看传出的 TCP 连接请求

  • 772

我想查看TCP我的 PC/服务器向其他主机发起的请求(同步数据包)。更具体地说,我想查看outgoing connection requests. 我怎样才能做到这一点?

此外,我不想看到任何连接到我的 PC/服务器的尝试。

以下iptables命令有效,但使用起来很笨拙,因为它记录了所有内容,而我只想查看屏幕上的所有内容:

iptables -I OUTPUT 1 -o eth0 -p tcp -m state --state NEW -j LOG
networking tcpdump
  • 1 1 个回答
  • 9699 Views

1 个回答

  • Voted
  1. Best Answer
    slm
    2018-09-04T07:04:59+08:002018-09-04T07:04:59+08:00

    如果您想查看来自您的主机的传出 TCP 连接,您可以使用 switchsrc host <ip>作为参数tcpdump:

    $ tcpdump -i any -nn src host 10.0.2.15 and port 80
    

    例子

    模拟传出流量:

    $ curl -vv telnet://www.google.com:80
    * About to connect() to www.google.com port 80 (#0)
    *   Trying 172.217.15.100...
    * Connected to www.google.com (172.217.15.100) port 80 (#0)
    ^C
    

    观看tcpdump:

    $ tcpdump -i any -nn src host 10.0.2.15 and port 80
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
    11:04:19.585773 IP 10.0.2.15.50642 > 216.58.218.4.80: Flags [S], seq 315169574, win 29200, options [mss 1460,sackOK,TS val 38358006 ecr 0,nop,wscale 7], length 0
    11:04:19.623676 IP 10.0.2.15.50642 > 216.58.218.4.80: Flags [.], ack 470600706, win 29200, length 0
    

    过滤同步数据包

    要仅捕获传出的 syn 数据包,您需要分析 tcpflags,特别是寻找tcp-syn标志。再次使用上面的相同curl命令,但现在调用tcpdump如下:

    $ tcpdump -i any -nn src host 10.0.2.15 and "tcp[tcpflags] == tcp-syn"
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
    11:13:39.962475 IP 10.0.2.15.44810 > 64.233.185.103.80: Flags [S], seq 3710429425, win 29200, options [mss 1460,sackOK,TS val 38918382 ecr 0,nop,wscale 7], length 0
    

    tcpflags

    从tcpdump手册页:
    The general format of a TCP protocol line is:
    
    src > dst: Flags [tcpflags], seq data-seqno, ack ackno, win window, urg urgent, options [opts], length len
    
    Src and dst are the source and destination IP addresses and ports. 
    Tcpflags are some combination of S (SYN), F (FIN), P (PUSH), R (RST), U 
    (URG), W (ECN CWR), E (ECN-Echo) or `.' (ACK), or `none' if no flags are 
    set. Data-seqno describes the portion of sequence space covered by the 
    data in this packet (see example below). Ackno is sequence number of the 
    next data expected the other direction on this connection. Window is the 
    number of bytes of receive buffer space available the other direction on 
    this connection. Urg indicates there is `urgent' data in the packet. Opts 
    are TCP options (e.g., mss 1024). Len is the length of payload data.
    

    参考

    • 带有示例的 tcpdump 教程和入门
    • 如何通过 Tcpdump 捕获 ack 或 syn 数据包?
    • slmingol/tcp_flags.txt
    • Amit 的笔记 - Docs » Networking » tcpdump
    • 5

相关问题

  • 查找与端口关联的线程/脚本?

  • 关于网络挂载文件的问题

  • IP地址可以以255结尾而不是广播IP地址吗?

  • 无法识别arp命令或ip命令哪个MAC地址输出正确

  • 奇怪的路由器与centos 6一起工作[关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    ssh 无法协商:“找不到匹配的密码”,正在拒绝 cbc

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    如何卸载内核模块“nvidia-drm”?

    • 13 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add 返回:“连接代理时出错:没有这样的文件或目录” 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve