Hosts files have been in use since ARPANET. They were used to resolve hosts names before DNS. hosts files would be massive documents used to aide the network name resolution.
Microsoft kept the hosts file alive in Windows networking which is why it varies very little whether used in Windows, macOS, or Linux. The syntax stays mostly the same across all platforms. Most hosts files will have several entries for loopback. We can use that for the basic example for the typical syntax.
The first part will be the location to redirect the address to, the second part will be the address that you will want to redirect, and the third part is the comment. They can be separated by a space, but for ease of reading are typically separated by one or two tabs.
Example
185.70.8.233 datacentreplus.co.uk www.datacentreplus.co.uk
Now let’s look at accessing the hosts files in the different operating systems…
Windows
If you are using a Microsoft operating system like Windows 10, Windows 8, Windows 7, and Windows Vista you must run Microsoft Notepad as an administrator.
Use the following instructions if you’re running Windows 10 or Windows 8:
1. Press the Windows key.
2. Type Notepad in the search field.
3. In the search results, right-click Notepad and select Run as administrator.
4. From Notepad, open the following file:
c:\Windows\System32\Drivers\etc\hosts
5. Make the necessary changes to the file.
6. Select File > Save to save your changes.
Use the following instructions if you’re running Windows 7 or Windows Vista:
1. Select Start > All Programs > Accessories.
2. Right-click Notepad and select Run as administrator.
The Windows needs your permission UAC window appears.
3. Click Continue to grant permission.
Notepad opens.
4. In Notepad, select File > Open.
5. In the File name field, enter the following path:
C:\Windows\System32\Drivers\etc\hosts
6. Select Open.
7. Make the necessary changes to the file.
8. Select File > Save to save your changes.
Use the following instructions if you’re running Windows NT, Windows 2000, or Windows XP:
1. Select Start > All Programs > Accessories > Notepad.
2. Select File > Open.
3. In the File name field, enter C:\Windows\System32\Drivers\etc\hosts.Select Open.
4. Select Open.
5. Make the necessary changes to the file.
7. Select File > Save to save your changes.
Launch Terminal, type sudo nano /private/etc/hosts and press Return. You’ll need to also enter your admin password to execute it, as with all sudo commands.
You will now have the hosts file open in the Nano editor. Use the arrow keys on your keyboard, to navigate and edit the file.
Like with the Windows method above you should just add the desired IP followed by the host name (or domain name).
Press Control-O to save the file.
Use your Web browser to test the changes and flush the cache with dscacheutil -flushcache if they still haven’t taken into effect.