修改后重启一下网络服务即可 systemctl restart network
[root@mini ~]# systemctl restart network [root@mini ~]#
这样动态配置IP地址就设置好了,这个时候再查看一下ip addr 就可以看到已经获取了IP地址,且可以上网(ping 百度)
2、配置静态IP地址
设置静态IP地址与动态iIP差不多,也是要修改网卡配置文件 vi /etc/sysconfig/network-scripts/ifcfg-ens32 (最后一个为网卡名称)
(1)bootproto=static
(2)onboot=yes
(3)在最后加上几行,IP地址、子网掩码、网关、dns服务器
IPADDR=192.168.1.160 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=119.29.29.29 DNS2=8.8.8.8
(4)重启网络服务
[root@mini ~]# systemctl restart network [root@mini ~]#
DNS服务器可以只配一个,我用的是两个免费的dns服务器,查看IP地址,测试联网
[root@mini ~]# ip addr 1: lo:mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens32: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:d2:42:55 brd ff:ff:ff:ff:ff:ff inet 192.168.1.160/24 brd 192.168.1.255 scope global noprefixroute ens32 valid_lft forever preferred_lft forever inet6 fe80::f86e:939e:ff9b:9aec/64 scope link noprefixroute valid_lft forever preferred_lft forever [root@mini ~]# ping www.baidu.com PING www.a.shifen.com (163.177.151.109) 56(84) bytes of data. 64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=1 ttl=55 time=27.5 ms 64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=2 ttl=55 time=35.2 ms ^C --- www.a.shifen.com ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1008ms rtt min/avg/max/mdev = 27.570/31.425/35.281/3.859 ms
更多centos相关技术文章,请访问centos系统教程栏目!
以上就是centos7配置IP地址的两种方法详解的详细内容,更多请关注其它相关文章!