4
2
I'm looking to edit the Windows TCP/IP hosts file (at c:\windows\system32\drivers\etc\hosts
). I'm wondering, what is the best way to do this (on Windows XP)?
Let's say that I want to redirect, say, the site a.com to google.com. I can find the IP address of a.com, but what is the correct way to edit the HOSTS file? I'm thinking of using this syntax:
this.is.ip.address google.com
However, two things:
- Is this the correct syntax? If so, is there a way to do it without having to find the IP address of a.com? Would just putting a.com into where the IP address currently is work?
- What is the best way to edit this file? I can't save to it because it is in use. Normally under these circumstances, I would go into Safe Mode and edit it from there, but is there an easier way (I'm thinking of killing some system processes...)?
One small addition as a comment, as it is not answering your question: In your sample, the user would call google.com from their browser, and would get redirected to a different IP address as specified in your hosts file. However, the browser will still send the
Host
header value asgoogle.com
- so the webserver behind the different IP address will need to be able to handle that. Just redirecting to e.g. Bing's IP might not work, as their webserver might not acceptHost: google.com
. – BennyInc – 2011-09-15T12:37:04.5771I've never had a problem editing the HOSTS file from Notepad (Start > Run > notepad c:\windows\system32\drivers\etc\hosts). Are you running some AV program that's keeping it locked? – quack quixote – 2009-10-04T01:27:23.090
oopsey, i was confusing myself because im on a vista comp right now. thanks @quack – Maxim Zaslavsky – 2009-10-04T01:33:20.057
yeah, it only appears locked because you didn't try to edit it with admin privs. start notepad.exe as admin, then you can edit it fine – davr – 2009-10-04T04:56:56.573