Centos设置静态IP及修改Centos配置文件的方法
<p><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>特别值得一提的是Centos设置IP有很多值得学习的地方,这里我们主要介绍Centos设置静态IP,包括介绍Centos配置文件,CentOS系统 TCP/IP网络配置、系统引导和启动、守护进程管理、系统监控和备份与恢复等内容。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>使用VirtualBox装了很多虚拟机,默认采用的DHCP的方式,但是随着虚拟机越来越多以后,这种方式很不方便,所以需要将机器的IP都Centos设置静态IP需要添加的几项内容的解释: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>IPADDRIP地址 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>NETMASK子网掩码 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>NETWORK网关地址 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>通常,如果我们想更改主机地址为静态地址或者更改主机名,需要修改的几个文件包括: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>/etc/sysconfig/network Centos设置主机名和网络配置 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>/etc/sysconfig/network-scripts/ifcfg-eth0针对特定的网卡进行设置 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>/etc/resolv.conf设置DNS </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>/etc/hosts设置指定的域名解析地址 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>一般我们只需要修改网卡的Centos配置文件就可以了,例如我的Centos配置文件如下: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>
</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";'>
<p class="right">
<span><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p class="msgborder" 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 <br>
BOOTPROTO=static <br>
TYPE=Ethernet <br>
NAME="System etho0" <br>
BROADCAST=192.168.56.255 <br>
HWADDR=08:00:27:24:F8:9B <br>
IPADDR=192.168.56.101 <br>
IPV6INIT=yes <br>
IPV6_AUTOCONF=yes <br>
NETMASK=255.255.255.0 <br>
NETWORK=192.168.56.1 <br>
ONBOOT=yes </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>Centos设置IP完成后,重启一下网卡就可以了:</span><font color="#ff0000" style='line-height: 25.2px; font-size: 14px; font-family: tahoma, arial, "Microsoft YaHei";'>service network restart</font><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'> </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>我们还有一个办法可以实现Centos设置静态IP,那就是通过 ifconfig 这个命令。通常,我们都用它来查看当前网卡的一些信息,同时,他也可以用来进行一些网卡信息的设置。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>修改的命令如下:</span><font color="#ff0000" style='line-height: 25.2px; font-size: 14px; font-family: tahoma, arial, "Microsoft YaHei";'>ifconfig eth0 192.168.56.102</font><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'> </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>但是,这个命令执行后,只能够在当前会话中修改网卡的地址,我们看一下 ifcfg-eth0 的配置文件,仍然是 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'># Advanced Micro Devices 79c970 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>DEVICE=eth0 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>ONBOOT=yes </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>BOOTPROTO=dhcp </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>HWADDR=08:00:27:43:73:2f </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>也就是说重新启动服务器后,仍然会按照Centos配置文件中的方式进行IP的获取。所以,如果需要修改IP为静态IP的话,最好的方式还是通过修改Centos配置文件来完成。</span></p>
頁:
[1]