linux - 在 ping 中使用 -m 选项

标签 linux unix networking ping

ping -m 选项有什么用?我阅读了 ping 手册页,但无法理解。谷歌搜索后,我看到如果使用 -m 选项,则会将 SO_MARK 选项添加到套接字。那么,这个选项有什么用,什么时候用呢?

提前致谢。

最佳答案

在 Linux 上,SO_MARK用于标记传出数据包:

   SO_MARK (since Linux 2.6.25)
          Set the mark for each packet sent through this socket (similar
          to the netfilter MARK target but socket-based).  Changing the
          mark can be used for mark-based routing without netfilter or
          for packet filtering.  Setting this option requires the
          CAP_NET_ADMIN capability.

因此,如果您使用该选项执行 ping 操作:

$ping -m 10 <host>

然后可以在 <host> 上使用 iptables 对其进行过滤:

$iptables -A INPUT -m mark --mark 0xa -j ACCEPT

或直接在代码中使用 getsockopt() .

它可以用于多种原因,例如路由决策或网络调试。

关于linux - 在 ping 中使用 -m 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36856897/

相关文章:

c - 编写 Linux 内存驱动程序以将小写字母转换为大写字母

unix - 像 "You have mail in/usr/spool/mail/root"这样的消息的目的是什么?

java - 调整 Java 套接字的性能

linux - unix复制/下载进度状态更新

c - UDP 客户端显示 'UDP Connected' 而没有 UDP 服务器在本地主机上运行

networking - 没有 Controller 和有 Controller 的mininet模拟

linux - 无法找到包色调

linux - 安装 yum php-devel 后,Centos 5 使用不同的 httpd.conf 重新启动 Apache 服务器

Linux/为什么 su 命令在 CMD 中运行而不是在脚本中运行?

c - 在 Unix 环境中,有没有办法以编程方式在 C 中调用 Which?