maps domain names to IP addresses
It is located in
/etc/hosts
It is on Linux and macOS systems
You can specify IPv6 addresses instead of IPv4 in the /etc/hosts file. The file is designed to handle both types of IP addresses
ipv4 is an IP that is numbers separated by periods (.) like 3.4.9.8 ipv6 is an IP that is numbers separated by 2 periods (:) like af:12:h5:5d
The /etc/hosts file always has the highest priority over any external DNS servers.
- The operating system always consults this file first (/etc/hosts)
- If the name is not found in /etc/hosts, the system checks its local DNS cache
- If the IP address is not found in the local cache, the system sends a request to the DNS servers configured on your network (those of your Internet Service Provider, Google DNS, Cloudflare, etc.) to obtain the correct IP address.
Changes are applied almost instantly on most systems, as the /etc/hosts file is read directly and does not require restarting services such as DNS.
I want to rename xxxx (ip) to alias locally on my machine using the /etc/hosts file, this only affects your machine, not the global network.
The /etc/hosts file is a table of IP addresses that your system consults before querying DNS (Domain Name System) servers on the Internet. It acts like a high-priority local phone book.
By adding an entry to this file, you are telling your computer: “Whenever someone asks me to go to ‘alias’, go directly to the IP of xxxx, without asking anyone else.”
To do this, you need xxxx’s IP address and administrator permissions (sudo) to edit the file.
Doesn’t use DNS: The /etc/hosts file is at the lowest level of the name resolution hierarchy. Your operating system (Linux, macOS, etc.) reads this file every time an application requests to resolve a name. It doesn’t rely on any external caching or DNS services that need to be restarted.
Although the operating system reads the file instantly, some applications (especially web browsers) maintain their own internal DNS cache to improve speed.
To know the IP of a domain, you have the command
ping
that is to say:
ping domain
that returns the IP in IPV4 or IPV6 version
The hosts file needs the IP, not a domain.
below images:
change the IP of “xxxx” to “alias”



the curl test with the IP:


other utility:
- You can block ads or malicious websites by mapping them to your own machine’s loopback address (127.0.0.1).