How do I edit my computer’s hosts file?

The hosts file is a text file that maps hostnames to IP addresses. This file is used by your computer's operating system to resolve hostnames to IP addresses. By editing the hosts file, you can point a hostname to a specific IP address. This can be useful for a variety of purposes, such as:

  • Testing a website before it goes live to the public
  • Bypass DNS issues
  • Redirecting traffic to a different server

Here are the steps on how to edit the hosts file on different operating systems. Always take a backup copy of any key files like this before you edit them and bear in mind that mistakes in this file can stop your computer being able to access things on the local network or the internet.

Windows 10 and 11

  1. Open Notepad as an administrator. You can do this by right-clicking on Notepad and selecting Run as administrator.
  2. In Notepad, navigate to the following file path:
C:\Windows\System32\drivers\etc\hosts
  1. Add the following line to the end of the file, replacing `192.168.1.100` with the IP address of the server you want to connect to, and `example.com` with the hostname you want to map to that IP address:
192.168.1.100 example.com
  1. If this is for a website, consider adding a second line for www.example.com with the same IP address, so that the change will take effect whether or not you include www. in the address you visit.
  2. Save the file.

macOS

  1. Open Terminal.
  2. Type the following command and press Enter:
sudo nano /etc/hosts
  1. Add the following line to the end of the file, replacing `192.168.1.100` with the IP address of the server you want to connect to, and `example.com` with the hostname you want to map to that IP address:
192.168.1.100 example.com
  1. If this is for a website, consider adding a second line for www.example.com with the same IP address, so that the change will take effect whether or not you include www. in the address you visit.
  2. Press `Ctrl`+`X` to exit nano.
  3. When prompted, save the file.

Linux

  1. Open a terminal.
  2. Type the following command and press Enter:
sudo vi /etc/hosts
  1. Add the following line to the end of the file, replacing `192.168.1.100` with the IP address of the server you want to connect to, and `example.com` with the hostname you want to map to that IP address:
192.168.1.100 example.com
  1. If this is for a website, consider adding a second line for www.example.com with the same IP address, so that the change will take effect whether or not you include www. in the address you visit.
  2. Press `:` to exit vi.
  3. When prompted, save the file.

**On Windows-based systems, after editing the hosts file, you may need to flush your DNS cache. To do this, open a command prompt and type the following command:**

ipconfig /flushdns

**Once you have flushed your DNS cache, you should be able to access the website or server you mapped to the specific IP address.**

Was this answer helpful?

0 Users Found This Useful