How to Edit Hosts File on Windows, Mac, or Linux

how to edit hosts file in windows, mac, linux

HOSTS file were used to resolve hosts names before DNS. They have been in use since ARPANET. Microsoft kept hosts’ files alive in Windows networking, which is why there is very little variation whether used in Windows, macOS or Linux. The syntax is mostly the same across all platforms. Today in this article we will learn how to edit your Hosts File on Windows, Mac, or Linux, which is often we try to do but before getting know how to use or edit the hosts file, let’s know first what is hosts file.

What Is Hosts File

Whenever you want to open any website on your computer using the Internet, you type the URL or address of the website, which is also known as the domain name, such as

Whenever you type any domain name in the browser, it searches the IP address set for it such as 192.1xx.x.x, instead of communicating with the domain name. So whenever you type the domain name, it first converts to IP address and then opens on the internet.

The process of converting the domain name (hostnames) to IP address is called Domain Name Resolution. Although DNS is the advanced and most used way but there is another way too, to resolve the domain name, in which the Domain Name System (DNS) is not used and that is the “HOSTS File”.

Almost all the operating systems that communicate with TCP / IP keep the hosts file. This file is used to create mappings between domain names and IP addresses. HOSTS file is a text file that saves the entry of IP address and domain name. In this file, first its IP address and then after one space, its domain name comes in the same line. A lot of entries can be done in a hosts file.

How to Edit Hosts File on Windows, Mac, or Linux

How to Edit Hosts File on Windows

So there are two different ways to edit hosts file on windows first for windows 7 & windows vista and second for windows 8, 8.1, and 10.

Edit hosts file in Windows 7

  • Turn on your windows 7 or windows vista PC and hit the Start button.
  • Now open the run command and type the following command

notepad c:\windows\system32\drivers\etc\hosts

  • It will open the hosts file on your PC.
  • Now make the necessary changes to the file and then select the “File” option and save the file.

Edit HOSTS file in Windows 8, 8.1 and 10

  • Turn on your Windows 8, 8.1, and 10 pc and hit the windows button from your keyboard.
  • Now in the search bar type Notepad.
  • Once you get “Notepad” in search results, instead of opening it directly, right-click Notepad and select Run as administrator.
  • Now it will ask for permission, so allow Notepad to run as administrator.
  • After that from Notepad, open the following file:


  • It will open the hosts file, now do the changes you want to do and then save the file.

How To Edit HOSTS file in macOS

  • Turn on you macOS PC and open a Finder window.
  • Now select Applications option from the sidebar and then double click on Utilities.
  • Double click on the terminal which will open a terminal window.
  • In the terminal window type the following command and then hit return.

sudo nano /private/etc/hosts

  • After that, it will ask for your administrator password so enter the password and then hit return.
  • So now you’re in the Nano text editor. If you want to add a new device or domain, move the cursor using the arrow keys and type after the text in the window, and after that hold the control and O keys to save the file, then control and X to exit.

How to Edit HOSTS file in Linux

  • Turn on your Linux system and open up the terminal.
  • Now Use the nano command line text editor to open the hosts file, which is

sudo nano /etc/hosts

  • Now it will ask for Linux user’s password so enter your password.
  • So now If you want to make any changes, do it. And then hold the control and O keys to save the file, then control and X to exit.

Read Also: How To Combine PDF File Online For Free

So that’s how you can edit hosts file on Windows, Mac, or Linux. Hopefully, now you may have understood the whole process but still, if you have any questions regarding how to edit hosts file on Windows, Mac, or Linux system, you can ask us in the comments section.


Please enter your comment!
Please enter your name here