虚拟组网代理环境二合一,WireGuard 加 Mihomo Core
由于 IOS 端需要使用 wg 绕校园网认证,所以在这期间无法使用其他的代理节点来访问外网服务。因此我需要在 wg 中转端环境里加上代理环境,这样就可以实现访问流量通过 wg 的同时流过代理节点了。
代理配置文件
随便找一个地方,创建目录,该目录里面新建 config.yaml 文件,其配置内容如下:(配置项说明文档)
mixed-port: 5101 # 内网访问用的端口
allow-lan: true
mode: Rule
log-level: warning
secret: # 面板密码
external-controller: 0.0.0.0:5102 # 外部管理 API 接口用的端口
external-ui: ui # 通过外部管理 API 接口地址加上 /ui 路径,即可访问面板
external-ui-url: https://github.com/Zephyruso/zashboard/releases/latest/download/dist.zip
authentication:
- user:password
skip-auth-prefixes:
- 127.0.0.1/32
- 10.0.0.0/8
profile:
store-selected: true
store-fake-ip: true
geo-auto-update: true
geo-update-interval: 24
geodata-mode: false
geox-url:
geoip: https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.dat
geosite: >-
https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite.dat
mmdb: >-
https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/country.mmdb
asn: >-
https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb
sniffer:
enable: true
parse-pure-ip: true
force-dns-mapping: true
override-destination: false
sniff:
HTTP:
ports:
- 80
- 443
override-destination: false
TLS:
ports:
- 443
skip-domain:
- +.push.apple.com
skip-dst-address:
- 91.105.192.0/23
- 91.108.4.0/22
- 91.108.8.0/21
- 91.108.16.0/21
- 91.108.56.0/22
- 95.161.64.0/20
- 149.154.160.0/20
- 185.76.151.0/24
- 2001:67c:4e8::/48
- 2001:b28:f23c::/47
- 2001:b28:f23f::/48
- 2a0a:f280:203::/48
dns:
enable: true
ipv6: true
listen: 0.0.0.0:1053
enhanced-mode: redir-host
fake-ip-range: 198.18.0.1/16
use-hosts: true
respect-rules: true
use-system-hosts: false
default-nameserver:
- 223.5.5.5
- 114.114.114.114
nameserver:
- https://doh.pub/dns-query
- https://dns.alidns.com/dns-query
proxy-server-nameserver:
- https://doh.pub/dns-query
- https://dns.alidns.com/dns-query
tun:
enable: true
device: mihomo
stack: mixed
auto-route: true
auto-redirect: false
auto-detect-interface: true
dns-hijack:
- "any:53"
- "tcp://any:53"
route-exclude-address: []
mtu: 1500
# 这里粘贴你实际订阅配置的内容,注意有些配置不要与上方的内容重复!
部署容器
由于为了方便配置网络使用了 host 网络模式,在部署前需在宿主机里配置一下 sysctls 内核参数。
编辑 /etc/sysctl.conf 文件,增加如下配置内容保存即可:
net.ipv4.ip_forward=1
net.ipv4.conf.all.src_valid_mark=1
net.ipv6.conf.all.disable_ipv6=0
net.ipv6.conf.all.forwarding=1
随后创建 docker-compose.yaml 文件,其内容如下:
services:
wg-easy:
container_name: wg-server
image: ghcr.io/wg-easy/wg-easy:15
restart: always
network_mode: "host"
environment:
- HOST=::0
- PORT=5100
- INSECURE=true
volumes:
- /lib/modules:/lib/modules:ro
cap_add:
- NET_ADMIN
- NET_RAW
- SYS_MODULE
mihomo-core:
container_name: mihomo-core
image: metacubex/mihomo
restart: always
network_mode: "host"
volumes:
- 代理配置文件所在目录路径:/root/.config/mihomo
- /lib/modules:/lib/modules:ro
cap_add:
- NET_ADMIN
- NET_RAW
- SYS_MODULE
devices:
- /dev/net/tun
通过命令或 UI 等方式启动容器即可。
使用注意
如果不需要使用代理时,可把节点切换到直连模式,就相当于没开代理啦。
如果你直接关闭了 Tun 模式,那可能造成无法访问外部网络,只能访问内网服务。
一旦其他人修改代理模式或代理节点,那将会影响到全部通过 wg 连进来的人。