步骤
centos7的网络IP地址配置文件在 /etc/sysconfig/network-scripts 文件夹下,先查看网卡名称,命令:ifconfig
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.223.203 netmask 255.255.255.0 broadcast 192.168.223.255
inet6 fe80::f0e4:ad62:792e:23a0 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d0:f5:d0 txqueuelen 1000 (Ethernet)
RX packets 22943 bytes 1795752 (1.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 22916 bytes 2063442 (1.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
可以发现有个网卡名称为:ens33,然后进入/etc/sysconfig/network-scripts下,可以看到一个ifcfg-ens33文件。
[root@localhost network-scripts]# ls
ifcfg-ens33 ifdown-isdn ifdown-tunnel ifup-isdn ifup-Team
ifcfg-lo ifdown-post ifup ifup-plip ifup-TeamPort
ifdown ifdown-ppp ifup-aliases ifup-plusb ifup-tunnel
ifdown-bnep ifdown-routes ifup-bnep ifup-post ifup-wireless
ifdown-eth ifdown-sit ifup-eth ifup-ppp init.ipv6-global
ifdown-ippp ifdown-Team ifup-ippp ifup-routes network-functions
ifdown-ipv6 ifdown-TeamPort ifup-ipv6 ifup-sit network-functions-ipv6
直接编辑文件,命令:vim ifcfg-ens33,增加如下内容:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" #修改为静态
IPADDR="192.168.223.203" #新增
NETMASK="255.255.255.0" #新增
GATEWAY="192.168.223.1" #新增
DNS1="192.168.223.1" #新增
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="bf936e3c-0258-41ab-a8eb-57a760d9a164"
DEVICE="ens33"
ONBOOT="yes"
配置完成后,重启网卡,命令:service network restart