配置外网 ip

[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 ~]#

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值