How To Edit Hosts File In Mac OS And Linux

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.

  1. Click Launchpad icon in the docker.
    macos launchpad
  2. Input keyword terminal in the search box.
    search terminal in macos dock launchpad
  3. Open terminal and cd into the /private/etc directory.
  4. Run below command to edit hosts file in above/private/etc directory.
    $ vim hosts
  5. 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
  6. 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.

  1. Open a terminal and cd into /etc folder.
  2. In /etc folder, there is a hosts file and a resolv.conf file.
  3. We add local ip domain mapping data in hosts file, and the resolv.conf file is used to save domain name server ip settings.
  4. 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.
  5. Run $ vim hosts to edit the ip domain mappings in hosts file like in MacOS.
(Visited 24 times, 1 visits today)
READ :   How To Show Hidden Files In MacOS Finder

Leave a Reply

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.