Linux作为路由器 – 我如何确定使用哪个路由(取决于不同的源地址)

我有一个Linux服务器,我用它作为一个路由器,它有两个networking接口。

我使用eth0(10.76.8.60/24,10.76.8.50/24,路由器:10.76.8.1)连接到networking,eth1(192.168.1.1/24)连接到LAN交换机。 我使用SNAT将数据包从eth1转发到eth0。

问题是我想把数据包从指定的客户端(如192.168.1.8,SNAT到10.76.8.60)转发到10.76.8.111(不是默认网关:10.76.8.1,SNAT到10.76.8.50),但是其他客户端的数据包仍然被转发到默认网关。

我试图解决使用IP路由表的问题,但失败了:

 ip路由冲刷表testing
 IP路由添加默认通过10.76.8.111 src 10.76.8.60表testing

我不知道该怎么做,请帮忙。 谢谢。

你想要基于策略的 路由 。 快速的不可识别的例子:

echo 200 custom >> /etc/iproute2/rt_tables ip rule add from 192.168.1.8 lookup custom ip route add default via 10.76.8.50 dev eth0 table custom