Il mio MacBook in ufficio non ha accesso a Internet. Così ho installato un proxy SOCKS istantaneo su SSH per accedere a StackOverflow. Uso principalmente il mio MacBook per lo sviluppo, quindi mi affido a /etc/hosts
e agli host virtuali per testare alcuni siti localmente.Perché il mio script segue/etc/hosts ma i browser non lo fanno, quando c'è un proxy SOCKS?
Tuttavia, quando provo ad aggiungere una voce al /etc/hosts
, il browser non andare sul sito che mi aspettavo ... WIFI
mio MacBook è spento ed è collegato alla LAN aziendale:
IP address: 192.168.8.250
Subnet mask: 255.255.255.0
Router: 192.168.8.1
DNS server: 8.8.8.8
Be default, non c'è accesso a internet.
C'è una scatola di sviluppo di Linux (192.168.12.128), che ha accesso a internet, così ho creato un proxy SOCKS istante per ottenere l'accesso a Internet per il mio MacBook:
ssh -fND localhost:30000 [email protected]
poi nella mia Preferenze di Sistema di MacBook > Rete> 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
Ora posso navigare sul Web, finora tutto bene.
Per lo sviluppo, ho creato un paio di voci in /etc/hosts
per gli host scopo virtuale:
127.0.0.1 air.company.com
In bash
:
$ 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>
Sembra buono e curl
restituisce il contenuto del index.html
bene.
Tuttavia, se provo ad aprire il sito: http://air.company.com
nei browser (Safari/Chrome/Firefox), nessuno di loro restituisce il risultato come curl
. Chrome dare un errore:
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.
Se posso aggiungere un'altra voce nel /etc/hosts
:
127.0.0.1 www.microsoft.com
In bash
, sembra OK:
$ 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>
cerco anche utilizzando script Ruby:
require 'socket'
require 'curl'
ip = IPSocket.getaddress('www.microsoft.com')
puts ip
puts
http = Curl.get("http://www.microsoft.com/")
puts http.body_str
L'output è OK:
$ bundle exec ruby openweb.rb
127.0.0.1
<html>OK</html>
Tuttavia, quando uso i browser, i browser restituiscono il contenuto dal server web del sito vera Microsoft, invece che il contenuto del mio MacBook (127.0.01) . Perché?
P.S .:
Se rendo invalido il proxy SOCKS, il browser restituisce il contenuto da 127.0.0.1 correttamente.
Se disconnetto il cavo LAN, il browser restituisce correttamente il contenuto da 127.0.0.1.