link:
[ root@centos7 ~]$ hostnamectl set-hostname centos77.magedu.com #Using this command will take effect immediately and restart will also take effect
[ root@centos7 ~]$ hostname #Check it down
centos77.magedu.com
[ root@centos7 ~]$ vim /etc/hosts #Edit the hosts file and give 127.0.0.1 add hostname
[ root@centos7 ~]$ cat /etc/hosts #an examination
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 centos77.magedu.com
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
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.
image
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
image
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)
image
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
image
Recommended Posts