# WireGuard-DNAT **Repository Path**: ripperTs/WireGuard-DNAT ## Basic Information - **Project Name**: WireGuard-DNAT - **Description**: 基于WireGuard全端口映射给内网服务器分配公网IP - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-28 - **Last Updated**: 2025-11-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # WireGuard-DNAT 基于WireGuard全端口映射给内网服务器分配公网IP 目前仅在 Ubuntu 22 系统上进行测试 ## 安装 ### 云服务器端 安装脚本: ```bash wget https://gitee.com/ripperTs/WireGuard-DNAT/raw/main/cloud-server-install.sh -O wireguard-install.sh # 启动 chmod 755 ./wireguard-install.sh && ./wireguard-install.sh ``` ### 内网机器 安装脚本: ```bash wget https://gitee.com/ripperTs/WireGuard-DNAT/raw/main/setup-wg-client.sh -O setup-wg-client.sh # 启动 chmod 755 ./setup-wg-client.sh && ./setup-wg-client.sh ``` ## 使用 - 首先在云服务器上执行脚本,得到公钥和服务器外网IP - 在内网机器上执行脚本,填写服务器公网IP和公钥,最后得到一个内网服务器的公钥 - 将内网服务器公钥填写到云服务器的配置文件中的指定位置 - 重启云服务器的 WireGuard 服务 - 重启内网服务器的 WireGuard 服务 ## Windows客户端配置 > 理论可行,未经过验证 ```ini [Interface] # 客户端自己的私钥(在 Windows 上点“生成密钥对”得到) PrivateKey = # 客户端在 WireGuard 虚拟网内的地址,要跟服务端 AllowedIPs 对应 Address = 10.10.0.2/24 # 按需设置,也可以填公司内网 DNS 或 8.8.8.8 之类 DNS = 8.8.8.8 [Peer] # 这里填服务端的公钥:就是你在脚本安装完成后打印出来的那个 SERVER_PUBLIC_KEY PublicKey = # 这里填云服务器对外可达的 IP / 域名 + 监听端口 # 比如:1.2.3.4:51820 或 vpn.example.com:51820 Endpoint = :51820 # 为了“全端口打通”,把所有流量都走 WireGuard AllowedIPs = 0.0.0.0/0, ::/0 # 穿透 NAT/防火墙时建议加一个保活 PersistentKeepalive = 25 ``` **需要改的只有这 3 个地方:** - ``:在 `Windows WireGuard` 客户端点 “生成密钥对” 里的 PrivateKey - ``:服务端脚本输出的那一串公钥 - ``:云服务器能被 Windows 访问到的 IP 或域名