虽然目前 BGP 线路已经很常见了,但单线、双线、三线的机房也还不少,给用户提供更多选择的同时,也可降低支出。
以 CentOS 为例
先增加两个路由表:
vi /etc/iproute2/rt_tables
163 ct (电信)
169 cu (联通)
然后设置路由表:
## 设置路由表
ip route replace default via <CT_GW> dev eth1(设定默认路由)
ip route flush table ct
ip route add default via <CT_GW> dev eth1 src <CT_IP> table ct
ip rule add from <CT_IP> table ct
ip route flush table cu
ip route add default via <CU_GW> dev eth0 src <CU_IP> table cu
ip rule add from <CU_IP> table cu
## 多线依此类推
仅双线时也可以简化为:
## 第二条线路可不设网关
ip route add default via <CU_GW> dev eth0 src <CU_IP> table cu
ip rule add from <CU_IP> lookup cu
ip rule add to <CU_IP> lookup cu