Reputation: 233
I just moved my website to a different host and now wanted to add a line to my hosts file to see if everything is working correctly. But after editing i still get directed to the current host, but when i ping the url i get the new ip adres.
I have searched a lot and tried everything i could find but nothing is working.
My line in hosts file: 1.2.3.4 example.com www.example.com
I tested it on safari, firefox and chrome, cleared my cache,...
On a windows pc i easily get it to work, but i would like to get it working on my mac. Any suggestions?
Upvotes: 0
Views: 3071
Reputation: 51
Look at System Preferences -> Network
If the currently active "Location" has one or more DNS servers listed then the system will create the file "/etc/resolv.conf" which will list those nameservers as the place to go for resolution, bypassing /etc/hosts entirely
resolv.conf is created dynamically by "Network" prefs, and overwritten based on the "DNS Server" field of the currently active "Location" or removed if that field is blank
Upvotes: 0
Reputation: 125708
I have two guesses:
Are you using a web proxy (including transparent proxy and some types of firewall)? If so, the DNS lookup is being done on the proxy server, and ignoring what you have in your /etc/hosts file.
Is the /etc/hosts line formatted exactly right? If it's even a little bit off (including having invisible characters in it), it won't work right. You can check with LC_ALL=C cat -vet /etc/hosts
, which will convert any nonprinting characters into a printing (visible) representation. You entry should look like one of these:
1.2.3.4^Iexample.com^Iwww.example.com$
or
1.2.3.4 example.com www.example.com$
The ^I
s are a printable representation of a tab character, and the $
represents the linefeed that indicates the end of the line. If the line ends with ^M$
, then you've somehow gotten a DOS/Windows-format line in there (Windows text editor? File copied from Windows?), with a carriage return (the ^M
) as well as linefeed at the end of the line, and the Mac is thinking the carriage return character is part of the domain name you're defining.
Upvotes: 2