My MacBook in office does not have internet access. So I set up an instant SOCKS Proxy over SSH to surf the web.
However, when I try to add an entry to
/etc/hosts, the browser does not go to the site I expected ...
My MacBook's WIFI is off and is connected to the company LAN:
IP address: 192.168.8.250 Subnet mask: 255.255.255.0 Router: 192.168.8.1 DNS server: 184.108.40.206
Be default, there is not internet access.
There a Linux development box (192.168.12.128) which has access to the internet, so I set up an instant SOCKS proxy to gain internet access for my MacBook:
ssh -fND localhost:30000 firstname.lastname@example.org
Then in my MacBook's System Preferences > Network > Proxies
(Enable) SOCKS Proxy SOCKS Proxy sever: 127.0.0.1:30000 Bypass proxy settings for these Hosts & Domains: *.local, 169.254/16, 127.0.0.1
Now I can surf the web, so far so good.
For development, I set up a few entries in
/etc/hosts for virtual hosts purpose:
$ ping air.company.com PING air.ohho.es (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.046 ms $ curl air.company.com <html>OK</html>
It looks good and
curl returns the content of the
However, if I try to open the site:
http://air.company.com in the browsers (Safari/Chrome/Firefox), none of them returns the result like
curl did. Chrome give an error:
This webpage is not available The webpage at http://air.company.com/ might be temporarily down or it may have moved permanently to a new web address. Error 120 (net::ERR_SOCKS_CONNECTION_FAILED): Unknown error.
If I add another entry in
$ ping www.microsoft.com PING www.microsoft.com (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.047 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.128 ms ^C --- www.microsoft.com ping statistics --- 2 packets transmitted, 2 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 0.047/0.087/0.128/0.041 ms $ curl www.microsoft.com <html>OK</html>
However, the browsers returns the content from the web server of the real Microsoft site, instead of the content from my MacBook (127.0.01). Why?
If I disable the SOCKS proxy, the browser returns the content from 127.0.0.1 correctly.
If I disconnect the LAN cable, the browser returns the content from 127.0.0.1 correctly.