Is it really that hard to edit a Hosts file?

 Feb 14, 2017

I have run quite a number of infrastructure courses, including basic networking subjects for many years now, and it still amazes me how often students get stuck trying to edit a simple Hosts file.

Now the Host file is a simple text file that is used to manually map IP addresses to host names, but only for that specific host. DNS of course is the automated way, but the Hosts file can still be used to “override” DNS queries (i.e. the Hosts file is checked first), or in cases where DNS resolution may be problematic, such as VPN server mappings etc. It can also be useful in troubleshooting scenarios (such as particular hosts not registering themselves with the DNS server), or to “block” certain web sites or hosts, by assigning the name to either an incorrect IP address or the loopback address e.g.

127.0.0.1     www.BadWebSite.com
127.0.0.1     NotMyServer

Very useful functions, but also very bad in the wrong hands, which meant that the Hosts file was a common target of attack by the Bad Guys – if a Bad Guy could modify the Hosts file on your computer they could do things like redirect you to their website instead of the real one etc. – usually without your knowledge.

Now Microsoft Windows, for a long time now, has protected the Hosts file by a number of means, such as naming the file Hosts without an extension, etc. but the main catch is that – like all the other system files under the Windows directory – it needs administrative access to save any changes.

Now most people I have seen tend to go to the Hosts file in Windows Explorer, right click to open it in Notepad, but then get an Access denied error or “requires Administrative access” when they try to save it – and then scratch their heads saying “but I do have administrative rights”. And I have seen many blogs and YouTube videos with ways to get around this security – from videos insisting you have to load a third–party editing program(s), to saving the file in a different location, changing the default folder options (to show hidden file extensions), to running complicated DOS commands using ATTRIB.exe or CACLS.exe etc. Definitely overkill. Now don’t get me wrong, most of those methods do tend to work – eventually – but I find there is a far simpler way.

All I do is right click Notepad and open it with the “Run as Administrator” option, then use Notepad to browse to and open the Hosts file. Then you can edit it to your hearts content and save it correctly. Note that Notepad’s default is to add the .txt extension when saving files so don’t forget to change the “Save as Type” option to All Files (*.*) before hitting the Save button.

One last tip: while you are in the Windows/System32/drivers/etc directory (a directory path that should be tattooed on the inside eyelids of all network techies) have a look at the other files there – particularly the Networks, Protocols and Services files. These are files that are on all Windows platforms since the early Windows for Workgroup days, and they are great for reminding you what services are on which particular port number, or which Assigned Internet protocol numbers are used in the IP header fields – at least for Windows platforms!

For more information, take a look at our SQL Server 2016 training courses.


How do your Excel skills stack up?   

Test Now  

About the Author:

Gordon Cowser  

With over 22 years real world and training experience, Gordon is our most senior IT Infrastructure trainer. His expertise includes but is not limited to; Microsoft Server and Client OS, Messaging, Collaboration, Active Directory and Network Infrastructure. Gordon also specialises in SharePoint technologies training in both technical and end user aspects. With his extensive skill-set he brings a thorough mentoring capability to the classroom where he can advise on technical issues and challenges often beyond the scope of the course curriculum. A very approachable and experienced training professional, he has the ability to establish credibility fast with students at all levels.

Read full bio
top