Searching...

Changing the hosts file in Linux, MacOS, Windows

Editing the hosts file allows you to overwrite DNS records for the domain only on your computer / server. This can be used, for example, to test websites on a live domain without having to change DNS records, avoiding the risk that your clients may see a broken website before modifying, for example, paths or databases. How to do it - depending on the OS (operating system) you should use the following steps:

Windows users

In case you have a Windows operating system, you should be able to access the hosts file in this directory (always edit with administrator privileges):

C:\Windows\system32\drivers\etc\

You can open the file hosts in your favourite text editor. You should add following lines:

xxx.xxx.xxx.xxx yourdomain.com
xxx.xxx.xxx.xxx www.youdomain.com

"xxx.xxx.xxx.xxx" - IP address where your website is hosted - yourdomain.com has to be set up as domain for this server as well.

MacOS users

In case you have a MacOS operating system, you can change the file using Terminal - open Terminal and enter:

sudo nano /private/etc/hosts

OS will ask you for your password to enable sudo (editing with root privileges). File will be opened in text editor nano, add following lines:

xxx.xxx.xxx.xxx yourdomain.com www.yourdomain.com

"xxx.xxx.xxx.xxx" - IP address where your website is hosted - yourdomain.cz has to be set up as domain for this server as well.

Linux users

In case you have a Linux operating system, any distribution, you can change the file using Terminal - open Terminal and enter:

sudo nano /etc/hosts

In case you're logged in as root, you don't need to add "sudo". OS will ask you for your password to enable sudo (editing with root privileges). File will be opened in text editor nano, add following lines:

xxx.xxx.xxx.xxx vasedomena.cz www.vasedomena.cz

"xxx.xxx.xxx.xxx" - IP address where your website is hosted - yourdomain.cz has to be set up as domain for this server as well.

You should be able to access your webpages from your webhosting server after saving hosts file. Sometimes it's needed to restart PC because of browser's DNS cache.

Comments

To submit comment you have to be logged-in