Windows - etc/hosts configuration not working - windows

I made this entry in my C:\windows\system32\drivers\etc\hosts file:
convert2mp3.net convert2mp3.com
so that my browser always calls convert2mp3.net instead of convert2mp3.com if i accidentially call convert2mp3.com
But it does not work. I also flushed the DNS cache by executing ipconfig /flushdns in the CMD. I also tried to use another browser but still no redirect.
What am I doing wrong?

The /etc/host file is used to force the resolution of a domain to a specified IP Address. Your line is missing the ip Address help for win7
It should be:
127.0.0.1 mywebsite

You cannot change DNS names like that, especially not in an HTTP context.
So the problem is you sometimes type a .com address in your browser where the site you want to go to actually is at the same address - only ending in ".net".
Even if you could change the hosts file to let the .com address point to the .net server's address, the request is likely to return an error, because their server isn't configured to handle requests to the .com address, which your browser will still send as a host header.
So create a bookmark in your browser and click that, instead of typing DNS addresses yourself if you're making that mistake that often.

Related

Create an alias for a website with /etc/hosts

At work we have a series of aliases for websites like repositories etc. and they are used by typing something like open/repo in the browser.
I wanted to create something like this at my private PC and found out I could add a line to /etc/hosts file and it looks like this:
172.217.16.46 gl
Now what I would expect is to type gl in any browser and it would redirect me to google.com, but unfortunately I get 404 errors on every browser. The only answers I found were browser specific, like this one for Chrome, where other browsers actually work as expected.
What I tried:
I've run ipconfig /flushdns in cmd (on admin rights)
I put http:// before the alias in Chrome
Note:
I would like to keep all the changes locally on my machine (without changing router configuration etc.)
If you are getting a 404 error, the problem is probably not that DNS resolution is failing but that your address is wrong. It sounds like you have tried to point gl to Google's IP. That would cause your request to hit Google's server, but Google will probably reject it since it is labeled addressed to gl instead of google.com in the HTTP request.
This phenomenon happens because it is common for web servers to host different websites on the same IP only with different domain names. I believe the term for these is "virtual host".
At any rate, try pointing to an IP that takes any name to access the website, or otherwise you are probably looking for some kind of redirect instead of A record DNS.

Hosts file how do I allow only one domain name

I'm setting up an iMAC in a store. They want to have the browser open to their website and restrict access so people can't use the computer to browse any other site. I see many discussions online but no actual code sample. Can you please write out the exact lines of code that I need to add to the hosts file and its location on a new iMAC with OS X.
You can achieve this by catching all web traffic and routing it to the IP address of the site you want to limit access to.
For example: If the website IP was 10.0.0.1
10.0.0.1 .com
10.0.0.1 .info
10.0.0.1 .org
(You can keep adding rows for each TLD (.com, .net etc) that you wish to block.
Any http requests sent from the machine would then try to resolve on that host.
This should prevent other websites from resolving but the one you require.

why does my domain name immediately switch to showing its ip address once page loads?

I just registered a new domain name and set it to point to an AWS EC2 instance. When I enter the domain name, it loads fine, but then as soon as the page loads, the browser address text is updated to show the ip address (replaces the domain name). I cloned this EC2 from another server where this was not happening and where I hadn't done any non-default Apache2 server settings other than URL shortening to remove .html and .php file extensions. Any ideas what could be happening here? I tried it on multiple computers and multiple browsers.
Sounds like your webserver is issuing a redirect after the first connection is made, and the redirect is pointed to the IP adress of the server. You can get more information to confirm this by using Chrome Network Console.
In this case I had mistakenly updated the DNS record for forwarding rather than for the # tag, so it was forwarding to the site.

I changed hosts file but can't see effects

I have to reach the wordpress platform installed by a certain hosting service, so I can build a new website (that will replace the old one), on a certain IP address. I changed my hosts file under their instructions. I put in it the IP address that they had given me and the website domain (separated by a single space). The hosts file hasn't any extension and it's in the right location (System32/drivers/etc - I'm on Windows 8). I cleaned browser and local DNS cache but nothing change: if I put in the browser the url they had given me (www.domain.com/?hostingname) I see the old website, not the wordpress platform. I tried to ping the domain and it returns a different IP address. What can I do? Thanks everyone in advance.
Ok, I solved. It's important to edit the hosts file with Windows Notepad and not with Notepad++

Difference between specifying IP in host file vs using IP directly

Is there any difference between the following when a intranet URL in accessed in IE
Add an entry in drivers/etc/host file for a name and IP
vs
Use IP directly
e.g. it works with the following link if I have a host entry as (XYZ 10.0.10.200)
http://XYZ/SiteDirectory/ABC/Default.aspx
but when I tried to use IP instead of name
http://10.0.10.200/SiteDirectory/ABC/Default.aspx
It gives me 404 not found error
Yes, there's a difference.
The web server is using HTTP/1.1 and "shared virtual hosting". When the client connects it sends an additional Host: header which contains the hostname part of the URL that the user supplied.
The web server looks at the header to find out which virtual host's data to serve.
In this case, the web server is configured to recognise and serve content from the "XYZ" domain, but doesn't know about any domain called 10.0.10.200
Smells like the webserver is using virtual hosts, so that it serves different pages if the client went to "www.foo.com" or "www.bar.com", even though they have the same IP-address.
As far as I can see there should be no difference. With a host name the order is hosts file before DNS so it should be used.
Is there another line in the host file with the same hostname?
What happens when you do a tacert? (trace route)

Resources