CentOS中网络配置相关文件配置选项说明
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>CentOS 修改IP地址等网络相关的配置文件</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
找到对应网卡的IP地址配置文件:ifcfg-eth数字.<br>
路径:/etc/sysconfig/network-scripts/ifcfg-eth数字<br>
文件内配置项说明</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode3" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0 <br>
BOOTPROTO=static #设置网卡获得ip地址的方式,选项有:static(静态),dhcp(通过DHCP获取IP)或bootp(使用BOOTP协议获得IP) <br>
BROADCAST=192.168.0.255 #子网广播地址 <br>
HWADDR=00:17:F3:05:18:20 #网卡物理地址(MAC) <br>
IPADDR=192.168.0.2 #BOOTPROTO=static时,使用此IP地址 <br>
IPV6INIT=no #初始化IPv6的功能 <br>
IPV6_AUTOCONF=no #是否自动化配置IPv6 <br>
NETMASK=255.255.255.0 #网卡对应的网络掩码 <br>
NETWORK=192.168.1.0 #网卡对应的网络地址 <br>
ONBOOT=yes #系统启动时是否启用此设备,yes时,系统启动时激活 <br>
#TYPE=Ethernet #网络类型 <br>
#USERCTL=no #非root用户是否可控制该设备</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
2014年03月18日补充更新:NETWORK这个参数在CentOS中不要设置,官方已经弃用,并且在设置之后可能会出现不能成功添加网关的问题</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
CentOS官方帮助:http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-networkscripts-interfaces.html</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
CentOS 网关配置相关的配置文件<br>
路径: /etc/sysconfig/network</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
文件内配置项说明</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode4" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
NETWORKING=yes # 表示系统是否使用网络,一般为yes。如果为no,则不使用网络,很多系统服务无法启动 <br>
#NETWORKING_IPV6=no #是否启用IPv6 <br>
#FORWARD_IPV4=no #是否开启IP转发功能 <br>
#HOSTNAME=localhost.localdomain #设置本机的主机名,设置的值要和/etc/hosts中设置的主机名对应;注释掉,一般先解析主机名或者域名,再解析DNS <br>
GATEWAY=192.168.1.1 #设置网关的IP地址 <br>
#GATEWAYDEV=gateway #网关设备名称</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
CentOS 官方帮助:http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-sysconfig-network.html<br>
<br>
CentOS DNS相关的的配置文件<br>
路径:/etc/resolv.conf</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
文件内配置项说明</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode5" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
#最重要的就是nameserver,其他可以忽略 <br>
nameserver 8.8.8.8 #google域名服务器 <br>
nameserver 8.8.4.4 #google域名服务器 <br>
#search mitchellchu.com www.mitchellchu.com #定义域名的搜索列表 <br>
#domain mitchellchu.com #定义本地域名 <br>
#sortlist #对返回的域名进行排序</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
网络设备重启<br>
service network restart<br>
或<br>
/etc/init.d/network restart</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
IP地址修改<br>
即时生效:<br>
ifconfig eth0 192.168.0.2 netmask 255.255.255.0<br>
重新启动网络设备后生效<br>
参见 /etc/sysconfig/network-scripts/ifcfg-eth数字 的修改</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
修改当前网关 Default Gateway<br>
即时生效:<br>
route add default gw 192.168.0.1 dev eth0<br>
重启网络设备后生效:<br>
参见:/etc/sysconfig/network的配置</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
修改DNS<br>
参见:/etc/resolv.conf配置<br>
修改后即时生效</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
修改主机名<br>
即时生效:<br>
hostname centos1<br>
重新启动生效:<br>
参见:/etc/sysconfig/network配置,注意这里还有/etc/hosts的配置</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
网络配置的CentOS官方帮助:http://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-networkscripts.html</p>
頁:
[1]