14

iptables --set-mark 走指定网卡为啥不生效

 2 years ago
source link: https://www.v2ex.com/t/806158
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

iptables --set-mark 走指定网卡为啥不生效

  bybyte · blacknight2018 · 1 天前 · 508 次点击

主机上目前有两个网络出口 两张网卡

alt

然后我设置 iptables 想把本机出口的所有流量标记为 20

alt

然后我设置了一个路由表 li 规定了从网络出口 eth1 出去到网关 192.168.123.1

localhost:~/Desktop # ip route show table li

default via 192.168.123.1 dev eth1

设置好了 ip rule 策略路由 让标记为 20 的包走路由表 li

localhost:~/Desktop # ip rule

0: from all lookup local

32764: from all fwmark 0x14 lookup li

32766: from all lookup main

32767: from all lookup default

这样设置好了按理说本机发出的数据流量会被标记为 20 然后在策略路由的时候走路由表 li,然后根据路由表的规则走 eth1 出口的吧?

但是最后发现本机发出的数据并没有走路由表 li 依然还是按照 route -n 路由表的默认路由项走

route -n 如下

localhost:~/Desktop # ip route

default via 192.168.123.96 dev eth0

192.168.123.0/24 dev eth1 proto kernel scope link src 192.168.123.85

192.168.123.0/24 dev eth0 proto kernel scope link src 192.168.123.75

数据流量依然没有走路由表 li 规定的从 eth1 口出去

localhost:~/Desktop # ip route get 8.8.8.8

8.8.8.8 via 192.168.123.96 dev eth0 src 192.168.123.75 uid 0 cache localhost:~/Desktop #

还是走的 eth0

折磨了我好几天了,想请教下 V 友们这个是什么情况,十分感谢!🙇‍


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK