Skip to content

Instantly share code, notes, and snippets.

@zenorocha
Last active April 11, 2024 23:07
Show Gist options
  • Save zenorocha/18b10a14b2deb214dc4ce43a2d2e2992 to your computer and use it in GitHub Desktop.
Save zenorocha/18b10a14b2deb214dc4ce43a2d2e2992 to your computer and use it in GitHub Desktop.
/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.
@cacarr-pdxweb
Copy link

Yeah, just to give it's own thread, there is a great little app to edit Windows hosts files (as well as swap them on the fly, ping endpoints, cut/copy/paste multiple entries, and disable/enable entries using check-boxes). It's called (brace yourselves, it's a super creative title): Hosts File Editor

image

Very nice. If I'm ever stuck on Windows (so straightforward on Linux), I'll install that.

@logbasex
Copy link

logbasex commented Jun 3, 2020

Thank you, but is there any idea about using the command line? I feel pretty uncomfortable with this solution.

@trainingbasket01
Copy link

Your post is very great.I read this post. It's very helpful. I will definitely go ahead and take advantage of this. Cheers for sharing with us your blog.
Python training in Noida
https://www.trainingbasket.in

@joaoldomingos
Copy link

Thank you, very good tutorial

Copy link

ghost commented Jun 16, 2020

Thank you, but is there any idea about using the command line? I feel pretty uncomfortable with this solution.

@hophiducanh : if you want to do everything from the command line, you need to install some form of 3rd party line editor (ported from Linux or other flavors of UNIX) to be able to edit the file. You would also need to make sure that the file is not in use by other apps or services, as well as making sure that the file is not write protected.

@loRes228
Copy link

hostname -I
😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment