当我们安装了一个虚拟机或者装了一个系统的时候,经常会遇到需要设置固定ip的情况,本文就以Centos 7为例,讲述如何修改固定IP地址。
1、用ifconfig命令查看使用的网卡

如上图所示,我们就会看到我们目前使用的网卡名称
2、编辑网卡地址文件
用vim打开网卡地址文件/etc/sysconfig/network-scripts/ifcfg-XXX,其中XXX就是上一步查询到的网卡名称,本例中就是ifcfg-ens33
shell
vim /etc/sysconfig/network-scripts/ifcfg-ens33
3、将BOOTPROTO的值改为static,并增加固定ip地址的信息,示例如下图:

为了方便复制,我将需要增加和修改的信息单独放在下面
shell
BOOTPROTO="static" #修改为static
IPADDR=192.168.86.129 #IP地址
GATEWAY=192.168.86.2 #网关
NETMASK=255.255.255.0 #子网掩码
DNS1=114.114.114.114 #DNS1
DNS2=8.8.8.8 #DNS2
用wq保存修改
4、重启网络
shell
service network restart

5、用ipconfig查看修改信息

6、验证修改结果
