How to - Edit your Hosts File

If you are a Web Developer you know that Cloudflare's Cache can be very annoying. Did you know your can modify your hosts file so that you can bypass networks such as Cloudflare, Fastly or Akamai? This is helpful if you wish to bypass some DNS settings such as bypassing Cloudflare to work directly on your webserver or website. Another thing you can do is give static IP's to devices on your network that never change, such as routers, switches, printers and NAS (network attached storage) devices. By adding the devices into your hosts file your computer will always be able to find them. Modifying your hosts file enables you to override the domain name system (DNS) for a domain on a specific machine.



The "hosts" file is generally located in the following areas on your Computer

  • Windows 11 / 10 / 8 - c:\Windows\System32\Drivers\etc\hosts
  • or %Windows%\System32\Drivers\etc\hosts
  • UNIX / Linux OS's - /etc/hosts
  • MacOS - /etc/hosts or /private/etc/hosts


The hosts file contains lines of text with two columns. In the first column there is an IP address. And in the second column, there is a computer hostname. The two columns can be separated by a space or tab. So, an example hosts file might look like this:

Hosts file example

192.168.0.1  gatewayrouter
192.168.0.10 swtich01
192.168.0.11 nas1
192.168.0.12 nas2
192.168.0.20 printer01
192.168.0.21 printer02
111.111.111.111 webserver.mycompany.com

Edit your Hosts file on Windows 11, 10 and Windows 8

Use the following instructions if you’re running Windows 10 or Windows 8:

  1. Press the Windows key.

  2. Type Notepad in the search field.

  3. In the search results, right-click Notepad and select Run as administrator.

  4. From Notepad, open the following file:

  5. c:\Windows\System32\Drivers\etc\hosts

  6. Make the necessary changes to the file.

  7. Select File > Save to save your changes.

Edit your Hosts File on Linux / UNIX

  1. Open a Terminal window.
  2. Enter the following command to open the hosts file in a text editor:
    sudo nano /etc/hosts
    
  3. Enter your sudo user password.
  4. Make the necessary changes to the file.
  5. Press Control-X.
  6. When you are asked if you want to save your changes, enter y.

Edit Hosts file on MacOS

  1. Open the Terminal application.
  2. Open the hosts file for editing. In the terminal window you just opened copy/paste the command string below, and press return.
    sudo nano /private/etc/hosts

    or on the newer MacOS

    sudo nano /etc/hosts
  3. Enter your password when it prompts you to enter your Mac user’s password.
  4. Edit the hosts file as described above.

Summary

Editing your hosts file can save you time and a lot of grief. Having proper host file settings will solve your DNS issues if your DNS servers go off line. As well it can help you to bypass CDN (Content Delivery Networks) Networks such as Cloudflare, Fastly or Akamai.

Ron Billings

Clustered Networks

Located in Edmonton, AB Canada, Clustered Networks was Incorporated in 2001 and has offered Network / Internet and IT Consulting services for over 20 years. We offer personalized service! Call Us Today! - Click Here for our Contact Info

#linux #windows10 #hosts

Posted in Linux Desktop Tips, Linux Network Admin Tips, Network Security Tips, Tech How To on Oct 06, 2021