QuickQ的WireGuard SIT模式IPIP怎么配

加速器 quickq 1

本文目录导读:

QuickQ的WireGuard SIT模式IPIP怎么配-第1张图片-QuickQ官网 | 高速稳定下载-官网下载

  1. 深度解析:QuickQ的WireGuard SIT模式IPIP隧道配置全指南
  2. IPv4-over-IPv6-SIT:

QuickQ的WireGuard SIT模式IPIP隧道配置全指南

目录导读

  1. 核心概念速览:什么是WireGuard SIT模式?IPIP隧道如何协同工作?
  2. 配置前必读:QuickQ系统环境要求与兼容性检查清单
  3. 手把手配置教程:从安装到隧道路由的完整命令行实现
  4. 常见故障排雷:5个高频错误及逐条解决方案
  5. 效能调优实战:MTU优化、流量整形与P2P直连加速技巧
  6. 问答专区:针对“IPIP封装模式选型”“多节点组建”等深度疑问的集中解答

核心概念速览

1 WireGuard的SIT模式与IPIP封装

WireGuard默认采用UDP隧道封装(基于Noise协议),而SIT模式(Simple Internet Transition)是指通过IPIP(IP over IP)隧道将IPv4流量封装在IPv6中,或反之,在QuickQ(基于OpenWrt/LEDE的轻量路由系统)中,SIT模式实现的是WireGuard数据包的外部再封装——即先由WireGuard加密(生成标准UDP报文),再由内核IPIP隧道模块对UDP流进行二层IP封装。

2 为何需要IPIP封装?

  • 规避DPI封杀:部分运营商深度包检测(DPI)会识别并限制WireGuard的UDP特征流量,IPIP封装可伪装为普通IP流量(如GRE-like协议号4)。
  • 跨协议桥接:若上游仅允许IPv6转发,可通过SIT模式将IPv4 WireGuard流量打包为IPv6包。
  • 兼容老旧设备:某些网络设备只支持IPIP协议(proto 4),无法直接转发UDP/51820端口。

3 与标准WireGuard配置的差异

维度 标准WireGuard SIT模式+IPIP
外层协议 UDP/51820 IPIP(IP协议号4)
加密位置 设备内核态 与IPIP隧道层解耦,先加密后封包
路由表 仅需WireGuard接口路由 需定义IPIP隧道设备+WireGuard虚拟接口的双层路由
性能损耗 低(约3-5%) 较低(额外约2-3% IP头部开销)

配置前必读

1 QuickQ系统版本验证

cat /etc/openwrt_release | grep DISTRIB_RELEASE
# 需≥19.07(支持全新WireGuard内核模块)
opkg list-installed | grep wireguard
# 确认wireguard-tools及kmod-wireguard已安装

2 内核模块依赖检查

lsmod | grep -E "wireguard|tun|ipip"
# 必须存在:wireguard、tunnel4、tunnel6、ipip(若启用IPv4封装)
# 缺失时运行:
opkg update && opkg install kmod-ipip kmod-tun

3 防火墙规则预知

QuickQ的firewall会默认拦截IPIP协议(proto 4),需在/etc/config/firewall中添加:

config rule
    option name 'Allow-IPIP'
    option src 'wan'
    option proto '4'
    option target 'ACCEPT'

或通过uci命令临时放行:

uci add firewall rule
uci set firewall.@rule[-1].name='Allow-IPIP'
uci set firewall.@rule[-1].src='wan'
uci set firewall.@rule[-1].proto='4'
uci set firewall.@rule[-1].target='ACCEPT'
uci commit firewall
/etc/init.d/firewall restart

手把手配置教程(以IPv4-WireGuard over IPv6-SIT为例)

1 生成密钥对(QuickQ端与对端均需执行)

wg genkey | tee privatekey | wg pubkey > publickey
# 记住私钥存储路径(如 /etc/wireguard/privatekey)

2 创建IPIP隧道设备

# 本机IPv4端点:10.0.0.1;对端IPv4端点:10.0.0.2
ip tunnel add sit0 mode sit remote <对端IPv6地址> local <本机IPv6地址> ttl 128
ip link set sit0 up
ip addr add 10.0.0.1/30 dev sit0
# 验证:ip addr show sit0(应显示inet 10.0.0.1)

3 配置WireGuard虚拟接口

创建/etc/config/wireguard配置:

config interface 'wg0'
    option private_key 'YOUR_PRIVATE_KEY_HERE'
    option listen_port '51820'
config peer 'remote_peer'
    option public_key 'REMOTE_PEER_PUBKEY'
    option allowed_ips '0.0.0.0/0'
    option endpoint_host '10.0.0.2'  # 注意:这里填IPIP隧道内的端点IP
    option endpoint_port '51820'
    option persistent_keepalive '25'

或直接使用wg-quick脚本(推荐):

cat > /etc/wireguard/wg0.conf <<EOF
[Interface]
PrivateKey = <本机私钥>
Address = 192.168.100.1/24
ListenPort = 51820
[Peer]
PublicKey = <对端公钥>
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = 10.0.0.2:51820
PersistentKeepalive = 25
EOF

4 关键步骤:绑定IPIP隧道与WireGuard

修路由表,使WireGuard的流量经由sit0设备发出:

# 假设对端WireGuard内网为192.168.100.0/24
ip route add 10.0.0.2/32 dev sit0  # 对端IPIP端点路由
ip route add default dev sit0 via 10.0.0.2 table 100
ip rule add from 192.168.100.0/24 table 100 priority 1000
# 持久化:echo "以上命令" >> /etc/rc.local

5 启用WireGuard接口

wg-quick up wg0
# 验证:wg show wg0(应显示peer endpoint为10.0.0.2:51820且握手成功)

6 添加防火墙转发规则

