Linux server hosts file configuration
The hosts file is a file in the Linux system that is responsible for the rapid resolution of IP addresses and domain names. It is saved in the "/etc" directory in ASCII format, and the file name is "hosts".
The hosts file contains the mapping between IP addresses and host names, as well as aliases for host names. In the absence of a domain name server, all network programs on the system resolve the IP address corresponding to a certain host name by querying the file, otherwise, you need to use the DNS service program to resolve. You can usually add commonly used domain names and IP address mappings to the hosts file to achieve quick and convenient access.
Below we introduce the methods and steps to modify the hosts configuration file:
Tools needed: vim/vi/emacs
Enter vim to see if there is vim in centos, recommend vim emacs
If not, install vim
sudo apt install vim -y # debian
sudo yum install vim -y # readhat
//Note that there is no installation if you already have vim in the system, you don't need to install it
Use the editor to modify the hosts file
1. Note that if you are already a root account, you don't need sudo
sudo vim /etc/hosts
2. Press the i key to enter the edit mode
The format of the hosts file is as follows:
IP address hostname/domain name
The first part: network IP address;
The second part: host name or domain name;
The third part: hostname alias;
127.0.0.1 localhost.localdomain localhost
192.168.1.100 linmu100.com linmu100
192.168.1.120 ftpserver ftp120
3. Enter the command: :wq save and exit
4. Enter the command: cat /etc/hosts to see if the content of the modified hosts file is modified successfully
Effective command:
cd /etc/init.d/network
restart