Steps to Edit Hosts File in Windows, Mac and Linux Ubuntu

How to Edit Hosts File in Windows, Mac and Linux Ubuntu

DNS servers use host files to convert domains to IP addresses, to simplify accessing websites, or to handle an attack. Certainly, you will need to Edit Hosts File on your current operating system in use. Join us with this article to learn How and Why to Edit Hosts File in Windows, Mac, and Linux Ubuntu. Regardless of using any operating system, this content would be useful after buy VPS.So, you will be able to use the host file of your system as a domain name.

First, let’s learn more about the host file, its location, and why you must know how to edit it on the required occasions, and then go learn the way you can edit hosts file on your considered operating system.

What is a Windows Host File and How it Works?

The host file is an almost 824-byte local plain-text file that is located deep down in the Windows folder. A host file translates domain names into an IP address and can be used to skip using the DNS server and block a website as a method to Block a Website for a User in Windows, Mac, or Chrome. The host file functions as though each Windows user has their own personal Domain Name System.

The DNS settings for the websites listed in the host file on that computer are overridden. The host file is the first place the computer searches to resolve a name when seeking an IP address. The lookup fails if the name is not found in the local host file or while trying to resolve it via a DNS.

Why to Edit Hosts File?

For a variety of reasons, you might need to update your computer’s host file to correctly resolve a website by its domain name. The most frequent justification for doing this is to enable users to read or create web content right away after buying a new domain name or switching an existing domain name to another ISP (Internet Service Provider). By changing your Hosts file, malware can redirect Web addresses on your computer. The Host File Hijack is the name for this. You can navigate to the host file, right-click on it, choose Properties, and set it to ”read-only” to stop host file hijacking. By doing this, you can lock down your Hosts file and stop malware or other users from writing to it.

You may edit hosts file on your computer as a temporary workaround if you must update your website right away and cannot wait for the internet to propagate the domain information. This workaround only applies to the PC or server where the modification was done. The website won’t be accessible to anyone online as a result. Also, if your DNS server is not functioning properly even after Configuring DNS Server in Windows, edit hosts file comes in handy. You can add the IP address and domain name to the hosts file to speed up the search process if your DNS server is operating slowly.

You generally won’t need to change your Windows hosts file very often. However, being aware of its location and functioning can be useful. So, stay with us on this guide to review all the required steps to Edit Hosts File in Windows, Mac, and Linux Ubuntu.

Tutorial Edit Hosts File in Windows

So far, you learned all about hosts file and the reasons you should know how to edit hosts file on your current operating system. All operating systems have hosts files, although they are located in different places. On Windows, the hosts file is located in “C:\Windows\System32\drivers\etc\hosts“. This part covers the way you can edit hosts file in Windows 7, 8, 10, and 11.

Edit Hosts File on Windows 10 & 11

The hosts file is still present in Windows 10 and Windows 11. So, after buying Windows VPS, you are ready to follow the below steps to learn the quickest way to edit hosts file on Windows 10 & 11. Since the hosts file is protected, much like the other files in the Windows folder, to move, edit, or delete the file, you must have administrator privileges.

  • We must first create a backup. If something goes wrong, you can use this to return to a previous state. To do this, launch File Explorer and go to the following location:

Right-click on the hosts file and then select Copy and paste the file into another secure location on your computer.

Create backup to Edit Hosts File on Windows

  • To modify the hosts file, you can use whatever plain text editor you like, although Notepad works just fine. After clicking the Start button and typing “notepad” into the search box, right-click the program and select “Run as Administrator.”

Using Notepad to edit hosts file

Go to File > Open in the next window. Click Open after entering the following address in the text box for the file name. You can also access the file manually:


The select should be changed to “All Files (*.*)” rather than “Text Documents (*.txt).” If you’re only displaying text documents, the hosts file won’t be visible because it doesn’t have a file extension. Find the “hosts” file and click open after making the necessary changes.

How to Edit Hosts File on Windows

After that, you can make any changes you want to the hosts file. It can be used for a few obvious things, such as blocking or redirecting internet traffic.

To continue and test what you have done here, open the file, then scroll to the bottom and type the IP address and domain name of the website you wish to ban. Suppose we wish to update the file to include YouTube’s IP address. Our file will appear as follows using this example. <a href="http://<a href="" target="_blank" rel="noopener"></a>"><a href="" target="_blank" rel="noopener"></a></a>

If you want to block a site, simply enter incorrect IP addresses like Using the example above, we will be entering the following text if we want to block YouTube. <a href="http://<a href="" target="_blank" rel="noopener"></a>"><a href="" target="_blank" rel="noopener"></a></a>

Click File > Save As to save time. Then, select All Files from the Save as type option by expanding it. Finally, save the file to your desktop with the name hosts2.

All that’s left to do is place the hosts file in the appropriate spot now that it’s ready to use. Go to the desktop, right-click the newly generated file, and select Rename.

Rename the new host file

