1、编辑 ifcfg-eth0 文件,vim 最小化安装时没有被安装,需要自行安装不描述。
2、修改如下内容
BOOTPROTO="static" #dhcp改为static
ONBOOT="yes" #开机启用本配置
IPADDR=192.168.197.131#静态IP
GATEWAY=192.168.197.2#默认网关
NETMASK=255.255.255.0#子网掩码
DNS1=192.168.197.2#DNS 配置
3、修改后效果
[root@root123 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
HWADDR="00:15:5D:07:F1:02"
TYPE="Ethernet"
BOOTPROTO="static" #dhcp改为static
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="eth0"
UUID="bb3a302d-dc46-461a-881e-d46cafd0eb71"
ONBOOT="yes" #开机启用本配置
IPADDR=192.168.197.131#静态IP
GATEWAY=192.168.197.2#默认网关
NETMASK=255.255.255.0#子网掩码
DNS1=192.168.197.2#DNS 配置
4、重启下网络服务
[root@root123 ~]# service network restart
5、查看改动后的效果,Centois 7 不再使用 ifconfig 而是用 ip 命令查看网络信息。
[root@root123 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UNKNOWN qlen
link/ether :0c::b3:a8:5e brd ff:ff:ff:ff:ff:ff
inet 192.168.197.131/ brd 192.168.197.255 scope global eth0
inet 192.168.197.129/ brd 192.168.197.255 scope global secondary eth0
inet6 fe80::20c:29ff:feb3:a85e/ scope link
valid_lft forever preferred_lft forever