How To Find The Host File In Windows
While the internet is but virtually 30 years old, in many ways the hosts file is a relic of its (not and so ancient) past.
In most cases you probably won't need to update your hosts file on Windows. Simply knowing where it is and how it works can be helpful if:
- you're having trouble with local evolution
- you lot suspect malware has tampered with the hosts file
- yous want a quick and simple fashion to block some websites
- or if you lot want to set upwards some helpful shortcuts to internal IP addresses
In this article we'll embrace what a hosts file is, how to edit information technology on Windows, and we'll go over some neat tricks y'all can do with it.
What's a hosts file anyway?
Dorsum in the early days of the internet, earlier information technology was widespread, computers used a hosts file to map long, hard to call back IP addresses with much shorter, easier to remember hostnames.
For example, here's a line you'll find in many hosts files on Windows, Linux, and macOs:
127.0.0.1 localhost
That style, instead of having to remember a long IP accost, all yous had to exercise was visit localhost.
Why hosts files brutal out of favor
The hosts files organization worked well for the early internet, but in that location were a few major problems.
Every bit the internet grew, then did the length and complication of the hosts files. Also, each hosts file just worked for the computer information technology was on, and keeping them in sync with the changes in hostnames and IP addresses became a huge pain.
For example, imagine that you take 2 computers, A and B. Their hosts files contain this mapping for google.com:
But when Google updates their IP addresses, simply computer A updates its hosts file to friction match:
And so anybody on computer B is stuck without Google until someone updates the hosts file. When that person does update the hosts file, they add another entry to handle Google with the www subdomain.
Now everyone on figurer B is taken to the correct website whether they visit google.com or www.google.com.
And anybody on computer A tin only visit google.com, not www.google.com, at least until its ain hosts file is updated to match.
Equally you can imagine, hosts files would get complicated, fast.
The solution
If you're thinking that someone should take merely made a primal repository to map all IP addresses with all hostnames, that's exactly what happened.
Early on, a central hosts file was manually maintained and shared past the Stanford Enquiry Found. This system lead to the invention of domains and top level domains like .com and .edu, Whois, and it became increasingly automated.
In the finish, the humble hosts file and innovators similar Elizabeth J. Feinler atomic number 82 to the invention of the Domain Name System still in utilise today.
How to edit a hosts file on Windows
To edit a hosts file on Windows 10, you lot'll need to open it equally an administrator.
Start, open up Notepad as an administrator past pressing the Windows fundamental, typing in "notepad", and clicking "Run as administrator":
To open the hosts file in Notepad, click "File", "Open up", and navigate to C:\Windows\System32\drivers\etc
.
You won't be able to see whatever files in this directory because they aren't text documents. To change the file type, click on the dropdown in the lesser correct of the Open menu and click on "All Files":
You'll run across a file named hosts
. Double click on that file to open it.
Then, you'll run into a hosts file like to this:
Notation that everything is commented out with #
characters, pregnant that nothing is actually being read from the hosts file. Modern versions of Windows include a sort of DNS system already, so if you visit localhost information technology'll automatically redirect you lot to 127.0.0.1
.
With that out of the way, hither are some things you can practice with the hosts file.
How to update the hosts file on Windows 10 if you lot take problem with localhost
If you're doing some local evolution and are having bug with localhost, you tin can merely remove the comments from your hosts file:
... # localhost name resolution is handled within DNS itself. 127.0.0.i localhost ::1 localhost
Later saving the hosts file, close Notepad.
And so, open PowerShell by pressing the Windows central, searching for "powershell", and clicking "Run equally Administrator":
In the PowerShell window, enter ipconfig /flushdns
to flush the inbuilt Windows DNS:
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 endmost your browser completely, then open a new browser window and try again.
How to update your hosts file on Windows 10 if you call back it'southward been tampered with
Even though hosts files have fallen out of favor with newer systems like DNS, they still piece of work for legacy reasons. And hackers have definitely taken reward of this in the past.
What they would exercise is point a common website like google.com towards an unsafe IP address. This IP address could serve a site that looks just like Google'due south, just is actually trying to steal your sensitive information.
While this was a problem in the past, nearly security software like the Windows Security Suite tin can recognize and set bug with the hosts file automatically.
That said, if you open up your hosts file and come across a lot of foreign entries, and so you may desire to revert to the default Windows hosts file.
Only re-create and paste the default hosts file from before in the article into your hosts file and save. Then, open PowerShell and use the ipconfig /flushdns
control to flush the Windows DNS.
Note that some third-party security software uses the hosts file to cake dangerous websites. If that's the case, 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
Don't want friends or family unit to visit certain websites on your computer? Or are you like me and go distracted past all the cat photos on the internet?
If and so, then you can use the hosts file to block websites entirely.
For example, if yous want to block Reddit, just add this to the bottom of your hosts file:
127.0.0.1 reddit.com 127.0.0.i world wide web.reddit.com
Then, open PowerShell and run ipconfig /flushdns
to flush the Windows 10 DNS. Also, close the browser windows that are open and reopen them.
Later that, every fourth dimension yous try to visit Reddit, or click on a Reddit URL similar https://www.reddit.com/r/FreeCodeCamp/, your browser will be redirected to 127.0.0.1
, or localhost.
Since there's no website there, your browser will evidence an error bulletin:
The 1 downside is that this simply works on ane device – you could simply reach for your phone and scan Reddit on that instead. Still, information technology'south a dandy style to create some friction on your work computer.
This leads nicely into the last play tricks, which is to use the hosts file to make your life a piddling bit easier.
How to use the hosts file on Windows 10 to set up helpful shortcuts
If you spend a lot of time adjusting your router's settings, or y'all accept a cool projection running on a Raspberry Pi, you lot'll know that typing in a long IP address is a drag.
Instead, you lot can use the hosts file to make connecting to other devices on your local network much faster.
For example, if your router is at 192.168. 0.1
, you lot tin can add the post-obit to your hosts file:
192.168.0.i my.router
Then, flush your Windows 10 DNS with ipconfig /flushdns
and restart your browser.
And and so any time yous visit my.router, you should be redirected to 192.168.0.i
.
Just notation that you may need to visit http://my.router, at least the offset time. Otherwise your browser might not recognize .router as a valid meridian-level domain (TLD), and volition endeavour to search for the term my.router instead.
To go around this, you could use a hostname like this instead:
192.168.0.ane router.my
This should work right away because .my is the TLD for people and companies in Malaysia.
Fortunately there are a whole lot of valid TLDs nowadays. Here's a list of some of the about mutual TLDs out at that place: https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
Again, the one downside to this method is that it only works on once device. You lot'd have to update the hosts files on your other devices to enable the same shortcuts.
And that should be only nigh everything yous demand to know virtually the hosts file on Windows 10. And a lot of this knowledge should behave over to Linux and macOS.
So leave there and customize your hosts file like the pioneers of the internet once did.
Did you discover this helpful? Are there whatsoever other hosts file tricks you know? Permit me know over on Twitter.
Stay rubber and happy hosts file editing!
Learn to code for gratuitous. freeCodeCamp's open source curriculum has helped more xl,000 people become jobs as developers. Get started
Source: https://www.freecodecamp.org/news/how-to-find-and-edit-a-windows-hosts-file/#:~:text=To%20open%20the%20hosts%20file,%5CSystem32%5Cdrivers%5Cetc%20.&text=You'll%20see%20a%20file,that%20file%20to%20open%20it.
Posted by: taylorshantoote1978.blogspot.com
0 Response to "How To Find The Host File In Windows"
Post a Comment