hosts file "/ etc / hosts" --Correspondence between host name and IP address

The hosts file is a file that describes the correspondence between IP addresses and host names.

cat / etc / hosts

By default, the correspondence between localhost and the loopback address is written. IPv4 and IPv6.

127.0.0.1 localhost.localdomain localhost
:: 1 localhost6.localdomain6 localhost6

Automatic IP address resolution in applications that handle host names

The role of the hosts file is to allow applications that work with hostnames to resolve IP addresses automatically.

Use vi to edit the hosts file.

sudo vi / etc / hosts

For example, suppose an application that connects to a database describes the host to connect to the database.

In this case, the development environment and the production environment have different databases and different IP addresses. In such a case, you can write the host name in the application and have the hosts file resolve the IP address.

13.66.226.204 database

This is a sample using the host name in the mysql command. If you define the correspondence with the IP address in the development environment and the production environment, you can connect with the same description.

#Specified by IP address
mysql -h 13.66.226.204 -ukimoto -p

#Specified by host name
mysql -h database -ukimoto -p

Associated Information