各位同学应该都知道TUN和socks5的概念以及用途,所以在此就不赘述了。
以debian为例,理论上linux都适用。
第一部分:将socks5转化成TUN设备(socks5用途非常广也很容易部署和获取到)
1.下载二进制文件
感谢大佬 heiher 的开源项目 https://github.com/heiher/hev-socks5-tunnel
试了多家的socks5转tun工具,最后决定使用这个开源项目,相对于其他家来说这个占用资源少,速度也在其他几家相对最快的。
更多格式请访问 https://github.com/heiher/hev-socks5-tunnel/releases
wget https://github.com/heiher/hev-socks5-tunnel/releases/download/2.8.0/hev-socks5-tunnel-linux-x86_64 -O tun2socks
2.赋予可执行权限
chmod +x ./tun2socks
3.配置文件(tun2socks.yaml)
重点说明一下 socks5->udp 这个参数,如果不需要UDP转发的请改成tcp(对于性能差的路由器CPU占用会明显降低)
如果socks5需要验证那么须配置username和password
另外须自行替换serverip和serverip-port,并去掉前面的#
tunnel:
name: tun1080
mtu: 8500
multi-queue: true
ipv4: 10.20.30.40
ipv6: '2001::10:20:30:40'
socks5:
port: serverip-port
address: serverip
udp: 'udp'
#username: 'username'
#password: 'password'
misc:
log-level: info
connect-timeout: 5000
read-write-timeout: 10000
4.运行tun2socks
./tun2socks tun2socks.yaml
5.判断是否配置成功
ping 10.20.30.40 -c 2
PING 10.20.30.40 (10.20.30.40) 56(84) bytes of data.
64 bytes from 10.20.30.40: icmp_seq=1 ttl=64 time=0.070 ms
64 bytes from 10.20.30.40: icmp_seq=2 ttl=64 time=0.050 ms
如果出现上述信息就是配置成功了。
这个TUN就相当于我们常说的第三层(网络层),也就是说可以使用(ip addr,ip rule,iptables)进行个性化定制
第二部分:将TUN设备转化成socks5(如果觉得更需要socks5,那么这一部分必看)
1.下载二进制文件
再次感谢大佬 heiher 的开源项目 https://github.com/heiher/hev-socks5-server
更多格式请访问 https://github.com/heiher/hev-socks5-server/releases
wget https://github.com/heiher/hev-socks5-server/releases/download/2.7.0/hev-socks5-server-linux-x86_64 -O socks5
2.赋予可执行权限
chmod +x ./socks5
3.配置文件(socks5.yaml)
bind-interface 指定出口设备(可以填TUN也就是第一部分讲的),如果为空则表示使用系统默认设置
如果需要验证用户名密码需要将auth2改成auth,并修改username和password
main:
workers: 5
port: 20443
listen-address: '::'
udp-port: 20443
bind-interface: ''
auth2:
username: 'user'
password: 'password'
misc:
connect-timeout: 5000
read-write-timeout: 10000
log-level: info
4.运行socks5
./socks5 socks5.yaml
5.判断是否配置成功
curl -x socks5://127.0.0.1:20443 ifconfig.me
如果出现返回IP地址就是配置成功了。
TUN 和 socks5 各有优劣,其它的就请佬友们各取所需吧
Good luck to all