Linux 设置真全局代理

zsxwz 24/08.28 14:59 252

偶尔有人问在国内的linux上设置代理,之前也说过很多次了,linux设置代理确实是比较麻烦,各种环境变量,各个软件的代理设置多多少少又有点区别,所以设置全局代理就比较方便点。

 

使用iptables+redoskcs。

1、安装 redsocks:

apt install redsocks

 

2、配置 redsocks (/etc/redsocks.conf):

ip和port就是你自己代理的ip和端口。

base {
    log_debug = on;
    log_info = on;
    log = "file:/var/log/redsocks.log";
    daemon = on;
    redirector = iptables;
}

redsocks {
    local_ip = 127.0.0.1;
    local_port = 12345;
    ip = your_proxy_address;
    port = your_proxy_port;
    type = socks5;  # 可以是 http-relay, socks4, socks5 等
}

 

3、配置 iptables:

iptables -t nat -N REDSOCKS

iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN

iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 12345 

iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDSOCKS
iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDSOCKS

 

4、如果要取消

iptables -F
iptables -X
iptables -Z
iptables -t nat -F
iptables -t nat -X
iptables -t nat -Z

上一篇:serv00免费虚拟主机及保号脚本
下一篇:gallery-dl 批量下载 pixiv
最新回复 (0)
    • 姿势论坛—姿势小王子
      2
返回
发新帖
友情链接
免责声明:本站部分资源来源于网络,如有侵权请发邮件(mail@zsxwz.com)告知我们,我们将会在24小时内处理。