用Squid在SSH開啟個Tunnel代理

這是icyboy自己想出來的想法,並在google和一些國外大神的幫助下,總算搞清楚了如何操作。

總所周知,squid是一個非常出色的HTTP代理軟體,常用於用於CDN分發、Load Balance等高端伺服器操作。現在,我們大材小用,把它用來鑽洞翻牆。據身在國內的icyboy說,他測試下來的結果,squid使用效率比SSH動態轉發高效得多,當然這得歸功於squid本身了。

首先,我們需要一台能在國內訪問的國外VPS或者獨立主機,日美韓三國的速度比較不錯。部落格里有很多賣vps的商家推薦,建議自己去看看。

第二,VPS需是Linux系統,Windows配置這裡不講。原理是通過SSH映射本機一個連線埠到伺服器上squid的一個連線埠,這樣,我們的代理就直接通過了SSH的加密,省下了不少GFW關鍵字重置的麻煩。

配置過程:

使用SSH命令安裝squid,本例只拿Debian做一個例子。

apt-get install squid

安裝好後直接修改/etc/squid/squid.conf的配置文件,如下內容:

# Recommended minimum configuration:
#
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
acl all src 0.0.0.0/0.0.0.0

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
#acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
#acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
#acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
#acl localnet src fc00::/7 # RFC 4193 local private network range
#acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT

#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager

# Deny requests to certain unsafe ports
#http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
#http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
#http_access allow localnet
http_access allow localhost
acl INTRANET dstdomain .intranet.example.com critical.example.com
http_access allow INTRANET
append_domain .domainname.com

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 800 16 256
cache_mem 500 MB

# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid

# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320

其實最複雜的部分就是配置squid的過程,現在已經簡化好了。這個配置里需要重點注意的是三行:
acl INTRANET dstdomain .intranet.example.com critical.example.com
http_access allow INTRANET
http_access deny all
除了本機,拒絕其他任何形式的連接。小老外在第三行這裡吃過虧,deny all機器認不出來。我就在上面的配置文件里加上了一行acl all src 0.0.0.0/0.0.0.0就能用了。icyboy的配置並沒有這一行。如果你最後的測試結果有問題,可以試著把這行去掉。Squid的連線埠可以自己改,不一定要默認的3128。記得修改完配置後/etc/init.d/squid restart重啟一下squid。

好了之後,下載plink.exe,在相同資料夾下創建一個bat批處理,命令行如下:

plink.exe -2 -P 22 -pw sshpassword -L localhost:9090:localhost:3128 username@serverIPaddress
命令中-p是連線埠號,如果你的SSHd連線埠被修改過,請自己更改。sshpassword是你的ssh密碼,最後一個username@serverIPaddress我不多講了吧。9090是本機映射的連線埠,3128是伺服器squid連線埠。

然後是本機設置。
Firefox可以通過外掛程式或者直接設置,通過HTTP代理來獲得翻牆功能。Chrome建議大家裝個Switchy!中文漢化版,在裡面新建一個squid的配置。具體也不多講了吧,這步是最簡單的了。

其實Squid除了用SSH加密之外,還可以用SSL加密,具體操作類似,配置不同而已。在伺服器443連線埠開個squid,把所有流量都代理出去。想試試的就直接Google吧。

轉載自 https://www.d0z.net/archives/5583/

原文鏈接:https://allinfa.com/zh-tw/squid-ssh-tunnel.html
原文標題:用Squid在SSH開啟個Tunnel代理 - 美博園
美博園文章均為「原創 - 首發」,請尊重辛勞撰寫,轉載請以上面完整鏈接註明來源!
軟體著作權歸原作者!個別轉載文,本站會註明為轉載。

:後文 »

網 友 留 言

1條評論 in “用Squid在SSH開啟個Tunnel代理”

這裡是你留言評論的地方


請留言


4 + 3 =
【您可以使用 Ctrl+Enter 快速發送】
Copyright © 2007 - 2025 , Design by 美博園. 著作權所有. 若有著作權問題請留言通知本站管理員. 【回到頂部】