搭建socket代理服务器
1.安装依赖
yum -y install gcc gcc-c++ automake make pam-devel openldap-devel cyrus-sasl-devel
yum -y install pam-devel openldap-devel cyrus-sasl-devel gcc automake make openssl openssl-devel
2.下载ss5源码包
wget http://nchc.dl.sourceforge.net/project/ss5/ss5/3.8.9-8/ss5-3.8.9-8.tar.gz
3.编译安装
进入解压目录
./configure
make
make install
4.服务注册并开机自启
chmod +x /etc/init.d/ss5
chkconfig --add ss5
chkconfig ss5 on
5.开启身份认证(二选一)
5.1 匿名连接
vim /etc/opt/ss5/ss5.conf
取消87行和203行的注释
5.2 设置账号密码
(1)取消注释并修改参数
vim /etc/opt/ss5/ss5.conf
取消87行的注释并修改最后一个参数由预设的“-”改为“u”,如下所示:
auth 0.0.0.0/0 - u
取消203行的注释并将第二个参数由预设的“-”改为“u”,如下所示:
permit u 0.0.0.0/0 - 0.0.0.0/0 - - - - -
(2)设置账号和密码
vim /etc/opt/ss5/ss5.passwd
添加用户名和密码
admin passwd
6.修改端口(可选,默认端口为1080)
S5_OPTS=" -u root -b 0.0.0.0:8899"
参数解释:
-u root
: 这个选项指定运行 SS5 服务的用户为root
。通常情况下,为了安全考虑,不建议以 root 用户身份运行服务,但这里可能是为了演示或特定环境下的配置。-b 0.0.0.0:8899
: 这个选项设置了 SS5 代理服务器监听的 IP 地址和端口号。其中:0.0.0.0
表示服务器将在所有可用网络接口上监听连接请求。8899
是指定的监听端口号,这意味着客户端应该连接到服务器的这个端口来使用 SOCKS5 代理服务。
7.启动ss5服务
service ss5 start #启动命令
service ss5 restart #重启命令
注:启动失败,可以执行如下命令后再启动
mkdir -p /var/run/ss5/
touch -p /var/run/ss5/ss5.pid
8.测试
在本机使用curl命令来测试
curl --socks5 0.0.0.0:8899 -U admin:passwd https://www.baidu.com #需认证
或
curl -x socks5://admin:passwd@0.0.0.0:8899 www.baidu.com #需认证
curl --socks5 0.0.0.0:8899 https://www.baidu.com #无需认证
[root@001 home]# curl --socks5 0.0.0.0:8899 -U admin:passwd https://www.baidu.com
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus=autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn" autofocus></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=https://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');
</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号 <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>