If you are having DNS issues, you can force your local machine to ignore public DNS and access a site IP directly. Why this may be a more advanced process, as you will need administrative rights to edit this file, it can be a useful tool when testing or troubleshooting your website.


Sections


What is the "hosts file"?

Your first question is "What is a hosts file?" Fair enough. In short, the hosts file for your operating system is used to override the public DNS for a website or domain.

Without getting too much into the weeds, when you look up a website on your browser, the browser requests the location (IP) of the target domain from the DNS server. Which DNS server it uses depends on several factors that are not important in this context. If you domain DNS is not correct, or you are in to process of updating you DNS, you site may not be reachable.

When you add a website to your hosts file, the browser will bypass the DNS lookup for the domain and go directly to the IP address listed in the hosts file. This can also be helpful if you are building a new website for your domain on a different server, but don't want to affect your current website. You can update the hosts file on the device you are using to build the site, while leaving the DNS pointing to the existing site.

There may be other cases where editing your hosts file can be helpful other then these cases.

Back to Menu


How do you edit your "hosts file"?

Your hosts file, like many config files, is written in simple text.

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost 
fe80::1%lo0 localhost

Any text editor can be used to edit the file. However, this file is protected by the operating system. Because of this, you will need administrator rights to update the file. How you achieve this depends on which operating system you are using.

You can also use your terminal on Mac and Linux machines, or PowerShell on Windows.

When adding domains to your hosts file, you only need to add the IP address, followed by the domain name. You can add a note to the line as well by preceding the note with a hashtag.

196.168.0.49 example.com #This is a note

Be sure to only add one domain per line.

Back to Menu


Editing your "hosts file" on Mac

The easiest method of modifying your hosts file on a Mac is using your terminal. You can edit it using your text editor, but because the file is write protected, you have to use a work-around.

Using the terminal

To edit your hosts file in the terminal, do the following:

  1. Open your Terminal app. You can find it under Applications in Finder. You can search using Spotlight or the Launchpad.
  2. Open the hosts file using Sudo. sudo nano /etc/hosts This will open nano (a text editor) with administrator rights.
  3. Enter your admin password.

You will now be able to edit the hosts file. Add your domains and IPs as needed and save your changes by entering the following commands:

  1. Control + O to Overwrite the file
  2. Control + X to close the app

Using a text editor

As mentioned above, your hosts file is a protected system file, so you cannot just edit it as you would any other normal text file. However, if you make a copy of the hosts file somewhere else on your machine, edit the new file, and then copy it to the original folder, it should overwrite the existing file.

Back to Menu


Editing your "hosts file" on Windows

With Windows, while you can alter your hosts file in PowerShell, this requires that you install a PowerShell text editor, as it does not have one installed by default. For this reason, it is easier to edit the file using a text editor app, such as the built in Notepad app.

Using Notepad

In order to edit your hosts file in Notepad, you must run the app as an administrator. This is due to the hosts file being a protected file. The easiest way to do this is using Windows search.

  1. Click the Windows key on your keyboard. This will open a search box.
  2. Now, type the name of the app (Notepad).
  3. You will see the results in the upper left of your screen.
  4. When you hover over the Notepad app, you will see a menu to the right.
  5. Click on "Run as administrator" to start the app with admin privileges.

One the Notepad app is open, you will need to now find and open the hosts file.

  1. Click on "File" in the menu bar.
  2. Go to "Open"
  3. Navigate to your hosts file. The default path is C:\Windows\system32\drivers\etc\
  4. Open the file.

You can now edit your hosts file as needed. Just be sure to save the file once you are finished.

Editing your hosts file in PowerShell

To edit your hosts file in PowerShell, you will first need to install a text editor for PowerShell. Luckily, you can easily install nano. You will need to run PowerShell as an administrator to both install nano, and edit the hosts file.

Run PowerShell as administrator

The process for this is identical as the method described above.

  1. Click the Windows key on your keyboard. This will open a search box.
  2. Now, type the name of the app (Powershell).
  3. You will see the results in the upper left of your screen.
  4. When you hover over the Notepad app, you will see a menu to the right.
  5. Click on "Run as administrator" to start the app with admin privileges.

Install Nano in PowerShell

Once you have PowerShell open as an administrator, you can install nano. Nano is a lightweight text editor that is used in most Mac and Linux systems. It can be installed using winget using this command winget install GNU.Nano. Once the installation completes, you will need to close PowerShell and reopen it as administrator an explained above.

Editing the hosts file

Now that you have your PowerShell open as administrator with nano installed, you can open and edit your host file by using this command:

nano C:\Windows\System32\drivers\etc\hosts

Edit your file and remember to save the file once completed using the following commands:

  1. Control + O to Overwrite the file
  2. Control + X to close the app

Back to Menu


Editing your "hosts file" on Linux

If you are a Linux user, then you probably comfortable using the terminal. This is the easiest way to edit your hosts file in Linux. The process for this is identical to the Mac method.

  1. Open your terminal
  2. Using sudo, open your hosts file sudo nano /etc/hosts.
  3. Enter your administrator password.

You can now edit your hosts file as necessary. Just remember to save your changes using the following commands:

  1. Control + O to Overwrite the file
  2. Control + X to close the app

Back to Menu


Still Having Issues?

If you are still having issues, you can contact our Customer Support in the following methods:

Live Chat

You can connect to our Live Chat Support Team from your MacHighway Client Area. If you are not sure how to do this, you can find a guide here.

Our Live Chat team is available Monday to Friday from 9:00 AM to 7:00 PM Eastern Time.

Support Ticket

You can submit a support ticket to our Support Team from your client area.

Our ticket Support Team is available 24/7/365.

Phone support

You can contact our Phone Support Team using the following number:

  • US/Canada 1-888-974-0334
  • International 1-727-800-3606

Our Phone Support team is available Monday to Friday from 9:00 AM to 7:00 PM Eastern Time.

Was this answer helpful? 0 Users Found This Useful (0 Votes)