Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit hosts file via CMD? [closed]

Tags:

Hello I'd like to block some websites directly from the command prompt.

echo like this:

0.0.0.0 websitename.com 

How can I do this? (OS: Windows 7)

like image 864
omnix Avatar asked Nov 19 '10 04:11

omnix


People also ask

Do not have permission to edit hosts file?

Locate hosts file, right-click it and choose Properties. Navigate to the Security tab and click the Edit button. You should see the list of users and groups on your PC that have access to the hosts file. If your user name or group is on the list, click it and make sure that it has Permissions set to Full control.

Does editing hosts file require restart?

You don't need to reboot. Any changes you make to the hosts file are immediate. You used to need to reboot for changes to take effect in Windows 9x.

How do I access my host file?

Click File in the menu bar at the top of Notepad and select Open. Browse the Windows Hosts File location: C:\Windows\System32\Drivers\etc and open the hosts file.


2 Answers

echo 0.0.0.0 websitename.com >> %WINDIR%\System32\Drivers\Etc\Hosts

the >> appends the output of echo to the file.

Note that there are two reasons this might not work like you want it to. You may be aware of these, but I mention them just in case.

First, it won't affect a web browser, for example, that already has the current, "real" IP address resolved. So, it won't always take effect right away.

Second, it requires you to add an entry for every host name on a domain; just adding websitename.com will not block www.websitename.com, for example.

like image 98
Andrew Barber Avatar answered Oct 12 '22 11:10

Andrew Barber


Use Hosts Commander. It's simple and powerful. You can download it here.

Examples of using

hosts add another.dev 192.168.1.1 # Remote host hosts add test.local # 127.0.0.1 used by default hosts set myhost.dev # new comment hosts rem *.local hosts enable local* hosts disable localhost 

...and many others...

Help

Usage:     hosts - run hosts command interpreter     hosts <command> <params> - execute hosts command  Commands:     add  <host> <aliases> <addr> # <comment>   - add new host     set  <host|mask> <addr> # <comment>        - set ip and comment for host     rem  <host|mask>   - remove host     on   <host|mask>   - enable host     off  <host|mask>   - disable host     view [all] <mask>  - display enabled and visible, or all hosts     hide <host|mask>   - hide host from 'hosts view'     show <host|mask>   - show host in 'hosts view'     print      - display raw hosts file     format     - format host rows     clean      - format and remove all comments     rollback   - rollback last operation     backup     - backup hosts file     restore    - restore hosts file from backup     recreate   - empty hosts file     open       - open hosts file in notepad 
like image 24
VEG Avatar answered Oct 12 '22 11:10

VEG