Select Page

Using a Local Domain Name for Testing

Using a Local Domain Name for Testing

Introduction

If “Money Makes The World Go Round” then Domain Names make the Web go round.  Without them we would all have to remember ip addresses (or yes – use a search engine).

Remembering http://212.58.246.90 instead of www.bbc.co.uk may be do-able, but try adding 216.58.201.36 for www.google.com and 51.211.239.244 instead of www.netflix.com to the old grey matter and you’ll soon have trouble.  And that’s before any ip address changes.

So – we’re all agreed – domain names are a jolly good idea – and for the most part not that expensive.  £10-£15 will get you a domain name for a year.  But what if you don’t want to buy a domain name because you’re just testing or learning – well the good news is you don’t have to buy a domain name to use one.

You can make up your own domain names and not spend a penny by using a local domain name.  The only downside is it will only work on the computer you set it up on.  But for testing or learning something that’s fine.

1. The Host File

So – how does it work?  Well, whether you’re using Linux or Windows or OSX they all have one thing in common.  They all have a host file.

This host file holds domain names and ip addresses and allows you to add domain names to your local device for testing.

The host files follow a pretty standard format which ever operating system they’re on – which is lucky for us.

Here’s an example of the default (unaltered) host file from a Windows 10 PC.

image

and here’s one from Linux.

image

and from OSX.

image

You should be able to see the similarities between the three above.

One thing to remember is that the host file is checked BEFORE the internet for a domain name match.

In this way you could send your browser to a different site so when you enter www.google.com it goes to your test server.  Not really a great idea, just know your host file is checked first.

2. Editing a Windows Host File

You can use any editor to edit the Windows host file.  As it’s a simple text file Notepad is a great choice.

Find Notepad in your menu and right click to bring up the context menu.

image

Select Run As Administrator and click YES  to “allow app to make changes”.

Select File->Open  from the Notepad menu and browse to c:\windows\system32\drivers\etc

image

Select All Files as above and then double click on ‘hosts’.

image

Now jump to the section lower down – Adding Your Own Local Domain Name.

3. Editing a Linux Host File

As with the Windows host file, the Linux host file is plain text so can be edited with your favourite editor such as Nano or Vi

To use Nano

> sudo nano /etc/hosts

To use Vi

> sudo vi /etc/hosts

image

Now jump to the section lower down – Adding Your Own Local Domain Name.

4. Adding Your Own Local Domain

With your editor open, go to the last line and make a new line.

The IP address is first things on the line and then the domain name so type the following on a new line:

192.168.1.110  www.myownwebsite.com

where 192.168.1.110 is the ip address of your test website and www.myownwebsite.com is the name you want to use.

You can have multiple names on one line such as :

192.168.1.110 www.myownwebsite.com myownwebsite.com

Now save the file.

You should now be able to browse to your test website, but remember – only from the computer where the edited host file is saved.

Leave a reply