How To Edit Hosts File In Mac OS And Linux

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.

  1. My macOS version is OS X.
  2. Click the Launchpad icon in the docker.
  3. Input keyword terminal in the search box.
  4. Open terminal and cd into the /private/etc directory.
  5. Run below command to edit hosts file in above/private/etc directory.
    $ vim hosts
  6. Type esc , i key on the keyboard to insert below IP domain mappings in the hosts file.
  7. Type esc, :wq! key on the keyboard to save the file and exit vim. Then when you access domain, it will be resolved to IP

2. Edit Hosts File In Ubuntu Linux.

  1. Open a terminal and cd into /etc folder.
  2. In the /etc folder, there is a hosts file and a resolv.conf file.
  3. 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.
  4. When you request a domain on this Linux computer, it will first lookup the domain’s IP in the computer local hosts file,
  5. 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.
  6. Run $ vim hosts to edit the IP domain mappings in hosts file like in macOS.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.