选择和安装代理工具
-
选择代理工具:
- socks5代理:适合需要全透明代理,支持所有协议。
- http代理:适合需要代理特定协议(如HTTP/S)。
- shadowsocks:绕过DNS过滤,适合复杂环境。
- frp(FastReverse Proxy):高性能,支持多种协议。
-
安装软件包:
- 安装socks5:
sudo apt update && sudo apt install socks5
- 安装http代理:
sudo apt update && sudo apt install http_proxy
- 安装shadowsocks:
git clone https://github.com/shadowsocks/shadowsocks.git cd shadowsocks make install
- 安装frp:
git clone https://github.com/frrn/frp.git cd frp make install
- 安装socks5:
配置系统代理设置
-
使用socks5代理:
- 打开
/etc/profile,添加以下内容:export http_proxy=socks5://localhost:108 export https_proxy=socks5://localhost:108
- 保存并执行:
source /etc/profile
- 打开
-
使用http代理:
- 打开
/etc/profile,添加:export http_proxy=http://localhost:808 export https_proxy=http://localhost:808
- 同样执行上述命令。
- 打开
-
使用NetworkManager(Debian/Ubuntu):
- 打开网络配置文件:
nano /etc/network/interfaces
- 添加代理设置:
# 定义socks5代理 post-up "socks5 -f socks5://localhost:108" # 定义http代理 post-up "http proxy=http://localhost:808" post-up "https proxy=http://localhost:808"
- 保存并重启网络服务:
sudo systemctl restart networking
- 打开网络配置文件:
-
使用ifconfig(旧系统):
- 打开
/etc/rc.local,添加:# socks5代理 socks5 -f socks5://localhost:108 # http代理 http proxy=http://localhost:808 https proxy=http://localhost:808
- 保存并运行:
sudo crontab /etc/rc.local
- 打开
配置高级代理工具(如shadowsocks或frp)
-
配置shadowsocks:
- 启用shadowsocks:
ss -o server listen 0...:108
- 连接外部服务器:
ss -R 127...1:1089
- 启用shadowsocks:
-
配置frp:
- 启用本地服务:
frp --subdomain example.com --port 800
- 指定外部服务器地址:
frp --remote-addr 你的IP:8443
- 启用本地服务:
验证代理配置
-
测试socks5代理:
curl -I http://example.com
或者访问:
elinks http://example.com
-
测试http代理:
curl -I http://example.com
-
测试shadowsocks:
curl -I http://example.com
处理可能的错误
-
防火墙问题:
sudo iptables -L -n
检查是否开放了代理端口(如108、808)。
-
日志文件: 查看
/var/log/syslog或相关日志文件,查找错误信息。 -
网络问题: 确保网络连接正常,检查IP地址和路由。
配置Linux代理服务器需要选择合适的工具,正确安装和配置,最后通过测试验证设置是否成功,遇到问题时,参考文档或社区资源,逐步排查解决,选择高级工具如shadowsocks或frp可以提供更高的代理性能和灵活性。




