服務器雙網卡配置不一樣運營商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
相關文章
相關標籤/搜索