Gizmos Freeware Reviews  

Go Back   Gizmo's Freeware Forum > Freeware Forum > General Computer Support

Reply
 
Thread Tools Display Modes
Old 14. Nov 2014, 09:37 PM   #1 (permalink)
Senior Member
 
Melita-s's Avatar
 
Join Date: Dec 2012
Location: Canada
Posts: 636
Default Is there a Command Line to open hosts file?

Could you please tell me the 'command line' to open the hosts file in the note pad, using the command window, for both Windows 7 and XP.

When I try to Open with note pad as admin, and typing the file path C:\Windows\System32\drivers\etc\hosts, Windows explorer opens 'downloads' page and I have to go to C: and follow the entire file path. I wonder if some setting in the computer has gone wrong for this to happen. As far as I can remember this method should open the hosts file in one step or am I wrong here? The method is successful but it takes too long

Regards,
__________________
Melita
Melita-s is offline   Reply With Quote
Old 15. Nov 2014, 12:53 AM   #2 (permalink)
Copy Editor
 
torres-no-tan-magnifico's Avatar
 
Join Date: Sep 2009
Posts: 1,120
Default

Windows key + R and type in the following: notepad c:\windows\system32\drivers\etc\hosts This will open up notepad containing the hosts file in both XP and W7.
HTH
__________________
(Mx16 + Cx1 + Lx2) + (Tx5 + Nx2 + Bx33)
torres-no-tan-magnifico is offline   Reply With Quote
Old 15. Nov 2014, 02:18 AM   #3 (permalink)
Senior Member
 
Melita-s's Avatar
 
Join Date: Dec 2012
Location: Canada
Posts: 636
Default

Thank you for this one. It works at the speed of light! Now, how can I do this with administrator privileges (like an elevated Command Prompt). Only then can I edit the file and save it. Without Administrator privileges I can edit but it will not save the changes.

There is also a method using the Command Prompt but I have forgotten it.

Kind regards,
__________________
Melita

Last edited by Melita-s; 15. Nov 2014 at 02:21 AM. Reason: add content
Melita-s is offline   Reply With Quote
Old 15. Nov 2014, 11:15 AM   #4 (permalink)
Super Moderator
 
Anupam's Avatar
 
Join Date: Jul 2008
Location: India
Posts: 15,323
Default

Melita, for opening the Notepad as administrator, you did right. But, why type the path manually?

From the Notepad menu, click on File --> Open...
and then navigate from there to the etc folder in the drivers directory.

Please note that to open the hosts file this way, you will have to select "All files" from the drop down list besides the box for file name, as normally, it will look for text files.

To open via command prompt, you do need an elevated command prompt. For that, go to Start Menu --> All Programs --> Accessories. There right click on Command Prompt and click on "Run as Administrator". This will open an elevated command prompt.

Also, another precaution, please be careful editing the hosts file, as editing without precautions will cause problems.
__________________
Anupam
Anupam is offline   Reply With Quote
Old 15. Nov 2014, 11:28 AM   #5 (permalink)
Site Manager
 
MidnightCowboy's Avatar
 
Join Date: Aug 2008
Location: South American Banana Republic, third bunch from the left
Posts: 15,276
Default

Quote:
Originally Posted by Anupam View Post

Also, another precaution, please be careful editing the hosts file, as editing without precautions will cause problems.
Indeed, such as loss of internet connection.

This link explains how to reset to default settings in the event of a problem.

http://www.askvg.com/how-to-reset-ho...p-vista-and-7/
__________________
Buy a Hoover and prove technology sucks.
MidnightCowboy is offline   Reply With Quote
Old 15. Nov 2014, 11:38 PM   #6 (permalink)
Senior Member
 
Melita-s's Avatar
 
Join Date: Dec 2012
Location: Canada
Posts: 636
Default

Quote:
Quote:
Originally Posted by Anupam View Post
Melita, for opening the Notepad as administrator, you did right. But, why type the path manually?

From the Notepad menu, click on File --> Open...
and then navigate from there to the etc folder in the drivers directory
.

I was doing that. Sorry Anupam I was not too clear in my writing.

Quote:
Also, another precaution, please be careful editing the hosts file, as editing without precautions will cause problems.
Thank you for cautioning me. I have been doing it for many years. Some time back I had quite a few unwanted web sites opening tabs in my computer and trying to get me to click on links etc. I am quite conversant with this operation and I have blocked about 40 domains. I still do that on the rare occasions that a rouge web site tries to mess with me. In fact I get a fiendish and malicious satisfaction when they get blocked! Thank you all the same

I also found the fastest way to open and edit 'hosts'. I typed what I learned from "torres-no-tan-magnifico", i.e. notepad c:\windows\system32\drivers\etc\hosts in to an elevated Command Window, instead of the 'RUN' window. hosts opened in note-pad and new entry saved successfully!

Quote:
Originally Posted by MidnightCowboy View Post
Indeed, such as loss of internet connection.

This link explains how to reset to default settings in the event of a problem.

