用Linux Wifi 热点分享SOCKS代理的路由设置

博客分类: 技术 阅读次数: comments

用Linux Wifi 热点分享SOCKS代理的路由设置

设置热点

\[\text{Internet}\xrightarrow{\text{wlp2s0}}\text{PC}\xrightarrow{\text{ap0}}\text{Hotspot}\]

用REDSOCKS作透明代理重定向

base {
    log_debug = off;
    log_info = off;
    log = "syslog:daemon";
    daemon = on;
    redirector = iptables;
}


redsocks {
    local_ip = 0.0.0.0;
    local_port = 12345;

    ip = 127.0.0.1;
    port = 1080;

    type = socks5;
}


redudp {
    local_ip = 127.0.0.1;
    local_port = 54321;

    ip = 127.0.0.1;
    port = 1080;

	dest_ip = 8.8.8.8;
	dest_port = 53;

	udp_timeout = 30;
	udp_timeout_stream = 180;
}


dnstc {
	local_ip = 127.0.0.1;
	local_port = 5300;
}

IPTABLES配置

sudo iptables -F
sudo iptables -t nat -A POSTROUTING -o wlp2s0 -j MASQUERADE
sudo iptables -A FORWARD -i wlp2s0 -o ap0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i ap0 -o wlp2s0 -j ACCEPT
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 --dport 80 -j REDIRECT --to-ports 12346
iptables -t nat -A REDSOCKS -p tcp --dport 443 -j REDIRECT --to-ports 12346
iptables -t nat -A REDSOCKS -p tcp --dport 11371 -j REDIRECT --to-ports 12345
iptables-save > ~/backup/iptables
ip6tables-save > ~/backup/ip6tables
iptables-restore < ~/backup/iptables
ip6tables-restore < ~/backup/ip6tables

参见