ubuntu网络配置Ubuntu-12.04-server版服务器
电信、联通双线接入
服务器环境如下:
操作系统:ubuntu-12.04-server
接入电信和联通的IP如下
电信(TEL)IP:  58.57.65.239;  子网掩码: 255.255.255.128; 网关:58.57.65.129
联通(CNC)IP:  61.133.41.239;  子网掩码: 255.255.255.192; 网关:61.133.41.193
操作步骤如下
1、 配置网卡信息
运行命令vi /etc/network/interfaces把里面的配置修改为如下
auto lo
iface lo inet loopback
auto eth0
      iface eth0 inet static
        address 61.133.41.239
        netmask 255.255.255.192
auto eth1
iface eth1 inet static
        address 58.57.65.239
        netmask 255.255.255.128
        gateway 58.57.65.129
保存配置信息并且得启网卡
/etc/init.d/networking restart
2、 增加电信tel和联通cnc的路由表
vi /etc/iproute2/rt_tables
里面已经显示了部分路由信息,在他的后面加上下面2句,保存退出(251、252可以是1-254之间任意数字,但不能与路由表已有的一样)
252 tel
251 cnc
3、 增加路由规则,运行下面6个命令,前3个是设置电信网关,让电信的数据从eth1网卡走,后3个是设置联通网关,让数据从eth0走
ip route flush table tel
ip route add default via 58.57.65.129 dev eth1 src 58.57.65.239 table tel
ip rule add from 58.57.65.239 table tel
ip route flush table cnc
ip route add default via 61.133.41.193 dev eth0 src 61.133.41.239 table cnc
  ip rule add from 61.133.41.239 table cnc
4、 运行命令vi /etc/init.d/networking配置脚本文件在exit 0前加入如下内容,其实就是刚才增加的路由规则。
ip route flush table tel
ip route add default via 58.57.65.129 dev eth1 src 58.57.65.239 table tel
ip rule add from 58.57.65.239 table tel
ip route flush table cnc
ip route add default via 61.133.41.193 dev eth0 src 61.133.41.239 table cnc
ip rule add from 61.133.41.239 table cnc
5、 重启网络运行/etc/init.d/networking restart
6、写入系统启动脚本运行命令vi /etc/rc.local,配置脚本文件在exit 0前加入如下内容(也就是添加步骤4的路由规则)
ip route flush table tel
ip route add default via 58.57.65.129 dev eth1 src 58.57.65.239 table tel
ip rule add from 58.57.65.239 table tel
ip route flush table cnc
ip route add default via 61.133.41.193 dev eth0 src 61.133.41.239 table cnc
ip rule add from 61.133.41.239 table cnc