Cloud Service >> Knowledgebase >> How To >> How to edit hosts file in Windows and Linux operating system?
submit query

Cut Hosting Costs! Submit Query Today!

How to edit hosts file in Windows and Linux operating system?

Editing the hosts report may be useful for numerous functions, including redirecting domain names to specific IP addresses or blocking certain websites. Here’s how you may edit the hosts file on each Windows and Linux working structures.

Windows

Open Notepad as Administrator:

 Search for "Notepad" in the Start menu.

Right-click on "Notepad" and select "Run as administrator." This is necessary because editing the hosts file requires administrative privileges.

Open the Hosts File:

In Notepad, go to File > Open.

Navigate to C:\Windows\System32\drivers\etc.

Change the file type from "Text Documents (.txt)" to "All Files (.*)".

Select the file named hosts and click Open.

Edit the Hosts File:

Add your desired entries at the end of the file. Each entry should be in the format:
Hosts File:

For example:
Hosts File:

This example redirects example.com to 127.0.0.1 (localhost).

Save the File:

After making your changes, save the file by going to File > Save.

Flush DNS Cache (if needed):

Open Command Prompt as an administrator.

Run the command:
Hosts File:

This clears the DNS cache and applies your changes immediately.

Linux

Open a Terminal Window:

You can usually find it in your applications menu or by pressing Ctrl+Alt+T.

Edit the Hosts File Using a Text Editor:

Use a text editor with superuser privileges. For example, with nano:
Hosts FileOr with vim:

Make Your Changes:

Add or modify entries in the file in the format:


For example:
Hosts File

Save and Exit:

In nano, save changes with Ctrl+O, press Enter, and exit with Ctrl+X.

In vim, save and exit with :wq and press Enter.

Flush DNS Cache (if needed):

Linux generally does not cache DNS queries in the same way as Windows. However, if your system uses systemd-resolved, you can restart it to clear the cache:
Hosts File

Notes:

Permissions: Editing the hosts record requires administrative or superuser permissions. Be cautious whilst making modifications, as incorrect entries can have an effect on your machine’s community conduct.

 

Backup: It’s a terrific concept to returned up the original hosts report earlier than making modifications. You can copy it to every other place for safekeeping.

If you come across issues or need similarly assistance, your operating system’s guide forums or documentation might also offer additional steerage.

Cut Hosting Costs! Submit Query Today!

Grow With Us

Let’s talk about the future, and make it happen!