问题:将租用的/24 IP段配置为多出口IP正向代理
解决方案步骤
1. 先确保租用的/24 IP段已在服务器上配置为可用虚拟IP
服务器必须先能识别并使用这些租用IP,否则无法作为出口:
- 临时添加单IP(替换为你的租用IP和网卡名,比如
eth0):ip addr add 192.168.1.2/32 dev eth0 - 永久配置(Ubuntu用netplan):编辑
/etc/netplan/00-installer-config.yaml,添加租用IP:
执行network: ethernets: eth0: addresses: - 你的Vultr内部IP/24 - 租用IP1/32 - 租用IP2/32 # 按需添加需要用作出口的IP,建议单IP/32避免冲突 gateway4: 你的Vultr网关地址 nameservers: addresses: [8.8.8.8, 8.8.4.4] version: 2netplan apply生效。
2. 修正Squid的出口IP绑定配置
修改Squid主配置文件/etc/squid/squid.conf:
- 基础配置(固定用某一个租用IP作为出口):
http_port 0.0.0.0:3128 tcp_outgoing_address 你的租用IP地址 - 多IP切换配置(按客户端IP分配不同出口):
acl client_group1 src 192.168.0.0/24 tcp_outgoing_address 租用IP1 client_group1 acl client_group2 src 10.0.0.0/24 tcp_outgoing_address 租用IP2 client_group2
修改后重启Squid:systemctl restart squid
3. 添加策略路由确保流量走租用IP
即使Squid绑定了IP,系统默认路由可能仍走内部IP,需添加规则:
- 创建自定义路由表:编辑
/etc/iproute2/rt_tables,新增一行:100 ipxo_routes - 添加路由规则:
ip rule add from 你的租用IP地址 table ipxo_routes ip route add default via 你的Vultr网关 dev eth0 table ipxo_routes - 永久保存规则:创建
/etc/network/if-up.d/ipxo-routes脚本,内容如下,再赋予执行权限:#!/bin/sh ip rule add from 你的租用IP地址 table ipxo_routes ip route add default via 你的Vultr网关 dev eth0 table ipxo_routeschmod +x /etc/network/if-up.d/ipxo-routes
4. 验证BGP(BIRD)配置有效性
确保BIRD已正确宣告租用的IP段,且Vultr侧已接收:
- 查看BGP会话状态:
birdc show protocols all - 检查宣告的路由:
birdc show route
确认租用的/24段处于Up状态,且已被Vultr的BGP邻居学习到。
5. 直达最终目标:SOCKS5代理配置(替代Squid)
如果最终要SOCKS5,用dante-server更简洁:
- 安装:
apt install dante-server - 编辑
/etc/danted.conf:logoutput: syslog internal: 0.0.0.0 port = 1080 external: eth0 socksmethod: none clientmethod: none user.privileged: root user.unprivileged: nobody client pass { from: 0.0.0.0/0 to: 0.0.0.0/0 } socks pass { from: 0.0.0.0/0 to: 0.0.0.0/0 outgoing: 你的租用IP地址 } - 重启服务:
systemctl restart danted
验证方法
- Squid测试:
curl -x http://你的服务器IP:3128 https://ifconfig.me - SOCKS5测试:
curl --socks5 你的服务器IP:1080 https://ifconfig.me
如果返回的不是租用IP,检查: - 防火墙是否放行代理端口(3128/1080)
- 查看服务日志(
/var/log/squid/access.log或/var/log/syslog)排查错误 - 确认IPXO的租用IP未被限制,BGP宣告无问题
内容的提问来源于stack exchange,提问作者AMTECH
相关产品推荐
相关产品推荐