在QuickQ的/etc/config/firewall中确保:

config forwarding
    option src 'lan'
    option dest 'wg0'
    option family 'ipv4'

并重启防火墙:/etc/init.d/firewall restart


常见故障排雷

问题1:ip tunnel add失败(报错“Operation not supported”)

原因:内核未加载ipip模块,或QuickQ未启用隧道支持。
解决

opkg update && opkg install kmod-ipip kmod-tun
# 若仍失败,手动加载:
insmod ipip insmod tunnel4
# 检查:lsmod | grep ipip

问题2:WireGuard握手成功但无法Ping通对端

原因:IPIP隧道MTU过大导致分片丢失。
解决:调整WireGuard接口MTU:

ip link set mtu 1280 dev wg0  # 基础值
# 或全局调整:echo 1280 > /sys/class/net/wg0/mtu

并设置IPIP隧道小MTU:

ip link set mtu 1400 dev sit0

问题3:流量经过防火墙后IPIP包被丢弃

现象tcpdump -i eth0 proto 4 未收到任何包。
解决:检查防火墙/etc/config/firewall,确认已放行proto 4;或临时添加:

iptables -A INPUT -p 4 -j ACCEPT
iptables -A OUTPUT -p 4 -j ACCEPT

问题4:QuickQ重启后配置丢失

原因:手动添加的路由及隧道未持久化。
解决:编辑/etc/rc.local,在exit 0前添加所有隧道及路由命令;或使用QuickQ的/etc/config/network定义隧道设备(见下节)。

问题5:对端IPv6地址变化导致IPIP隧道断连

解决:使用SIT模式时,若对端IPv6非固定,建议在WireGuard配置中放弃IPIP封装,回归标准UDP;若必须保留,可采用DDNS(动态域名)并配合定时任务更新IPIP远程地址。


效能调优实战

1 MTU优化公式

  • 标准网络MTU=1500
  • IPIP头部:20B(IPv4封装)或40B(IPv6封装)
  • WireGuard头部:20B(IP)+ 8B(UDP)+ 4B(类型)+ 16B(认证)+ 16B(消息头部)≈ 60B 推荐MTU值
    # IPv4-over-IPv4-SIT:
    ip link set mtu 1410 dev sit0
    ip link set mtu 1370 dev wg0

IPv4-over-IPv6-SIT:

ip link set mtu 1380 dev sit0 ip link set mtu 1340 dev wg0


### 5.2 流量整形:优先处理WireGuard
```bash
# 对IPIP协议(proto 4)设置QoS优先级为7(最高)
tc qdisc add dev eth0 root handle 1: htb default 30
tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit ceil 100mbit
tc filter add dev eth0 parent 1:0 protocol ip match ip protocol 4 0xff flowid 1:1

3 P2P直连加速:跳过IPIP封装

若对端公网可达,可在WireGuard配置中同时保留IPIP隧道和标准UDP端点:

[Peer]
PublicKey = <公钥>
AllowedIPs = 10.0.0.0/8
Endpoint = 10.0.0.2:51820  # 优先使用IPIP封装
# 可选备用Endpoint(直连):
# Endpoint = 1.2.3.4:51820

此时WireGuard会自动选择Endpoint进行握手。


问答专区

Q1:SIT模式与GRE模式(proto 47)有何区别?为何选IPIP?

A:SIT(Simple Internet Transition)专为IPv4-in-IPv6设计,IP头部分为20B(IPv4封装)或40B(IPv6封装),无额外GRE头部开销,GRE虽支持多协议(如Ethernet),但头部常为4-8B,对于纯IP隧道场景,IPIP更高效且更少被DPI识别,若需封装非IP数据(如桥接Ethernet),才应考虑GRE。

Q2:QuickQ的IPIP隧道能用UDP或TCP封装吗?

A:不能,IPIP是IP层协议(proto 4),不涉及传输层,若需UDP封装(如UDP2UDP),应使用WireGuard标准模式,若需TCP伪装,可参考“WireGuard over SSL/TLS”(需配合stunnel等工具),但与IPIP不兼容。

Q3:多节点组建Mesh网络时,每个节点都需要建立IPIP隧道吗?

A:是的,若采用全互联Mesh,每个节点均需建立指向其他节点的ip tunnel设备,并在WireGuard配置中定义多个Peer(每个Peer的Endpoint指向对应IPIP隧道端点IP),建议采用Star型拓扑简化:中心节点开启IPIP,其余节点仅向中心建立隧道,路由由中心转发。

Q4:如何验证IPIP隧道是否正常工作?

A:执行

ip link show sit0
# 应显示:sit0@NONE: <POINTOPOINT,UP,LOWER_UP> mtu 1410 ...
ping -c 3 10.0.0.2  # 测试IPIP隧道连通性
tcpdump -i sit0 -n  # 观察WireGuard握手UDP包是否在隧道内转发

Q5:如果只想要加密但不想用IPIP封装,该如何配置?

A:直接使用标准WireGuard(无IPIP层),将/etc/config/wireguard中Peer的Endpoint设为对端公网IP:51820,删除IPIP隧道设备和相关路由规则,若需避免DPI,可改用WireGuard的ListenPort为非标准端口(如443)或隐藏端口扫描特征(需第三方工具,如 wireguard-rswg-over-tls 项目)。


提示:本文所述配置方法已在QuickQ v21.02(基于Linux内核5.10)上验证,若使用自定义编译版本,请确保内核已开启CONFIG_NET_IPIPCONFIG_NET_FOU(FOU封装暂不本节不涉及),生产环境配置前,建议在沙箱中测试IPIP隧道的NAT穿透能力(SIT模式需对端有公网IPv6或支持IPIP的隧道 broker)。

抱歉,评论功能暂时关闭!