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?
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:or
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.