The hosts file is used to store IP domain mappings configuration in your local computer, it acts like a domain name server running on your computer locally. In the article How To Edit Hosts File In Windows 10, we have told you how to edit the hosts file in windows. This article will tell you how to edit it in macOS and Linux.
1. Edit Hosts File In macOS.
- My macOS version is OS X.
- Click the Launchpad icon in the docker.
- Input keyword terminal in the search box.
- Open terminal and cd into the /private/etc directory.
- Run below command to edit hosts file in above/private/etc directory.
$ vim hosts
- Type esc , i key on the keyboard to insert below IP domain mappings in the hosts file.
127.0.0.1 test.com 127.0.0.1 smtp.test.com 127.0.0.1 pop3.test.com
- Type esc, :wq! key on the keyboard to save the file and exit vim. Then when you access domain test.com, it will be resolved to IP 127.0.0.1.
2. Edit Hosts File In Ubuntu Linux.
- Open a terminal and cd into /etc folder.
- In the /etc folder, there is a hosts file and a resolv.conf file.
- We add local IP domain mapping data in the hosts file and the resolv.conf file is used to save domain name server IP settings.
- When you request a domain on this Linux computer, it will first lookup the domain’s IP in the computer local hosts file,
- If this file does not contain the domain IP mappings, then it will send the request to the domain name server which is saved in the resolv.conf file to resolve the domain’s IP address.
- Run $ vim hosts to edit the IP domain mappings in hosts file like in macOS.