Editing your machine’s hosts file / View a website as it appears on a different host

Change the domain’s A-Record (without changing the domain’s A -record)

In the old days of the internet there was no DNS system. Everyone kept a copy of all the hosts (this was before the days of websites) on the internet on a file on their computer. As new hosts were added to the internet an updated hosts file was sent round everyone on the internet so they could get their local copy updated. This system got out of hand as the internet expanded so it was replaced by the DNS system.

You can override the DNS for a domain on your local computer. This lets you view a website (or user ftp etc.) as it would appear on a different server or host, as though the domain pointed to a different location even when it doesn't.

Let’s say I was looking at moving example.com to a different server. Currently the domain is pointed to 93.184.216.34 and I’m going to be moving the site over to a new server at 123.123.123.123. I want to see how the site would look on the new server but I don’t want anyone else to see it. By adding a single line to my hosts file I can ‘repoint’ the domain to the new IP address but just for myself.

You will need elevated permissions on whatever system you are using. If you are on a restricted work computer this may not be possible.

On Windows the hosts file is located at the following path: C:\Windows\System32\drivers\etc\hosts Find notepad or a text editor of your choice. Right click on it and ‘run as administrator’ then file open and find the file with the path shown above (you may need to select the option ‘view all files’ to see the file listed as it is not a txt file) Add the line:

123.123.123.123 example.com www.example.com

This will point the both the domain and the www subdomain to the chosen IP address. You will need to restart your browser for this to apply.

On Linux or MacOS the process is the same except that the hosts file is located at /etc/hosts The vim text editor can be used for this by running the command in the Terminal:

sudo vim /etc/hosts

Add the line:

123.123.123.123 example.com www.example.com

This will point the both the domain and the www subdomain to the chosen IP address. You will need to restart your browser for this to apply.

You can re-open the hosts file using the same method as described above, delete the offending lines and save the file. (Don't forget to restart your browser for it to apply again.) Another option is to comment out the offending line. Adding # before any line in the hosts file comments it out. (So the text will remain but it will not do anything.)

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies

Spotted a mistake? Have a comment or suggestion? We'd love to hear from you. Please feel free to get in contact.

All information provided by Rootchronicles.com is without warranty. We take no responsibility for any loss, damage or any other misfortune resulting from following or attempting to follow guidance found on this site. If in doubt always seek professional consultation.

  • Last modified: 2022/03/27 19:56 (2 years ago)
  • by megatea