linux系统,多网卡配置,源进源出
环境:
eth1:网通 10.202.36.201/23 网关10.202.37.254 ip:10.202.36.201
eth2:教育网 10.202.41.8/23 网关10.202.41.254 ip:10.202.41.8
实现功能:
从网通进入的所有数据仍从网通出口传出。
从教育网进入的所有数据仍从教育网出口传出。
实现方法:
1.额外创建两个路由表cnc jyw
echo 200 cnc >> /etc/iproute2/rt_tables
echo 201 jyw >> /etc/iproute2/rt_tables
2.设置两个路由表中的路由:
ip route add 10.202.0.0 dev eth1 src 10.202.36.201 table cnc
ip route add default via 10.202.37.254 table cnc
ip route add 10.202.0.0 dev eth2 src 10.202.41.8 table jyw
ip route add default via 10.202.41.254 table jyw
3.设置路由
ip route add 10.202.0.0 dev eth1 src 10.202.36.201
ip route add 10.202.0.0 dev eth2 src 10.202.41.8
4.设置缺省路由
ip route add default via 10.202.37.254
5.设置路由规则
ip rule add from 10.202.36.201 table cnc
ip rule add from 10.202.41.8 table jyw
由此即可实现简单的基于源地址的路由
已实践的例子:
IP:10.202.36.201 & 10.202.41.8
echo 200 cnc >> /etc/iproute2/rt_tables
echo 201 jyw >> /etc/iproute2/rt_tables
ip route add 10.202.0.0 dev em1 src 10.202.36.201 table cnc
ip route add default via 10.202.37.254 table cnc
ip route add 10.202.0.0 dev em2 src 10.202.41.8 table jyw
ip route add default via 10.202.41.254 table jyw
ip route add 10.202.0.0 dev em1 src 10.202.36.201
ip route add 10.202.0.0 dev em2 src 10.202.41.8
ip route add default via 10.202.41.254
ip rule add from 10.202.36.201 table cnc
ip rule add from 10.202.41.8 table jyw
环境:
eth1:网通 10.202.36.201/23 网关10.202.37.254 ip:10.202.36.201
eth2:教育网 10.202.41.8/23 网关10.202.41.254 ip:10.202.41.8
实现功能:
从网通进入的所有数据仍从网通出口传出。
从教育网进入的所有数据仍从教育网出口传出。
实现方法:
1.额外创建两个路由表cnc jyw
echo 200 cnc >> /etc/iproute2/rt_tables
echo 201 jyw >> /etc/iproute2/rt_tables
2.设置两个路由表中的路由:
ip route add 10.202.0.0 dev eth1 src 10.202.36.201 table cnc
ip route add default via 10.202.37.254 table cnc
ip route add 10.202.0.0 dev eth2 src 10.202.41.8 table jyw
ip route add default via 10.202.41.254 table jyw
3.设置路由
ip route add 10.202.0.0 dev eth1 src 10.202.36.201
ip route add 10.202.0.0 dev eth2 src 10.202.41.8
4.设置缺省路由
ip route add default via 10.202.37.254
5.设置路由规则
ip rule add from 10.202.36.201 table cnc
ip rule add from 10.202.41.8 table jyw
由此即可实现简单的基于源地址的路由
已实践的例子:
IP:10.202.36.201 & 10.202.41.8
echo 200 cnc >> /etc/iproute2/rt_tables
echo 201 jyw >> /etc/iproute2/rt_tables
ip route add 10.202.0.0 dev em1 src 10.202.36.201 table cnc
ip route add default via 10.202.37.254 table cnc
ip route add 10.202.0.0 dev em2 src 10.202.41.8 table jyw
ip route add default via 10.202.41.254 table jyw
ip route add 10.202.0.0 dev em1 src 10.202.36.201
ip route add 10.202.0.0 dev em2 src 10.202.41.8
ip route add default via 10.202.41.254
ip rule add from 10.202.36.201 table cnc
ip rule add from 10.202.41.8 table jyw