Ubuntu/Debian UFW 防火墙配置与使用指南
如何在VPS上搭建Shadowsocks服务
本文将指导您利用虚拟专用服务器(VPS)搭建Shadowsocks代理服务,实现安全稳定的网络连接,Shadowsocks作为一种轻量级加密代理协议,能有效保护网络隐私并提升访问效率。
搭建前准备工作
-
获取VPS服务器
选择信誉良好的VPS服务商(如Vultr、DigitalOcean或Linode),推荐配置:- CentOS 7+ 或 Ubuntu 18.04+ 系统
- 512MB以上内存
- 10GB以上存储空间
-
连接服务器
使用SSH工具登录服务器:ssh root@your_server_ip
安装Shadowsocks服务端
-
更新系统组件
# Ubuntu/Debian系统 apt update && apt upgrade -y # CentOS系统 yum update -y
-
安装Python环境(如未预装)
apt install python3 python3-pip -y # Ubuntu/Debian yum install python3 python3-pip -y # CentOS
-
安装Shadowsocks
pip3 install https://github.com/shadowsocks/shadowsocks/archive/master.zip
-
创建配置文件
nano /etc/shadowsocks.json
复制以下配置(按需修改):
{ "server":"0.0.0.0", "server_port":8388, "local_address":"127.0.0.1", "local_port":1080, "password":"your_strong_password", "timeout":300, "method":"aes-256-gcm", "fast_open":true }安全建议:使用高强度密码并采用
chacha20-ietf-poly1305等现代加密算法 -
启动Shadowsocks服务
ssserver -c /etc/shadowsocks.json -d start
系统服务配置(可选)
创建systemd服务实现开机自启:
nano /etc/systemd/system/shadowsocks.service
[Unit] Description=Shadowsocks Server After=network.target [Service] Type=simple ExecStart=/usr/local/bin/ssserver -c /etc/shadowsocks.json Restart=on-failure RestartSec=10 [Install] WantedBy=multi-user.target
启动服务:
systemctl daemon-reload systemctl enable shadowsocks systemctl start shadowsocks
防火墙配置
开放服务器端口:
ufw allow 8388/udp # CentOS (firewalld) firewall-cmd --permanent --add-port=8388/tcp firewall-cmd --permanent --add-port=8388/udp firewall-cmd --reload
客户端连接配置
-
下载Shadowsocks客户端:
- Windows: Shadowsocks-Windows
- macOS: ShadowsocksX-NG
- Android: Shadowsocks-Android
-
配置客户端参数:
- 服务器地址: VPS公网IP
- 端口: 与配置文件一致(默认8388)
- 密码: 配置文件中设置的密码
- 加密方式: 与配置文件一致
安全优化建议
-
禁用密码登录:
配置SSH密钥认证并禁用root密码登录 -
安装Fail2Ban:
apt install fail2ban -y # Ubuntu/Debian yum install fail2ban -y # CentOS
-
定期更新系统:
设置自动安全更新:apt install unattended-upgrades -y dpkg-reconfigure --priority=low unattended-upgrades
-
启用BBR加速(提升网络性能):
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf sysctl -p
维护与故障排查
-
查看服务状态:
systemctl status shadowsocks
-
检查服务日志:
journalctl -u shadowsocks -f
-
端口测试: 在本地计算机执行:
telnet your_server_ip 8388
-
流量监控:
apt install vnstat -y # 安装流量监控工具 vnstat -l -i eth0
法律与合规说明
在使用Shadowsocks服务时,请务必遵守当地法律法规,本教程仅供技术学习与网络研究参考,实际使用需确保符合所在地区的网络管理规定,建议仅用于合法用途,如企业远程办公、学术研究等场景。
通过本指南搭建的Shadowsocks服务可实现稳定安全的网络加密代理,建议定期更新系统组件并监控服务运行状态,确保服务长期稳定运行,遇到连接问题时,可优先检查防火墙设置和端口状态,确认配置文件参数无误后重启服务。
文章版权声明:除非注明,否则均为亚朵原创文章,转载或复制请以超链接形式并注明出处。

