For many Internet users the idea of editing operating system files can fill them with dread. However, if you are careful, do your research and create a backup then there are some very interesting ways in which you can use your host file. It is probably best to explain exactly what a host file is before we look at ways of editing it to do specific tasks
Table of Contents
What is a host file?
Whether using Windows, Mac or any other operating system, your machine will have a host file. The Host file allows you to override DNS (domain name system) servers. The best way to describe a DNS server is a public exchange where a domain address is used to find a website hosting server IP address. (Side note, the Internet actually works on IP addresses although it is easier for users to remember domain names). This ensures that when you try to access a website you are directed to the website host server and the relevant files, etc are accessed and uploaded. If you have ever accessed domain name records you will be asked to enter details of your hosting account for DNS records. So, where does a host file fit in?
When you try to access any website on your computer your browser will first search the operating system host file. If, as is normal, there is no information in the host file then the next stage will be to check DNS records to find the IP address for the website hosting server.
Checking the host file before the DNS records is in fact important in the hierarchical system.
Editing your host file
In order to edit your host file you will need to log on as an administrator. If using Windows OS you need to access the following folder:-
The best way to edit the file is to open it using the notepad option. This ensures there are no control characters which could cause problems. While some people will find it useful to create a backup of the host file, in reality you can simply remove previous entries if you need to or you find any issues.
5 Useful ways to use your host file
Let’s examine some useful ways to use your host file. We can pretty much guarantee you will never have heard of some of them.
1. Test a web server before going live
This is an extremely useful option when either releasing a new website to the World Wide Web or transferring a website to a new host server. It basically allows you to test a web server to see how a website would look giving you time to make any relevant changes before it goes live. This instruction looks the same but is a little more complicated behind the scenes. It makes use of host header files for shared hosting accounts.
Let us assume that you are in the process of moving your website to a new hosting server with the IP address 188.8.131.52. There are two main reasons to use this option which are:-
- Testing a new website before launch
- Awaiting the update of DNS server records
As we mentioned above, when you change host servers for any domain name it does take some time for DNS server records to be updated across the board. During this period, entering the domain name into a web browser might intermittently move between the old server and the new server until everything fully updates. So, by adding the following line into your host file:-
Your machine would be redirected to the new host server IP address while the DNS records are being updated. If you have a number of websites on a shared hosting account ( as opposed to for example a dedicated server) then you would simply add additional command lines such as:-
While the IP addresses are the same for these two websites the web host server will use the URL information to search for the relevant host headers. This will ensure that the request goes to the relevant section of a shared hosting server.
2. Block a website
If you’re looking to block a website from your computer, you may be censoring it for the family or it may be involved in some kind online hack, this is very simple. Within the host file you can add an IP address and a website domain name on the same line as follows:-
This simple but very effective command will ensure that every time the domain name is typed into your browser it will refer to the host file, see the new IP address and redirect the website request to this IP address. So what does this mean?
Well, let’s say that the IP address 184.108.40.206 is actually that for your computer as opposed to any web hosting server. Every time somebody tries to access the fake site on your machine it will be redirected to your computer, where there is no host server and no possibility of creating a connection. Hey presto, no access!
3. Redirect a website
The process of redirecting a website is very similar to that of blocking a website in that you introduce a different IP address which your browser will associate with the website address in the host file. As we mentioned above, the fact that the host file is accessed before the DNS records ensures you have full control when looking to redirect a website. So how does this work in reality?
Let us assume that every time you type in the domain name googlenews.co.uk you wish to redirect to the bbc.co.uk website. The first thing we need to do is find the IP address for the bbc.co.uk website which for this example we will assume to be 220.127.116.11. So, when editing the host file add the following line:-
Let’s test our theory. We know that the IP address is the one for the BBC website. So, when you type googlenews.co.uk into your browser, this would redirect to the BBC website. The potential use for this type of redirect is endless and can allow you to personalise your browser options.
4. Creating browser shortcuts
While this particular option is maybe not as powerful as it has been in the past, due to the ability to save favourite websites, it is still a very useful one to know. Let’s say for example you access the SkySports website on a regular basis. Rather than typing in the full domain name what if you could just type in “FB” for football?
This is very simple as all you need to do is find the IP address for the SkySports website which in this example we will use 18.104.22.168. When you have opened the host file add the following line:-
Every time that you type FB into your browser, your computer will access the host file and see if there is an instruction for that particular domain name/shortcut. Then the request redirects to the IP address 22.214.171.124 and hey presto, the SkySports website will open in your browser.
5. Accessing local domain names
When you set up a new router, initial access will be via the IP address. From here, you can set the relevant variables for your machine to allow full access to the Internet. Thankfully, using the host file you can set up access instructions to a number of local domain names. This can be very useful when you forget the IP address or you simply want to save time.
Most routers will use the IP address 192.168.0.1 to give you access. Use this connection to add relevant information to your machine. So, rather than typing the IP address every time, what if you could simply type router into your browser. You can by adding this instruction:-
So, every time you type route into your browser it will access the host file, see the instruction and point your request to the relevant IP address. Perfect!
Summary: A very powerful function!
The majority of Internet users will not be aware of the host file on their machine and the potential power this holds. The most common use is to test whether a website is working correctly on a new server prior to DNS records being updated. It is useful for testing a website before a launch. Plus, you can also use it to introduce an array of other options. Some options include: blocking websites, entering shortcuts and assigning local domain names. Certainly worth investigating! For a step by step guide to edit your host file please refer to this article.