V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
plko345
V2EX  ›  问与答

tcpdump net 用法疑问

  •  
  •   plko345 · 2020-08-05 16:59:46 +08:00 · 1429 次点击
    这是一个创建于 1331 天前的主题,其中的信息可能已经有所发展或是发生改变。
    # 正常开始捕获
    tcpdump net 65.192.0.0/10          # 1
    
    # 报错: tcpdump: non-network bits set in "10.44.0.0/10"
    tcpdump net 10.44.0.0/10            # 2
    
    # 正常开始捕获
    tcpdump net 10.44.0.0/14            # 3,   14 以上正常捕获
    

    找到网上的说法是:

    This is because the apparent intent of your rule is to exclude traffic from your local network, and the correct way to specify a network address is to specify the network's lowest IP address (which is called the network address) / netmask. If you specify any address other than the lowest address in the range for a network with a netmask of $myNetworkBytes, then you will get the error message:

    man page 中的解释:

    True if the IPv4/v6 address matches net with a netmask len bits wide. May be qualified with src or dst.

    OK, 然后我还是没太明白(哭~), 有大佬解释下吗? 1 可以, 2 却不行, 3 为什么 14 就可以了, 不应该是 16 之后才可以吗?

    5 条回复    2020-08-05 21:22:16 +08:00
    hatebugs
        1
    hatebugs  
       2020-08-05 17:32:33 +08:00 via Android   ❤️ 1
    44-= 00101100 14=8+6 。 老老实实先算好再用 net
    plko345
        3
    plko345  
    OP
       2020-08-05 18:23:22 +08:00
    @hatebugs 谢谢, 那为什么 tcpdump 不支持 10.44.0.0/10 这种写法呢? 这种不就等于 10.0.0.0/10 吗?
    gefranks
        4
    gefranks  
       2020-08-05 20:57:39 +08:00   ❤️ 1
    10.44.0.0/10 还真不等于 10.0.0.0/10 在我看来会产生 4 个子网 10.0.0.0/10, 10.64.0.0/10, 10.128.0.0/10, 10.192.0.0/10
    这个 44 是落在第一个子网里的, 而写目标网络的时候是按一块一块来写的.
    写主机地址的时候 10.44.0.0/10 是可以的,但是网络地址是不对的
    plko345
        5
    plko345  
    OP
       2020-08-05 21:22:16 +08:00
    @gefranks 谢谢, 大致明白了, 我再去复习下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2819 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:25 · PVG 23:25 · LAX 08:25 · JFK 11:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.