http://www.askvg.com/how-to-reset-ho...p-vista-and-7/
Thank you for this link. Much appreciated. I have already made copies of the hosts files of my Windows 7 and XP both.

I want to point out an error in the 'askvg. com' page. Please look at my attachments. 'hosts 1' shows the hosts file for Windows 7 and 8. This is not going to work because there is the # mark before 127.0.0.1 and ::1. When the hash is typed before the entry, Windows takes it as a 'comment' and ignores it. As you say, the user may lose the Internet connection.

Image 'hosts 2' shows the same entries for Vista, which are correctly typed. XP also there shows correct entry.

Kind regards,
Attached Images
File Type: png hosts 1.PNG (2.6 KB, 1 views)
File Type: png hosts 2.PNG (3.3 KB, 1 views)
__________________
Melita

Last edited by Melita-s; 15. Nov 2014 at 11:55 PM. Reason: correction
Melita-s is offline   Reply With Quote
Old 16. Nov 2014, 10:08 AM   #7 (permalink)
Super Moderator
 
Anupam's Avatar
 
Join Date: Jul 2008
Location: India
Posts: 15,323
Default

Quote:
Originally Posted by Melita-s View Post
Thank you for cautioning me. I have been doing it for many years. Some time back I had quite a few unwanted web sites opening tabs in my computer and trying to get me to click on links etc. I am quite conversant with this operation and I have blocked about 40 domains.
If you are having the problem of pop-ups, or unwanted sites opening up in tabs, then using hosts file to block these sites is a way of dealing with them, but it's not the right way.

First, make sure that you are running a browser with a pop-up blocker (which most browsers have). Then, you need to have an ad-blocker installed too.

These two should deal with the pop-ups and ads situation. You can also use NoScript, which deals with scripts running on the sites, which can sometimes be malicious. Using NoScript requires a little bit of learning and getting used to, though.

Despite using these, if you have the problems of pop-ups, or unwanted sites opening in your browser, then most probably your computer is infected with some kind of malware. This should be dealt with by scan with the resident antivirus, or antispyware program like MalwareBytes Antimalware, or in case of severe infection, boot discs like Kaspersky Rescue Disc.

Dealing with the pop-ups, or unwanted sites editing the hosts file is one way to stop the sites from opening. But, what about the malware infection still on the computer which was causing the sites to open? That's still present. So, that infection will have to be removed, which can cause other problems.

hosts file is often used for blocking ad domain sites, which are well known to show ads, or other malicious sites. Often, such pre-made hosts files are available from security sites.

Quote:
Originally Posted by Melita-s View Post
I also found the fastest way to open and edit 'hosts'. I typed what I learned from "torres-no-tan-magnifico", i.e. notepad c:\windows\system32\drivers\etc\hosts in to an elevated Command Window, instead of the 'RUN' window. hosts opened in note-pad and new entry saved successfully!
Glad that worked out for you.

Quote:
Originally Posted by Melita-s View Post
I want to point out an error in the 'askvg. com' page. Please look at my attachments. 'hosts 1' shows the hosts file for Windows 7 and 8. This is not going to work because there is the # mark before 127.0.0.1 and ::1. When the hash is typed before the entry, Windows takes it as a 'comment' and ignores it. As you say, the user may lose the Internet connection.

Image 'hosts 2' shows the same entries for Vista, which are correctly typed. XP also there shows correct entry.
It is not an error. Actually, whether those lines are commented or not, it does not matter.

Quote:
127.0.0.1 localhost loopback
::1 localhost
These lines actually show two entries for resolution of the same address. This is just an example to show how the hosts file can be used, and also to show that an IP address may have multiple host names.

127.0.0.1 is the loopback address for the adapter. Often to check if the adapter is working, you can ping this address, and it should ping.

Since it is a loopback, often, this address is used to block sites from opening on the computer. This is how ad domains, and other malicious sites can be blocked... which is what you must be doing.

hosts file is mainly used for hostname resolution... but with modern networking system, it's not required, and these things are now managed by DNS on the internet.

However, hosts file is now used like above, to block sites, or, used for its original purpose in some networks.

So, it's not an error, and the system will be able to connect to internet just fine whether you comment those two lines or not. Those are just for example.

For example, on my Windows 8.1 system, those two lines are commented, but my system has no problem in connecting to the internet.
__________________
Anupam
Anupam is offline   Reply With Quote
Old 16. Nov 2014, 05:06 PM   #8 (permalink)
Senior Member
 
Melita-s's Avatar
 
Join Date: Dec 2012
Location: Canada
Posts: 636
Default

I am sorry for having said the wrong thing. I know for a fact that Windows ignores any entries made by the user if it is preceded by #. So I assumed that the localhost also needs to be entered without the hash. That is the way it is in Widows 7 (without #).

Quote:
Since it is a loopback, often, this address is used to block sites from opening on the computer. This is how ad domains, and other malicious sites can be blocked... which is what you must be doing
.

