Windows終端,Linux設定代理
阿新 • • 發佈:2018-12-06
Windows端:
輸入下面指令
set HTTP_PROXY=http://127.0.0.1:1080
set HTTPS_PROXY=https://127.0.0.1:1080
然後:
curl.exe -vv www.google.com
會有如下:
* Rebuilt URL to: www.google.com/ * Trying 127.0.0.1... * TCP_NODELAY set * Connected to 127.0.0.1 (127.0.0.1) port 1080 (#0) > GET http://www.google.com/ HTTP/1.1 > Host: www.google.com > User-Agent: curl/7.55.1 > Accept: */* > Proxy-Connection: Keep-Alive > < HTTP/1.1 200 OK < Date: Sun, 30 Sep 2018 05:00:54 GMT < Expires: -1 < Cache-Control: private, max-age=0 < Content-Type: text/html; charset=ISO-8859-1 < P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info." < Server: gws < X-XSS-Protection: 1; mode=block < X-Frame-Options: SAMEORIGIN < Set-Cookie: 1P_JAR=2018-09-30-05; expires=Tue, 30-Oct-2018 05:00:54 GMT; path=/; domain=.google.com < Set-Cookie: NID=140=raFGjxxCNdYyaiTPhO5I5KJ_A8HG98EWivfKYlhtidIqE_KksY8MJzJLTCMRE4xz1PFUDIGTcDLnaCI9brm0-cwALIyKra1x0nkpqyWe57H5ihq-4vyY0OfydlOHl4m-; expires=Mon, 01-Apr-2019 05:00:54 GMT; path=/; domain=.google.com; HttpOnly < Accept-Ranges: none < Vary: Accept-Encoding < Connection: close < <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="OLUp6EEIFhGQShPxVk2zJg==">(function(){window.google={kEI:'hliwW9XVNcfYvASQj4OoAg',kEXPI:'0,1353747,57,1369 ... ... b=window.innerHeight;if(!a||!b){var c=window.document,d="CSS1Compat"==c.compatMode?c.documentElement:c.body;a=d.clientWidth;b=d.clientHeight}a&&b&&(a!=google.cdo.width||b!=google.cdo.height)&&google.log("","","/client_204?&atyp=i&biw="+a+"&bih="+b+"&ei="+google.kEI);}).call(this);})();</script><div id="xjsd"></div><div id="xjsi"><script nonce="OLUp6EEIFhGQShPxVk2zJg==">(function(){function c(b){window.setTimeout(function(){var a=document.createElement("script");a.src=b;google.timers&&google.timers.load.t&&google.tick&&google.tick("load",{gen204:"xjsls",clearcut:31});document.getElementById("xjsd").appendChild(a)},0)}google.dljp=function(b,a){google.xjsu=b;c(a)};google.dlj=c;}).call(this);if(!google.xjs){window._=window._||{};window._DumpException=window._._DumpException=function(e){throw e};window._F_installCss=window._._F_installCss=function(c){};google.dljp('/xjs/_/js/k\x3dxjs.hp.en_US.gfUd3gGLV_0.O/m\x3dsb_he,d/am\x3dYmA2/rt\x3dj/d\x3d1/rs\x3dACT90oHvOIimbVzFWVCBD4BW8X11VvhzZA','/xjs/_/js/k\x3dxjs.hp.en_US.gfUd3gGLV_0.O/m\x3dsb_he,d/am\x3dYmA2/rt\x3dj/d\x3d1/rs\x3dACT90oHvOIimbVzFWVCBD4BW8X11VvhzZA');google.xjs=1;}google.pmc={"sb_he":{"agen":true,"cgen":true,"client":"heirloom-hp","dh":true,"dhqt":true,"ds":"","ffql":"en","fl":true,"host":"google.com","isbh":28,"jsonp":true,"msgs":{"cibl":"Clear Search","dym":"Did you mean:","lcky":"I\u0026#39;m Feeling Lucky","lml":"Learn more","oskt":"Input tools","psrc":"This search was removed from your \u003Ca href=\"/history\"\u003EWeb History\u003C/a\u003E","psrl":"Remove","sbit":"Search by image","srch":"Google Search"},"ovr":{},"pq":"","refpd":true,"rfs":[],"sbpl":24,"sbpr":24,"scd":10,"sce":5,"stok":"LV27IvCUv9DJcQMYpc72Q-cfoQw","uhde":false},"d":{},"ZI/YVQ":{},"Qnk92g":{},"U5B21g":{},"DPBNMg":{},"YFCs/g":{}};google.x(null,function(){});(function(){var r=[];google.plm(r);})();(function(){var m=[] ;google.jsc && google.jsc.m(m);})();</script></div></body></html>* Closing connection 0
大家會用ping命令ping不通,因為Ping是ICMP協議,不是TCP/UDP協議,Ping不走,也無法走代理。
由於Linux下SS客戶端僅代理socks5協議的流量(如果不是這個原因懇請指正)。所以想在LX終端使用代理,需要在SS的socks5流量前再接一個代理,允許http、https、ftp協議流量通過。
我們也假定本地socks5代理為127.0.0.1:1080
安裝polipo
Debian下直接使用apt命令安裝:
sudo apt update
sudo apt install polipo
編輯配置檔案:
sudo nano /etc/polipo/config
# This file only needs to list configuration variables that deviate # from the default values. See /usr/share/doc/polipo/examples/config.sample # and "polipo -v" for variables you can tweak and further information. logSyslog = true logFile = /var/log/polipo/polipo.log proxyAddress = "0.0.0.0" socksParentProxy = "127.0.0.1:1080" socksProxyType = socks5 chunkHighMark = 50331648 objectHighMark = 16384 dnsQueryIPv6 = no
按CTRL+X,Y儲存退出。
重啟polipo服務:
sudo service polipo restart
啟用代理
通過 service polipo status
命令,我們可以看到新的監聽埠為8123。
因此,LX終端啟用代理的命令為:
export http_proxy=http://127.0.0.1:8123
export https_proxy=http://127.0.0.1:8123
export ftp_proxy=http://127.0.0.1:8123
同樣,直接輸入上述命令設定的代理也是臨時的。一個比較實用的方法是在~/.bashrc檔案中設定環境,之後就不需要再手動設定了。
sudo nano ~/.bashrc
在檔案最後插入上述三條指令,儲存。
測試 wget
指令: