Centos7 configuration host name and IP address

link:

Configure the host name##

[ 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

Configure IP address##

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

Centos7 configuration host name and IP address
CentOS7.2 and Nginx configuration virtual host
Centos7 configure IP address
Centos: add an IP address
Centos mysql installation and configuration
Centos7 installation and configuration prometheus
CentOS installation and configuration cmake
Centos7 installation and configuration of Jenkins
CentOS 8 install Git and basic configuration
Centos7 hadoop cluster installation and configuration
ubuntu modify and configure ip address
Java-JDK installation and configuration under CentOS
CentOS 7 Tomcat service installation and configuration
Centos 7 RAID 5 detailed explanation and configuration
CentOS NTP server installation and configuration
Centos7 mysql database installation and configuration
Tomcat installation and configuration under CentOS 7 (Tomcat startup)
MySQL 8.0 installation, deployment and configuration under CentOS 6/7
CentOS7 modify network card name and network repair
Installation and configuration of redis under centos7
Centos7 hive stand-alone mode installation and configuration
IP address problem after restarting CentOS 7 system
Installation and configuration of JDK in CentOS 7 system
CentOS7.0 network configuration
CentOS 7.0 network configuration
CentOS 6.5 system installation and configuration graphic tutorial (detailed graphic)
CentOS7 and Docker configuration Chinese character set problem
CentOS 7 installation and configuration graphic tutorials under VMware10
Centos7.6 dual network card configuration and switching test
Install svn and configuration through yum under CentOS
Installation and configuration of rsync server under CentOS 6.5
Installation and configuration of CentOS 7 in VMware Workstation
Explain the implementation of Centos8 static IP configuration
Installing CentOS 6 and SSH configuration under Windows 8 Hyper-V
IP and network settings of CentOS Linux 7 VMware
MySQL 8.0 installation, deployment and configuration tutorial on CentOS 8
The virtual machine centos and the host ping each other
Tencent cloud centos 8.0 single network card configuration multiple IP
Linux firewall related configuration commands and operations (centos and ubuntu)
Install centos7 and connect
Vmware-install and start Centos 8
Xfs configuration on centos7
Vmware-install and start Centos 7
Centos kernel compilation configuration
Ubuntu18.04, Centos7 static IP
Python3 configuration and entry.md
Detailed explanation of Spark installation and configuration tutorial under centOS7