wireguard迁移方案

Ethereal Lv4

1. 启用管理员权限

1
2
3
4
5
6
# 如果是在docker中运行,需要添加--privileged参数,如
docker run --privileged -it your_image_name
# 如果是使用k8s启动的容器,则需要在配置中添加
securityContext:
privileged: true
# 其中securityContext与pod的ports并列。

2. 启用转发

1
2
3
4
5
6
7
8
# 查看是否开启了ipv4的转发 如果是1跳过下面
cat /proc/sys/net/ipv4/ip_forward
# 开启ipv4的内核转发
sudo sh -c 'echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf'
# 使配置生效
sudo sysctl -p
# 再次查看一些是否开启了ipv4的转发
cat /proc/sys/net/ipv4/ip_forward

3. 安装配置udp2raw

1
2
3
4
5
6
# 下载udp2raw文件
wget https://github.com/wangyu-/udp2raw/releases/download/20230206.0/udp2raw_binaries.tar.gz
# 解压
tar xvf udp2raw_binaries.tar.gz
# 检查其中是否存在udp2raw_amd64文件
ls

4. 安装wireguard

1
2
# 安装 wireguard
sudo apt install wireguard resolvconf -y

5. 写入配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 写入如下内容到wg0.conf中
[Interface]
PrivateKey = <钥1>
Address = 10.254.254.18/24
DNS = 10.2.89.8, localdomain
MTU = 1300
PreUp = <udp2raw_amd64路径> -c -l0.0.0.0:51820 -r 120.55.67.92:33394 --raw-mode faketcp --cipher-mode none --auth-mode none --disable-anti-replay > /tmp/udp.log &
PostDown = killall udp2raw_amd64 || true

[Peer]
PublicKey = <钥2>
PresharedKey = <钥3>
AllowedIPs = 10.254.254.0/24, 10.2.0.0/16, 10.4.0.0/16, 10.6.0.0/16, 10.11.0.0/16, 10.12.0.0/16, 10.31.0.0/16, 10.0.40.0/24, 10.8.0.0/16
Endpoint = 127.0.0.1:51820
PersistentKeepalive = 10

需要填写上述<钥1><钥2><钥3>以及<udp2raw_amd64路径>。

然后将配置文件复制到指定路径下

1
cp wg0.conf /etc/wireguard/

启动服务

1
2
wg-quick up wg0 # 启用wg0
wg-quick down wg0 # 关闭wg0

6. 验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 直接访问某一网址,查看是否成功收到数据
wget http://10.2.89.23/dashboard/self
# 如果显示
--2024-11-05 12:34:18-- http://10.2.89.23/dashboard/self
Connecting to 10.2.89.23:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5329 (5.2K) [text/html]
Saving to: 'self'

self 100%[=================================================>] 5.20K --.-KB/s in 0.001s

2024-11-05 12:34:20 (8.53 MB/s) - 'self' saved [5329/5329]

# 则正确配置
  • Title: wireguard迁移方案
  • Author: Ethereal
  • Created at: 2024-11-13 00:10:00
  • Updated at: 2024-11-24 20:57:05
  • Link: https://ethereal-o.github.io/2024/11/13/wireguard迁移方案/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments