Understanding '/etc/hosts' file: set up local domains for your projects
When you work on a local project that needs a domain to be used (to use SSL, for example) you can create fictional domains that redirect to your project’s local IP address.
These DNS resolutions only work on the machine where you configure them. You just need to edit
/etc/hosts (as root) and add a new line with the IP and a hostname.
[ip address] [hostname] [aliases]
$ cat /etc/hosts # Static table lookup for hostnames. # See hosts(5) for details. 127.0.0.1 localhost ::1 localhost 127.0.1.1 myarch.rs1 myarch
- The IP address can be IPv4 or IPv6. You can add a line for each IP protocol with the same hostname.
- Fields are separated by spaces or tabs.
- Comments start with a
- Hostnames must start with an alphabetic character and end with an alphanumeric character.
- You can also add one or more ‘alias’ after the hostname (separated by spaces or tabs) that also resolve to the specified IP.
$ nmap myarch.rs1 Starting Nmap 7.92 ( https://nmap.org ) at 2022-07-08 21:07 CEST Nmap scan report for myarch.rs1 (127.0.1.1) Host is up (0.00013s latency). $ nmap myarch Starting Nmap 7.92 ( https://nmap.org ) at 2022-07-08 21:09 CEST Nmap scan report for myarch (127.0.1.1) Host is up (0.00013s latency).
- Modifications of this file normally take effect immediately.
If you have any suggestion, feel free to contact me via social media or email.