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 article How To Edit Hosts File In Windows 10, we have told you how to edit it 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 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 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! 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 /etc folder, there is a hosts file and a resolv.conf file.
- We add local ip domain mapping data in hosts file, and the resolv.conf file is used to save domain name server ip settings.
- When you request a domain in this Linux computer, it will first lookup the domain’s ip in hosts file, if this file do not contain the domain ip mappings, then it will send request to the domain name server which 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.