服务器双网卡配置不一样运营商IP的方案

有一台网关服务器,须要配置电信联通两条线路,以保证电信和联通用户的访问速度bash

  • 配置IP,配置默认路由到其中一个运营商,如联通。另一条电信线路不配网关。
  • 把规则和数字的对应规则添加rt_tables文件
echo 201 telnet-line >> /etc/iproute2/rt_tables
  • 添加路由及网关信息到相应规则
ip route add 222.171.246.0/24 dev eth0 src 222.171.246.150 table telecom-line 
ip route add default via 222.171.246.254 dev eth0 table telecom-line
ip rule add from 222.171.246.150 table telecom-line
ip rule add to 222.171.246.150 table telecom-line

至此所有配置以完成,访问电信IP的用户会自动从电信线路返回。其他的都会从联通线路返回。服务器

测试没有问题咱们能够把以上IP加入启动脚本里/etc/rc.local测试

# routing policy for telecom line
ip route add 222.171.246.0/27 dev eth0 src 222.171.246.150 table telecom-line
ip route add default via 222.171.246.254 dev eth0 table telecom-line
ip rule add from 222.171.246.150 table telecom-line
ip rule add to 222.171.246.250 table telecom-line
相关文章
相关标签/搜索