How to edit Host file ?
The host file, also known as the "hosts" file, is a plain text file that maps hostnames to IP addresses. It is used by operating systems to resolve domain names locally before querying DNS servers. Here are the locations of the host file in macOS, Windows, and Linux, along with instructions on how to edit them:
macOS:
Host file location: "/etc/hosts" or “/private/etc/hosts”
To edit the host file in macOS, you can follow these steps:
Open the Terminal application.
Type "sudo nano /etc/hosts" and press Enter.
Enter your administrator password when prompted.
The host file will open in the nano text editor. Make the necessary changes.
To save the changes, press Control+O, then press Enter.
To exit the editor, press Control+X.
Windows:
To edit the host file in Windows using Notepad, you can follow these steps:
Press the Windows key on your keyboard to open the Start menu.
Type "Notepad" (without quotes) in the search bar.
Right-click on "Notepad" in the search results and select "Run as administrator." This will open Notepad with administrative privileges.
In Notepad, click on "File" in the menu bar and choose "Open."
In the file explorer window, navigate to the following location:
%windir%\system32\drivers\etc\
Or
PowerShell
Start-Process -FilePath "notepad.exe" -ArgumentList "$env:windir\system32\drivers\etc\hosts" -Verb RunAs
The `%windir%` is an environment variable that represents the Windows installation directory, typically `C:\Windows`.
Change the file type filter to "All Files (*.*)".
Select the "hosts" file and click on "Open."
Make the necessary changes to the file.
After making the changes, click on "File" and choose "Save" to save the modified host file.
Close Notepad.
Remember, you need to run Notepad as an administrator to have the necessary permissions to edit the host file. Also, be cautious when editing the host file to avoid any unintended disruptions to network connectivity or DNS resolution.
Or
Host file location: "C:\Windows\System32\drivers\etc\hosts"
To edit the host file in Windows, you can follow these steps:
Open the File Explorer and navigate to "C:\Windows\System32\drivers\etc"
Copy the hosts file to the desktop or another location.
Open the copied hosts file using a text editor such as Notepad.
Make the necessary changes to the file.
Save the file.
Copy the edited hosts file back to the "etc" folder, replacing the original file if prompted.
Linux (Debian and Fedora):
Host file location: "/etc/hosts"
To edit the host file in Linux, you can follow these steps:
Open the Terminal.
Type "sudo nano /etc/hosts" and press Enter.
Enter your administrator password when prompted.
The host file will open in the nano text editor. Make the necessary changes.
To save the changes, press Control+O, then press Enter.
To exit the editor, press Control+X.
It's important to note that editing the host file requires administrative privileges. Therefore, you may need to use the "sudo" command in macOS and Linux or open the text editor with administrator privileges in Windows. Additionally, be cautious when modifying the host file, as incorrect changes can disrupt network connectivity or DNS resolution.