大网数据广告活动
服务器运维问答

How to create a protocol-based default route using iproute2

· 52CE 我爱测

I'm trying to create two routes -- Send all packets with IP protocol version 100 to 1.1.1.1 (via device eth1) Send all other IP packets to 2.2.2.2 (via device eth2) Reviewing the man pages of ip-route and ip-rules, it seems like …

问题原文

原帖链接 · Runcible · CC BY-SA 3.0

I'm trying to create two routes --

Send all packets with IP protocol version 100 to 1.1.1.1 (via device eth1)
Send all other IP packets to 2.2.2.2 (via device eth2)

Reviewing the man pages of ip-route and ip-rules, it seems like I should be able to do this, but I haven't been able to figure out the correct syntax.

This article has an example of how to setup a policy-based routing, but it's based on source IP address, not protocol number: http://blog.scottlowe.org/2013/05/29/a-quick-introduction-to-linux-policy-routing/

Is it possible to create protocol-based routing rules?

已采纳解答

原帖链接 · Zoredache · CC BY-SA 3.0

This is completely untested, but maybe something like this? This method uses firewall marking.

# part ip packets with a value of 100 as a protocol
iptables -A PREROUTING -i eth0 -t mangle --proto 100 -j MARK --set-mark 1

# packets with that mark use tabpe 'p100'
ip rule add fwmark 1 table p100

# a route on table 'p100' to a gateway for that network
/sbin/ip route add default via 192.0.2.1 dev eth2 table p100

See: http://lartc.org/howto/lartc.netfilter.html

PS don't forget to disable reverse path filtering.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-03-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。