How to modify hosts file on Windows, Linux and Mac ?
How to edit the hosts file in Windows 8, 10 and 11?
Editing the hosts files on all Windows versions is essentially the same – you have to edit the hosts files with Notepad. The only difference is that from Windows 7 onwards, you must run Notepad as an administrator, whereas in older versions (Windows XP and earlier) this is not mandatory.
However regardless of the Windows version, the default Windows host file location is identical, unless you installed the OS in a different partition:
C:\Windows\System32\drivers\etc\hosts
-
Step 1: Open Notepad from Windows Menu
In this guide, we’ll edit the hosts file on Windows 10. To begin with, click on the Windows icon (Start menu).
Start typing Notepad, which automatically enables the search function. The first result will be Notepad. Right-click on the icon and select Run as administrator.
-
Step 2: Open the hosts file in Notepad
From Notepad’s window, click on the File menu and select Open, which will open a file selector box.
Make sure to select All Files otherwise the hosts file won’t show in the dialogue box as it is a hidden file and doesn’t have a .txt extension. Navigate to the hosts file path, select the file, and press Open.
-
Step 3: Edit the hosts file
The Windows 10 hosts file is pretty much the same as on any other operating system. It contains a few lines defining the address for the local host and other services, although it should be noted that they are commented with the “#” symbol. This means that they are not enabled but only left as examples.
To add your custom hostname’s settings, write a new line at the bottom of the file, omitting the “#” symbol.
The new entry should be in the following format:
IP_address yourdomain.com www.yourdomain.comReplace “IP_address” with the actual website’s IP and “yourdomain.com” with the domain you are mapping to the IP.
In our case, we are connecting the non-existing domain my-new-website.com to the IP address 35.214.215.226, therefore the line will read:
35.214.215.226 my-new-website.com www.my-new-website.com
To keep the new changes, save the file with the keyboard shortcut Ctrl + S, or from File menu > Save.
How to edit the host file on any macOS version
-
Step 1: Open Terminal in macOS
You need to use the Terminal application to edit the Mac hosts file. To open it, navigate to Finder > Go > Utilities.
Open the Utilities menu where the tools for Mac can be accessed. Find the Terminal icon and double-click on it.
Alternatively, you can quickly open Terminal by bringing up the Spotlight Search bar with the keyboard shortcut Command + Space. In the pop-up window, type Terminal and press Enter.
-
Step 2: Open the hosts file in Terminal
Once the Terminal window is open, you can edit the hosts file with one of the available text editors.
First, make sure you are located in your Mac’s top-level folder by typing the command:
cd /Press Enter to confirm the command, which will bring you to your Macintosh HD main folder.
The hosts file’s location on Mac computers is:
/private/etc/hostsIn our example, we are using the Nano text editor. To be able to modify the hosts file, you need to have administrator privileges (sudo). The command to open the file is:
sudo nano /private/etc/hosts
Once you’ve confirmed the command with Enter, you will be asked to provide the administrator password. Type in the password and confirm with Enter.
-
Step 3: Edit the hosts file in Terminal
This is where you can add your custom hostname settings. By default, the file only contains a few lines defining the address for localhost and broadcasthost.
With the arrow keys, move the cursor under the last line where you can add a new entry. To point a domain to a specific server use the following format:
IP_address yourdomain.com www.yourdomain.comYou must replace IP_address with the website’s IP and yourdomain.com with the actual domain name.
In our example, we want to use the non-existing domain my-new-website.com, which is not registered and doesn’t have active DNS settings.
The website for my-new-website.com is hosted on the IP address 35.214.215.226.
So, to force a computer to open this domain from that IP address, you should add the following line in the hosts file:
35.214.215.226 my-new-website.com www.my-new-website.com
After you’ve finished adding the new settings, press the combination Control + O (WriteOut) to confirm them and then hit Enter. Finally, you can press Control + X to exit the Nano editor.
Edit the Linux host file
-
Step 1: Open Terminal in Linux
Just like in macOS, you can edit the hosts file on a Linux operating system from the Terminal application. To open the menu with all applications, navigate to the respective button in the bottom left corner. Depending on the Linux version, the tool may be located on the main page or in the Utilites section. Select the Terminal icon to open the application.
-
Step 2: Open the hosts file in Terminal
Once inside the Terminal console, make sure you are in the top-level folder by typing the command:
cd /The path to the hosts file on Linux is:
/etc/hostsEditing the file requires administrative privileges (sudo) and a text editor such as Nano. Use the following command to open and edit the file:
sudo nano /etc/hosts
The system will prompt you to provide the administrator’s password before opening the file. After you type the password, press Enter.
-
Step 3: Edit the hosts file in Terminal
With the arrow keys, place the text cursor under the last written line and add the hostname settings. In our case, we are adding an address with the hostname my-new-website.com. Therefore, the line should read:
35.214.215.226 my-new-website.com www.my-new-website.com
To confirm the new changes, press the key combination Control + O and press Enter. You can then exit the editor by pressing Control + X.
