Squid+Stunnel 翻墙看世界

加密代理功能的实现,越过封锁限制,访问被墙的国外站点,比如Google、FaceBook。

一、首先是国外的服务器安装squid和stunnel

1.安装Squid

yum -y install squid

也不用修改配置,因为单单squid代理根本翻不了墙,所以需要一个加密的通道,stunnel,而stunnel只需要连接localhost的squid端口即可。

2.安装Stunnel

yum -y install stunnel openssl openssl-devel

生成pem证书:

cd /etc/stunnel/
openssl req -new -x509 -days 365 -nodes -out stunnel.pem -keyout stunnel.pem
openssl gendh 512>> stunnel.pem #警告:这行不是必须的
useradd -s /sbin/nologin -M stunnel

修改/etc/stunnel/stunnel.conf(stunnel默认的配置文件),复制以下内容:

cert = /etc/stunnel/stunnel.pem
CAfile = /etc/stunnel/stunnel.pem
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1

;;;chroot = /var/run/stunnel
pid = /tmp/stunnel.pid
verify = 3

;;; CApath = certs
;;; CRLpath = crls
;;; CRLfile = crls.pem

setuid = stunnel
setgid = stunnel

;;; client=yes
compression = zlib
;;; taskbar = no
delay = no
;;; failover = rr
;;; failover = prio
sslVersion = TLSv1
;;; fips=no

debug = 7
syslog = no
output = stunnel.log

[sproxy]
accept = 34567
connect = 127.0.0.1:3128

accept = 34567 是 stunned要监听的端口号

connect = 127.0.0.1:3128 是Squid的监听地址和端口

在参考的原文中 fips=no 是未被注释的,但在我机器上此参数导致不能启动,所以我才注释掉,如遇到无法启动,可去掉注释。

3.启动squid和stunnel

service squid start
stunnel

如果没有错误输出表示配置成功,并可以使用以下命令查看是否启动成功。

ps aux | grep -E "squid|stunnel"
netstat -an | grep “LISTEN” | grep -E "squid|stunnel"

二、国内服务器:

只需要安装stunnel(yum -y install stunnel openssl-devel),将国外服务器生成的stunnel.pem复制过来,唯一的不同在于配置文件中 sproxy那段,编辑stunnel.conf:

cert = /etc/stunnel/stunnel.pem
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
verify = 2
CAfile = /etc/stunnel/stunnel.pem
client=yes
compression = zlib
ciphers = AES256-SHA
delay = no
failover = prio
sslVersion = TLSv1
;; fips = no
[sproxy]
accept  = 0.0.0.0:7071
connect = 国外服务器IP:34567

解释说明: accept = 0.0.0.0:7071 即是用户要设置的端口, connect = 国外服务器IP:34567 ,即国外服务器IP和Stunnel监听的端口号

启动stunnel

stunnel

此时用户连接到国内服务器7071作为代理就可以访问一些被墙的网站。

在国内没有服务器,可以我在本地安装的一个Stunnel,用来加解密,所以没有国内服务也不要紧。

去stunnel官网下载一个windows版的客户端,将上面国内服务器的stunnel.conf配置文件和国外服务器stunnel.pem证书放到stunnel安装目录/config/下启动即可。

 

原文:https://staugur.gitbooks.io/saintic/content/blog/28.html

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s