While the internet is only about 30 years old, in many ways the hosts file is a keepsake of its ( not so ancient ) past. In most cases you probably wo n’t need to update your hosts file on Windows. But knowing where it is and how it works can be helpful if :

  • you’re having trouble with local development
  • you suspect malware has tampered with the hosts file
  • you want a quick and simple way to block some websites
  • or if you want to set up some helpful shortcuts to internal IP addresses

In this article we ‘ll cover what a hosts file is, how to edit it on Windows, and we ‘ll go over some neat tricks you can do with it .

What’s a hosts file anyway?

back in the early days of the internet, before it was widespread, computers used a hosts file to map hanker, hard to remember IP addresses with much shorter, easier to remember hostnames.

For exemplar, here ‘s a note you ‘ll find in many hosts files on Windows, Linux, and macOs :

127.0.0.1       localhost

That direction, rather of having to remember a hanker IP address, all you had to do was visit localhost .

Why hosts files fell out of favor

The hosts files arrangement worked well for the early internet, but there were a few major problems. As the internet grew, indeed did the distance and complexity of the hosts files. besides, each hosts file entirely worked for the calculator it was on, and keeping them in synchronize with the changes in hostnames and IP addresses became a huge pain. For example, imagine that you have two computers, A and B. Their hosts files contain this function for google.com :

172.217.26.46       google.com

Computer A and B’s hosts file But when Google updates their information science addresses, entirely computer A updates its hosts file to match :

172.217.175.78       google.com

Computer A’s updated hosts file indeed everyone on calculator B is stuck without Google until person updates the hosts file. When that person does update the hosts file, they add another introduction to handle Google with the world wide web subdomain .

172.217.175.78       google.com
172.217.175.78       www.google.com

Computer B’s newly updated hosts file now everyone on computer B is taken to the correct web site whether they visit google.com or www.google.com. And everyone on computer deoxyadenosine monophosphate can only visit google.com, not www.google.com, at least until its own hosts file is updated to match. As you can imagine, hosts files would get complicated, fast .

The solution

If you ‘re thinking that person should have equitable made a cardinal repository to map all IP addresses with all hostnames, that ‘s precisely what happened. early on, a central hosts file was manually maintained and shared by the Stanford Research Institute. This arrangement lead to the invention of domains and top degree domains like .com and .edu, Whois, and it became increasingly automated. In the end, the humble hosts file and innovators like Elizabeth J. Feinler lead to the invention of the Domain Name System however in use nowadays .

How to edit a hosts file on Windows

To edit a hosts file on Windows 10, you ‘ll need to open it as an administrator. first, assailable Notepad as an administrator by pressing the Windows key, typing in “ notepad ”, and clicking “ Run as administrator ” :imageNote: You may need to click the arrow button to expand the dropdown to see the “Run as administrator” option To open the hosts file in Notepad, pawl “ File ”, “ outdoors ”, and voyage to C:\Windows\System32\drivers\etc. You wo n’t be able to see any files in this directory because they are n’t text documents. To change the file type, click on the dropdown in the bottom right of the Open menu and click on “ All Files ” :image-1 You ‘ll see a charge named hosts. Double click on that file to open it. then, you ‘ll see a hosts file exchangeable to this :

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

Windows 10’s default hosts file note that everything is commented out with # characters, meaning that nothing is actually being read from the hosts file. modern versions of Windows include a sort of DNS organization already, so if you visit localhost it ‘ll automatically redirect you to 127.0.0.1. With that out of the room, here are some things you can do with the hosts file. If you ‘re doing some local development and are having problems with localhost, you can good remove the comments from your hosts file :

...
# localhost name resolution is handled within DNS itself.
127.0.0.1       localhost
::1             localhost

