There are two main ways to obtain an IP address for centos7, 1: dynamically obtain ip; 2: set a static IP address
Before configuring the network, we need to know what the name of the centos network card is. Centos7 no longer uses the ifconfig command, and can be viewed through the command IP addr. As shown in the figure, the network card is named ens32, and there is no IP address.
1、 Obtain ip dynamically (provided that your router has enabled DHCP)
Modify the network card configuration file vi /etc/sysconfig/network-scripts/ifcfg-ens32 (the last one is the network card name)
To obtain an IP address dynamically, you need to modify two places
(1)bootproto=dhcp
(2)onboot=yes
After modification, restart the network service to systemctl restart network
[ root@mini ~]# systemctl restart network
[ root@mini ~]#
In this way, the dynamic configuration IP address is set. At this time, check the ip addr and you can see that the IP address has been obtained and you can go online (ping Baidu)
2、 Configure static IP address
Setting a static IP address is similar to dynamic iIP, but also to modify the network card configuration file vi /etc/sysconfig/network-scripts/ifcfg-ens32 (the last one is the network card name)
(1)bootproto=static
(2)onboot=yes
(3) Add a few lines at the end, IP address, subnet mask, gateway, dns server
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) Restart the network service
[ root@mini ~]# systemctl restart network
[ root@mini ~]#
DNS server can only be equipped with one, I use two free dns servers, check the IP address, test the network
[ root@mini ~]# ip addr
1: lo:<LOOPBACK,UP,LOWER_UP> 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:<BROADCAST,MULTICAST,UP,LOWER_UP> 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 from163.177.151.109(163.177.151.109): icmp_seq=1 ttl=55 time=27.5 ms
64 bytes from163.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
Recommended Posts