Removing the 2 (or any other number or letter you added) will leave the file with the name Hosts alone.
Copy the file. Open File Explorer, then go to where the host was originally located. If you receive an overwrite prompt, simply paste the new file here and select Replace the file in this destination.

Replace the file in the destination of the host

You can now use your edited hosts file.

Edit Hosts File on Windows 8

On Windows 8 and 8.1, editing the hosts file is essentially the same as on Windows 10 or 11.

  • So, again type “Notepad” into the search bar, right-click it in the search results list, and select “Run as Administrator”.

Edit Hosts File on Windows 8

Once Notepad is launched, open it by clicking “File” in the top right corner, selecting “Open,” and then going to the /etc/ folder:


The hosts file can be edited just like any other file. If you like, you can use it to restrict access to particular websites.

Edit Hosts File on Windows 7

The hosts file can be accessed in Windows 7 the same way it can in newer Windows versions. To open the hosts file, locate it using Notepad while running as administrator, and then open it.

  • There are several options for doing this. Finding Notepad, selecting “Run as Administrator,” and then going to the hosts file are the initial steps. It’s situated at:

Instead, press Windows+R to open the Run window, then type the following command into it:

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

Edit Hosts File on Windows 7

The command will open the chosen file immediately and launch Notepad as administrator. You can edit the file after Notepad is opened. In this example, Google will be blocked. Simply type the following after the # mark to accomplish this.    <a href="" target="_blank" rel="noopener"></a>

Once you’ve finished editing your hosts file, be sure to save it.

How to Edit Hosts File in Linux Ubuntu

So far, you learned how to edit hosts file in Windows. Regardless of the version you are using, the above content can be helpful. But if you are going to edit hosts file on your Linux after buying Ubuntu VPS, Linux VPS, the following part of this tutorial is all for you.

Edit Hosts File on Linux Ubuntu

To edit hosts file on Linux Ubuntu, you can use your preferred text editor to complete the task on Linux. In Ubuntu (and most Linux systems) it is possible to change the hosts file in the Terminal directly. You can use your preferred GUI text editor or your preferred command-line editor.

  • In this case, we will use Ubuntu’s Gedit. Ctrl+Alt+T will launch the Terminal. Then enter your admin password after typing the command below:
sudo su

Enter the following command to launch Gedit and access the hosts file:

sudo gedit /etc/hosts

Just like in the Windows 10 & 11 instructions, add the targeted IP address, a space, and the domain name at the bottom of the hosts file and save your edits.

Edit Hosts File on macOS

As the latest explained OS, if you are using Mac, use the below steps to edit the Mac hosts file:

  • Open Terminal by clicking the Launchpad button. The Nano Editor is what we’ll be utilizing. Type the following statement into the box and hit Enter to run it as an administrator:
sudo nano /private/etc/hosts

Your password must be entered. You’ll be taken to the hosts file. Include the domain name first, then your preferred IP address, separated by a space. Use the Ctrl + O shortcut to save your changes.

Troubleshoot Hosts File Not Working

There may be several causes for the hosts file to stop functioning on Windows, Linux, or Mac. It’s possible that you can’t open the file because the format isn’t supported, or you don’t have the necessary access permissions. Here are some troubleshooting techniques you can attempt if you are having problems with the file:

1. Clear the NetBIOS and DNS Cache

The first thing we advise doing to fix such problems is clearing DNS cache because they frequently result from damaged or defective cache files.

Once the DNS cache has been removed, proceed as follows to erase the NetBIOS cache:

In the Windows search box, enter “Command Prompt”, select “Run as administrator.”, and run the following command in the ensuing window.

nbtstat -R

Check to see if the issue has been fixed after running the command.

2. Restart the hosts file

To fix any problems with the hosts file, you can also attempt restoring it to its original state. Launch File Explorer and go to the following location:

%systemroot% \system32\drivers\etc

Change the hosts file’s name to hosts.bak and navigate to the location below:


To change the text in the hosts file, double-click on it and enter the following:

Troubleshoot Hosts File Not Working

To make the changes, save the file.


In this article, you learned How to Edit Hosts File in Windows, Mac, and Ubuntu. If you have recently bought a domain, you can benefit from this content. Additionally, your domain must point to the new server when you move your website to a different hosting company. You won’t be able to view your website for 24 to 48 hours while your domain is usually starting to function. You can access your website by making changes to the hosts file, specifically by adding a unique IP address that points to your domain. If you want to make changes to your site after migration to see how they will appear on the new server, this is helpful.

All the explained steps in this tutorial can be used for a variety of functions, including blocking, redirecting, building website shortcuts, and even testing web servers. keep in mind that all the taught modifications need administrator access on every system, and they only apply to the machine where the hosts file is located. If you follow the above steps properly then you can Edit Hosts File in Windows, Mac, and Linux Ubuntu but do not hesitate to contact us if you encounter any problems. Our technical support team will try their best to solve your problems.

Leave a Reply

Your email address will not be published. Required fields are marked.