在《Centos 7 搭建 socks5 代理服务器》这篇博文中,我们介绍了如何利用 shadowsocks 搭建一个 socks5 代理服务器。本篇博文可以说是它的姊妹篇,也是讲述 socks5 代理,只不过所采用的手段变成了 ss5 罢了。
关于 ss5,大家可以在官网中找到这样的描述:
SS5 is a socks server that implements the SOCKS v4 and v5 protocol. As a proxy server, SS5 authenticates, profiles and processes network requests for clients. It establishes connections to application hosts for client applications. When the client attempts to access the network, the client connects to the SS5 daemon instead of the application host.
Following authentication, clients request that SS5 perform network activities for the client. The activities might include: Connect, Bind and Udp Associate.
The SS5 protocol is independent of application protocols, and can assist with different networking services, including telnet, ftp, finger, whois, gopher, and WWW access.
我们将采用源码编译的方式来安装 ss5。
安装依赖组件
# yum -y install gcc automake make
# yum -y install pam-devel openldap-devel cyrus-sasl-devel openssl-devel
下载并解压源码
# wget https://superb-dca2.dl.sourceforge.net/project/ss5/ss5/3.8.9-8/ss5-3.8.9-8.tar.gz
# tar xvf ss5-3.8.9-8.tar.gz
# cd ss5-3.8.9
编译安装
# ./configure
# make
# make install
代理配置
第一步,修改认证方式。编辑文件
# vim /etc/opt/ss5/ss5.conf
找到
# ///////////////////////////////////////////////////////////////////////////////////
# SHost SPort Authentication
#
#auth 0.0.0.0/0 - -
把它改成
# ///////////////////////////////////////////////////////////////////////////////////
# SHost SPort Authentication
#
auth 0.0.0.0/0 - u
另外,找到
# /////////////////////////////////////////////////////////////////////////////////////////////////
# Auth SHost SPort DHost DPort Fixup Group Band ExpDate
#
#permit - 0.0.0.0/0 - 0.0.0.0/0 - - - - -
把它改成
# /////////////////////////////////////////////////////////////////////////////////////////////////
# Auth SHost SPort DHost DPort Fixup Group Band ExpDate
#
permit u 0.0.0.0/0 - 0.0.0.0/0 - - - - -
在这两个改动中,第一,我们取消了 auth
和 permit
的注释;第二,把原来的某个 -
改成了 u
。前者无需多解释,后面是因为我们打算增加用户名和密码认证,因此用 u
来标识。默认是不需要认证的。
第二步,增加用户名和密码认证。编辑文件:
# vim /etc/opt/ss5/ss5.passwd
每行一个用户 + 密码(之间用空格),按需增加。
user1 12345
user2 56789
第三步,修改启动参数,自定义端口。编辑文件
# vim /etc/sysconfig/ss5
找到注释行
#SS5_OPTS=" -u root"
把注释打开。也可以重启一行,并修改成如下配置
SS5_OPTS=" -u root -b 0.0.0.0:10801"
其中 10801
是对外开放的端口号。
防火墙开放端口
如果不使用防火墙,可跳过这一节。通过如下命令,为防火墙打开 10801
端口号。
# firewall-cmd --zone=public --add-port=10801/tcp --permanent
# firewall-cmd --reload
启动服务
首先给 bash 文件增加可执行权限:
# chmod 755 /etc/rc.d/init.d/ss5
这时候就可以启动服务了
# service ss5 start
至此,ss5 服务已经启动起来了。可通过如下命令查看连接情况
# netstat -an | grep 10801
如果想要关闭服务,只需要执行如下命令即可
# service ss5 stop
重启服务也类似
# service ss5 restart