092thum_副本.png
视频地址:https://youtu.be/lRLVpbbzcCA

WireGuard设置过程

安装wireguard


sudo apt update
sudo apt install wireguard

生成本地公私钥


wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey

编辑连接wg0的配置


sudo nano /etc/wireguard/wg0.conf

VPS主机-配置文件内容:


[Interface]
Address = 10.10.5.2/32
ListenPort = 5632
PrivateKey = PrivateKey

[Peer]
PublicKey = PublicKey
AllowedIPs = 10.10.5.2/32,192.168.1.0/24
#Endpoint = ip or domain:51820
PersistentKeepalive = 10

内网主机-配置文件内容:


[Interface]
Address = 10.10.5.1/32
ListenPort = 51820
PrivateKey = PrivateKey
PostUp = iptables -A FORWARD -i %i -j ACCEPT
PostUp = iptables -A FORWARD -o %i -j ACCEPT
PostUp = iptables -t nat -A POSTROUTING -s 10.10.5.0/24 -j SNAT --to-source 192.168.1.194
PostDown = iptables -D FORWARD -i %i -j ACCEPT
PostDown = iptables -D FORWARD -o %i -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -s 10.10.5.0/24 -j SNAT --to-source 192.168.1.194
#MTU = 1200

[Peer]
PublicKey = PublicKey
AllowedIPs = 10.10.5.2/32
Endpoint = 127.0.0.1:5632
PersistentKeepalive = 10

内网主机开启数据转发


echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

修改全部文件权限


sudo chmod 600 /etc/wireguard/*

随启动运行


sudo systemctl enable wg-quick@wg0

sudo systemctl start wg-quick@wg0

VPS端 注意防火墙要打开5632

重启wg0接口


wg-quick down wg0 && wg-quick up wg0

udp2raw部分

下载udp2raw


mkdir udp2raw
cd udp2raw
wget https://github.com/wangyu-/udp2raw/releases/download/20230206.0/udp2raw_binaries.tar.gz

tar -xzf udp2raw_binaries.tar.gz

server.sh 服务端脚本


#!/bin/bash

nohup /root/udp2raw/udp2raw_amd64 -s -l0.0.0.0:30005 -r127.0.0.1:5632 -k "pass" --raw-mode faketcp --cipher-mode xor  -a > /root/udp2raw/udp_16400.log 2>&1 &

client.sh 客户端脚本


#!/bin/bash

nohup /root/udp2raw/udp2raw_amd64 -c -l0.0.0.0:5632 -r141.11.175.39:30005 -k "pass" --raw-mode faketcp --cipher-mode xor  -a > /root/udp2raw/udp_16400.log 2>&1 &

修改本地主机的wg0配置文件

1.添加MTU = 1200
2.修改接入点地址 

stop.sh 停止后台运行脚本


#!/bin/bash
echo "Stopping udp2raw instances..."
pids=$(ps aux | grep udp2raw_amd64 | grep -v grep | awk '{print $2}')
for pid in $pids; do
    kill -9 $pid
    echo "Stopped process with PID $pid"
done
echo "All udp2raw instances stopped."

udp2raw各参数释义

选项注释
--raw-mode伪装模式,支持 faketcp/udp/icmp,用于绕过防火墙
-k,--key密码设置
--cipher-mode加密模式(如 aes128cbc
--auth-mode认证模式(如 md5/crc32
-a,--auto-rule自动管理iptables规则
-g,--gen-rule自动生成 iptables 规则
--disable-anti-replay禁用反重放保护功能
--source-ip服务端IP地址
--source-port服务端端口号
--conf-file指定配置文件
--fifo向运行中的程序发送命令
--log-level日志级别(0静默, 1错误, 2警告, 3信息)
--log-position设置日志文件名
--disable-color禁用日志颜色输出
--disable-bpf
--sock-buf设置 socket 缓冲区大小
--force-sock-buf
--seq-mode
--lower-levelMAK地址
--gen-add
--keep-rule定期主动检查 iptables 规则
--clear清除iptables规则

发表评论