After saving the hosts file, close Notepad. then, open PowerShell by pressing the Windows winder, searching for “ powershell ”, and clicking “ Run as Administrator ” :Screenshot showing how to open PowerShell as an administrator In the PowerShell window, embark ipconfig /flushdns to flush the built-in Windows DNS :Screenshot showing how to flush the Windows DNS with PowerShell After that, you should be able to visit localhost in your browser and see whatever you ‘re hacking on. If you ‘re still having issues, try closing your browser completely, then open a new browser window and try again.

even though hosts files have fallen out of favor with newer systems like DNS, they placid work for bequest reasons. And hackers have decidedly taken advantage of this in the past. What they would do is point a common web site like google.com towards an insecure IP address. This IP address could serve a site that looks equitable like Google ‘s, but is actually trying to steal your sensitive information. While this was a trouble in the past, most security software like the Windows Security Suite can recognize and fix problems with the hosts file mechanically. That said, if you open up your hosts file and see a lot of strange entries, then you may want to revert to the default Windows hosts file. precisely imitate and paste the default hosts file from earlier in the article into your hosts file and save. then, candid PowerShell and use the ipconfig /flushdns command to flush the Windows DNS. note that some third-party security software uses the hosts file to block dangerous websites. If that ‘s the character, no worries – your security software should add all those entries back to your hosts file. We ‘ll go over how this works in the next section .

How to use the hosts file on Windows 10 to block websites

Do n’t want friends or family to visit certain websites on your calculator ? Or are you like me and get distracted by all the cat photograph on the internet ? If therefore, then you can use the hosts file to block websites entirely. For example, if you want to block Reddit, just add this to the bottomland of your hosts file :

127.0.0.1     reddit.com
127.0.0.1     www.reddit.com

then, open PowerShell and run ipconfig /flushdns to flush the Windows 10 DNS. besides, close the browser windows that are open and reopen them. After that, every fourth dimension you try to visit Reddit, or snap on a Reddit URL like hypertext transfer protocol : //www.reddit.com/r/FreeCodeCamp/, your browser will be redirected to 127.0.0.1, or localhost. Since there ‘s no web site there, your browser will show an error message :Screenshot of error message after blocking reddit.com in the hosts file and visiting it in the browser The one downside is that this entirely works on one device – you could just reach for your phone and browse Reddit on that rather. still, it ‘s a neat means to create some friction on your work calculator. This leads nicely into the stopping point trick, which is to use the hosts file to make your life a little piece easier .

How to use the hosts file on Windows 10 to set up helpful shortcuts

If you spend a set of fourth dimension adjusting your router ‘s settings, or you have a cool project running on a Raspberry Pi, you ‘ll know that typing in a hanker IP address is a drag. rather, you can use the hosts file to make connect to early devices on your local net much fast. For example, if your router is at 192.168. 0.1, you can add the following to your hosts file :

192.168.0.1       my.router

then, flush your Windows 10 DNS with ipconfig /flushdns and restart your browser. And then any clock you visit my.router, you should be redirected to 192.168.0.1. barely note that you may need to visit hypertext transfer protocol : //my.router, at least the first gear time. Otherwise your browser might not recognize .router as a valid top-level world ( TLD ), and will try to search for the term my.router alternatively. To get around this, you could use a hostname like this alternatively :

192.168.0.1       router.my

This should work right away because .my is the TLD for people and companies in Malaysia. fortunately there are a unharmed bunch of valid TLDs nowadays. here ‘s a list of some of the most coarse TLDs out there : hypertext transfer protocol : //en.wikipedia.org/wiki/List_of_Internet_top-level_domains again, the one downside to this method acting is that it only works on once device. You ‘d have to update the hosts files on your other devices to enable the like shortcuts. And that should be merely about everything you need to know about the hosts file on Windows 10. And a batch of this cognition should carry over to Linux and macOS.

so get out there and customize your hosts file like the pioneers of the internet once did. Did you find this helpful ? Are there any other hosts file tricks you know ? Let me know over on Twitter. Stay safe and glad hosts file editing !

informant : https://themedipia.com
Category : Website hosting

Leave a Reply

Your email address will not be published.