Skip to main content

Edit your Hosts File to access your domain on another server/IP

During the lifetime of a website, you will probably have the need to migrate the whole website to another host with another IP address.

To test on your local desktop client if your website works before you change the productive DNS entries of your domain you can use the hosts file.

How to change the local Hosts File

In our example, we point the domain testdomain.ch with the subdomains (www, sub) to the new IP address 192.168.0.1.

As soon as we open our local webbrowser, all requests regarding testdomain.ch and its subdomains will be sent to the new IP address 192.168.0.1. The usual DNS entries will be suppressed.

WARNING: Please do not forget to remove the entries after your testing!

Linux / MacOS

The file /etc/hosts contains all local host definitions.

It can only be modified by the root user. Add the following entries:

root@server:$ vi /etc/hosts

192.168.0.1 testdomain.ch www.testdomain.ch sub.testdomain.ch

Windows

The file c:\Windows\System32\Drivers\etc\hosts contains all local host definitions.

It can only be modified with administrator rights. Add the following entries using the notepad editor:


192.168.0.1 testdomain.ch www.testdomain.ch sub.testdomain.ch