方法一
内网IP为:192.168.4.213,内网网关:192.168.4.1
外网IP为:58.200.200.15 子网掩码为:255.255.255.128 网关为:58.200.200.1
1.当配置服务器为外网IP和内网IP的方式时,只设置外网IP的网关,不要设置内网IP的网关.
操作如下:
vi /etc/network/interfaces
修改里面的内容如下
auto eth0
iface eth0 inet static
address 192.168.4.213
netmask 255.255.255.0
auto eth1
iface eth1 inet static
address 58.200.200.15
netmask 255.255.255.128
gateway 58.200.200.1
注意: 我们没有为 eth0(内部网络) 设置 gateway,保存退出
2.重启网卡,Ubuntu 重启网卡的命令是:
/etc/init.d/networking restart
3.手动设置服务器的路由
route add -net 192.168.4.0/24 gw 192.168.4.1 dev eth0
注意:手动添加的路由,服务器重启后不生效
方法二
vi /etc/network/interfaces
修改内容如下
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 211.x.x.x
netmask 255.255.255.x
gateway 211.x.x.x
dns-nameservers 114.114.114.114 119.29.29.29
auto eth1
iface eth1 inet static
address 10.16.16.15
netmask 255.255.255.0
up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.16.16.254 eth1
**
只能设置一个网关,另一个网关用路由,指定网关ip和网络接口
**