No, I don't use 127.0.0.1. I use some thing like 10.11.12.13. Any IP address like 192.168.77.88 or 10.11.12.13 or 172.16.17.18, which is not routable on the internet will do the trick. But if you use the hash before the entry, it definitely will not work. Ping test will show you that.

Quote:
hosts file is mainly used for hostname resolution... but with modern networking system, it's not required, and these things are now managed by DNS on the internet.
This must be the reason why we can have 127.0.0.1 with or without the hash.

Quote:
However, hosts file is now used like above, to block sites, or, used for its original purpose in some networks.
What kind of networks are they?

Quote:
So, it's not an error, and the system will be able to connect to internet just fine whether you comment those two lines or not. Those are just for example

For example, on my Windows 8.1 system, those two lines are commented, but my system has no problem in connecting to the internet
Yes, I just tried it in my Windows 7 and it also connects with a hash in front of 127.0.0.1. Interestingly, for some reason, the 'localhost' entry is the only entry without the hash, in the default hosts file in Window 7 and earlier. So, strictly speaking, if you use the hash in WIN 7, it is not the default file, as the web page claims. I know I am splitting hairs but I am like that when the subject is my computer.

Many thanks for the wealth of information in your reply

Kind regards,
__________________
Melita

Last edited by Melita-s; 16. Nov 2014 at 05:10 PM. Reason: to edit text
Melita-s is offline   Reply With Quote
Old 16. Nov 2014, 05:29 PM   #9 (permalink)
Super Moderator
 
Anupam's Avatar
 
Join Date: Jul 2008
Location: India
Posts: 15,323
Default

Quote:
Originally Posted by Melita-s View Post
I am sorry for having said the wrong thing.
No need to be sorry . We are all learning here. I myself consider myself just an above average users, and even I am learning. There are many things I don't know about computers.

Quote:
Originally Posted by Melita-s View Post
No, I don't use 127.0.0.1. I use some thing like 10.11.12.13. Any IP address like 192.168.77.88 or 10.11.12.13 or 172.16.17.18, which is not routable on the internet will do the trick. But if you use the hash before the entry, it definitely will not work. Ping test will show you that.
That's actually not the proper way .

To block a site on your computer... simply write this:

127.0.0.1 domain name

See details and explanation here:

http://www.guidingtech.com/4868/edit...lock-websites/

The above page also includes a link to a software called HostsMan, which makes the job easier.

Yes, putting a hash before any line will not work, because then the hosts file treats that line as a comment. It's helpful to put comments like that. And also, to temporarily disable blocking of site.

Quote:
Originally Posted by Melita-s View Post
What kind of networks are they?
These can be private networks, like in universities, etc.

Quote:
Originally Posted by Melita-s View Post
Yes, I just tried it in my Windows 7 and it also connects with a hash in front of 127.0.0.1. Interestingly, for some reason, the 'localhost' entry is the only entry without the hash, in the default hosts file in Window 7 and earlier. So, strictly speaking, if you use the hash in WIN 7, it is not the default file, as the web page claims. I know I am splitting hairs but I am like that when the subject is my computer.
Yes, the website might have made an error. Anyways, since it does not make any difference, it's not exactly an error .
__________________
Anupam
Anupam is offline   Reply With Quote
Old 17. Nov 2014, 04:49 PM   #10 (permalink)
Senior Member
 
Melita-s's Avatar
 
Join Date: Dec 2012
Location: Canada
Posts: 636
Default

Thank you for the link to 'guidingtec'. It gives a simple but good explanation of how the hosts file works, specially for people like me. I sometimes go to Wikipedia when I don't understand something but their explanations are so wrapped up in more technical language that I end up more confused than before

About 127.0.0.1, it is true that it blocks web sites when you use that. Also, every one who deals with the subject always mentions only 127.0.0.1 and nobody says anything about using a randomly made up IP.

At the same time, it is also true, if you use a random IP like I mentioned, it makes no difference to the outcome. The result is the same. The web site gets blocked just as if you used 127.0.0.1 I habitually use 10.11.12.13 Not only are the sites blocked without exception, but the ping tests also show negative ('request timed out; 4 packets lost' is what you get). I have done much experimenting with this. For instance, after using a random IP (not routable on the Internet) to block a website, and getting negative for a 'ping', I remove a single letter from that web address or put a hash in front or do something similar, I immediately get '4 packets sent; 4 packets received' for the ping test! When I change it back to the proper entry the ping is again negative. I am sure you are able to workout how and why this happens.

I picked up this information a few years ago from something I read but I have forgotten the source. There is also another reason why it is not advisable to use 127.0.0.1 I don't really understand what it means but it has something to do with a change Microsoft made in the "TCP loopback interface" , which slows down the computer if 127.0.0.1 is used to block web sites.

By the way, why do you think Microsoft left 'localhost' in the hosts file without the hash, when they included the hash in every single thing in that file. The only exception being the 'localhost'?

Best regards,
__________________
Melita

Last edited by Melita-s; 17. Nov 2014 at 05:01 PM. Reason: To add content
Melita-s is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT +1. The time now is 05:15 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.