如何使用netfilter抓包?
我现在正在使用libpcap捕获GRE数据包并转发,我认为效率不是很好。
所以我决定使用 netfilter 进行转发,但我对此很陌生。有人能给我一个
简单的例子来使用 netfilter 捕获 IP 或 GRE 数据包吗?谢谢!
I am using libpcap to capture GRE packets and forward now, I think the efficiency is not very good.
so I decide to do forwarding with netfilter, but I am new for this. Could someone gives me one
simple example to capture IP or GRE packets with netfilter? thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前尚不清楚您想要实现什么目标。您是否尝试捕获数据包进行分析(例如wireshark或tcpdump),或者通过GRE隧道转发流量?
如果您尝试捕获流量进行分析,那么使用 netfilter 没有多大意义。使用 QUEUE 目标之类的东西将数据包传递到用户空间可能是可能的,但我怀疑你会比使用带有合适 BPF 规则的 libpcap 获得更好的性能。
如果您尝试通过 GRE 隧道转发流量,通常的方法是设置 gre 隧道接口;执行
man ip
并查看“隧道”部分。隧道接口(例如gre0)是系统路由表可以向其发送数据包的普通网络接口。It's not clear what you're trying to accomplish. Are you trying to capture the packets for analysis (like wireshark or tcpdump), or forward traffic through a GRE tunnel?
If you're trying to capture traffic for analysis, using netfilter doesn't make much sense. It's probably possible, using something like the QUEUE target to pass packets to userspace, but I doubt you'd get better performance than using libpcap with suitable BPF rules.
If you're trying to forward traffic through a GRE tunnel, the normal way to do that is to set up a gre tunnel interface; do
man ip
and look at the "tunnel" section. The tunnel interface (e.g. gre0) is a normal network interface that the system's routing table can send packets to.