Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/etc/hosts on Windows

1. Get your IP Address

echo `ifconfig $(netstat -nr | grep -e default -e "^0\.0\.0\.0" | head -1 | awk '{print $NF}') | grep -e "inet " | sed -e 's/.*inet //' -e 's/ .*//' -e 's/.*\://'`

2. Modify your hosts file

notepad

For Windows 10 and 8
  1. Press the Windows key.
  2. Type Notepad in the search field.
  3. In the search results, right-click Notepad and select Run as administrator.
  4. From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
  5. Make the necessary changes to the file.
  6. Click File > Save to save your changes.
For Windows 7 and Vista
  1. Click Start > All Programs > Accessories.
  2. Right-click Notepad and select Run as administrator.
  3. Click Continue on the Windows needs your permission UAC window.
  4. When Notepad opens, click File > Open.
  5. In the File name field, type C:\Windows\System32\Drivers\etc\hosts.
  6. Click Open.
  7. Make the necessary changes to the file.
  8. Click File > Save to save your changes.
For Windows NT, Windows 2000, and Windows XP
  1. Click Start > All Programs > Accessories > Notepad.
  2. Click File > Open.
  3. In the File name field, type C:\Windows\System32\Drivers\etc\hosts.
  4. Click Open.
  5. Make the necessary changes to the file.
  6. Click File > Save to save your changes.
@ashikcse20

This comment has been minimized.

Copy link

commented Sep 9, 2018

Thanks.

@metalgina

This comment has been minimized.

Copy link

commented Sep 27, 2018

wow, well, you guys seem to be having all this fun editing your 'hosts' file, the problem is, and I'm running windows 7 because windows 10 is absolute GARBAGE, I, for the life of me, can't SAVE the file!! I've tried it in DOS, I've tried using cmd, I've tried powershell, I've tried just using notepad, I've tried attribing it to different attribs to make it so I can write to the file, I've even tried editting the autoexec.bat to edit the file to add the correct address for my WMP and NOTHING!! I am so frustrated! I've been working on this thing for three hours I'm ready to light my computer on fire and run down the street naked!!! HELP!!!!

@Benjaminlooi

This comment has been minimized.

Copy link

commented Sep 29, 2018

@metalgina try cmd, powershell, notepad with Administrative privaledges?

@marieclairembanga

This comment has been minimized.

Copy link

commented Oct 25, 2018

I can't see the repo etc in notepad. Additionally when i navigate on my explorer I see the file hosts but it's encoding when I open it

@Evil-cluster

This comment has been minimized.

Copy link

commented Oct 27, 2018

To edit the hosts file in Windows 10 you need to do it from another OS, no matter if it is a live USB or just another OS in your computer, this is due to the fact that the system automatically opens this file just when you start your machine, and therefore it cannot be modified at the same time. To override this, you only need to do what I just mentioned, so that the hosts file doesn't get open and you can easily modify it. The same happens with the rest of the system files.
I hope I'm helpful.

@JoelAzaria

This comment has been minimized.

Copy link

commented Oct 29, 2018

To edit the hosts file in Windows 10 you need to do it from another OS, no matter if it is a live USB or just another OS in your computer, this is due to the fact that the system automatically opens this file just when you start your machine, and therefore it cannot be modified at the same time. To override this, you only need to do what I just mentioned, so that the hosts file doesn't get open and you can easily modify it. The same happens with the rest of the system files.
I hope I'm helpful.

I'm on windows 10 and have customers on Win10. I see zero evidence that any of this has any basis in reality.
I edit my hosts file just fine from an admin cmd prompt.

@lopugit

This comment has been minimized.

Copy link

commented Nov 9, 2018

To edit the hosts file in Windows 10 you need to do it from another OS, no matter if it is a live USB or just another OS in your computer, this is due to the fact that the system automatically opens this file just when you start your machine, and therefore it cannot be modified at the same time. To override this, you only need to do what I just mentioned, so that the hosts file doesn't get open and you can easily modify it. The same happens with the rest of the system files.
I hope I'm helpful.

bro you are cooked

@lopugit

This comment has been minimized.

Copy link

commented Nov 9, 2018

To edit the hosts file in Windows 10 you need to do it from another OS, no matter if it is a live USB or just another OS in your computer, this is due to the fact that the system automatically opens this file just when you start your machine, and therefore it cannot be modified at the same time. To override this, you only need to do what I just mentioned, so that the hosts file doesn't get open and you can easily modify it. The same happens with the rest of the system files.
I hope I'm helpful.

I'm on windows 10 and have customers on Win10. I see zero evidence that any of this has any basis in reality.
I edit my hosts file just fine from an admin cmd prompt.

@frankarma is cooked

@beanstalkim

This comment has been minimized.

Copy link

commented Nov 15, 2018

wow, well, you guys seem to be having all this fun editing your 'hosts' file, the problem is, and I'm running windows 7 because windows 10 is absolute GARBAGE, I, for the life of me, can't SAVE the file!! I've tried it in DOS, I've tried using cmd, I've tried powershell, I've tried just using notepad, I've tried attribing it to different attribs to make it so I can write to the file, I've even tried editting the autoexec.bat to edit the file to add the correct address for my WMP and NOTHING!! I am so frustrated! I've been working on this thing for three hours I'm ready to light my computer on fire and run down the street naked!!! HELP!!!!

I had the same problem. The workaround is pretty simple, copy the file to your desktop, edit it, then move it back.

Don't ask me why. :)

@priteshjha4u

This comment has been minimized.

Copy link

commented Nov 26, 2018

Alright, Do i need to restart my system after making the changes? It doesn't seem to be working instantly.

@JonBee

This comment has been minimized.

Copy link

commented Nov 27, 2018

@beanstalkim @metalgina The hosts file is owned by SYSTEM. In order to edit it with notepad, you'll need to run notepad as an administrator.

@priteshjha4u Running "ipconfig /flushdns" in command prompt should force Windows to reload the hosts file, if I remember correctly.

@ncolsens

This comment has been minimized.

Copy link

commented Dec 29, 2018

The hosts file works with all versions of windows, in most operating systems use a hosts file including your android phone. When editing the hosts file simply make the changes and then save the file, but since windows will not allow you to save it where it resides, save it to your desktop and then manually copy it to C:\windows\system32\drivers\etc. You will be prompted to overwrite the file select yes. Remember when you finish editing the hosts file to strip off the extension ".txt" for it to work. There is no need to reboot your system, just close and re-open your browser of choice. When editing the host file on android phones you will need to reboot the phone. for the changes to take effect

Additionally do not use your WAN IP in the hosts file. you should use either
0.0.0.0
or
127.0.0.1

Your IP address can change too often

@bala0406

This comment has been minimized.

Copy link

commented Jan 19, 2019

thanks..it worked.

@BunnyImran

This comment has been minimized.

Copy link

commented Feb 12, 2019

@beanstalkim
Thanks your solution worked!

@x011

This comment has been minimized.

Copy link

commented Feb 13, 2019

Don't forget to issue :

ipconfig /flushdns

To flush cached ip's

@FortniteGod52

This comment has been minimized.

Copy link

commented Apr 10, 2019

this is not true

@FortniteGod52

This comment has been minimized.

Copy link

commented Apr 10, 2019

https://en.wikipedia.org/wiki/Get_a_Life_(TV_series) this is where you should go lol!!! hahahahahahahahahahahahahahahahaahahaahahahaahahahahhahahahhahhahhahahahah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.