[root@centos-qmail ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HWADDR="00:13:21:1B:6B:51"
NM_CONTROLLED="yes"
ONBOOT="yes"
ONPROTO="static"
IPADDR="124.254.88.171"
NETMASK="255.255.255.240"
GATEWAY="124.254.88.161"
~
~
~
~
~
~
~
~
~
~
~
~
~
~
[root@centos-qmail ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
124.254.88.160 * 255.255.255.240 U 0 0 0 eth0
192.168.21.0 * 255.255.255.0 U 0 0 0 eth1
link-local * 255.255.0.0 U 1002 0 0 eth0
link-local * 255.255.0.0 U 1003 0 0 eth1
default 192.168.21.1 0.0.0.0 UG 0 0 0 eth1
[root@centos-qmail ~]# route add default netmask 0.0.0.0 gw 124.254.8.161
[root@centos-qmail ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
124.254.88.160 * 255.255.255.240 U 0 0 0 eth0
192.168.21.0 * 255.255.255.0 U 0 0 0 eth1
link-local * 255.255.0.0 U 1002 0 0 eth0
link-local * 255.255.0.0 U 1003 0 0 eth1
default 124.254.88.161 0.0.0.0 UG 0 0 0 eth0
default 192.168.21.1 0.0.0.0 UG 0 0 0 eth1
[root@centos-qmail ~]# route delete default netmask 0.0.0.0 gw 192.168.21.1
[root@centos-qmail ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
124.254.88.160 * 255.255.255.240 U 0 0 0 eth0
192.168.21.0 * 255.255.255.0 U 0 0 0 eth1
link-local * 255.255.0.0 U 1002 0 0 eth0
link-local * 255.255.0.0 U 1003 0 0 eth1
default 124.254.88.161 0.0.0.0 UG 0 0 0 eth0
[root@centos-qmail ~]#
----------------------
vi配置好外网ip后.查看一下路由的默认网关.如果默认是本地的话.外网就不能访问的.
需要设置成外网网关.
就可以 了.
像上面的配置,会在reboot后route值又还原成eth1的了.
所以,如果想永久话.得使用下面的方式来配置
[root@centos-qmail ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos-qmail
GATEWAY=124.254.88.161
GATEWAYDEV=eth0
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"/etc/sysconfig/network" 4L, 75C written
[root@centos-qmail ~]# reboot
Broadcast message from root@centos-qmail
(/dev/pts/1) at 18:31 ...
The system is going down for reboot NOW!
[root@centos-qmail ~]# Last login: Wed Oct 26 18:21:11 2011 from 192.168.21.156
[root@centos-qmail ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
124.254.88.160 * 255.255.255.240 U 0 0 0 eth0
192.168.21.0 * 255.255.255.0 U 0 0 0 eth1
link-local * 255.255.0.0 U 1002 0 0 eth0
link-local * 255.255.0.0 U 1003 0 0 eth1
default 124.254.88.161 0.0.0.0 UG 0 0 0 eth0
[root@centos-qmail ~]#