💥一、配置 VPS 到Win10内网的WireGuard💦
🎈1、生成服务端密钥:
sudo sh -c ‘umask 077; wg genkey > /etc/wireguard/vps.key; wg pubkey < /etc/wireguard/vps.key > /etc/wireguard/vps.pub’
sudo cat /etc/wireguard/vps.pub
🧨2、下载WireGuard的Win10版本
下载地址:Installation – WireGuard(需要魔法🍡)
直接安装,运行。
🎀3、在 Win10的WireGuard 客户端中复制公钥
到 VPS编辑配置:sudo vim /etc/wireguard/wg0.conf
写入:
[Interface]
Address = VPS内网IP/24
ListenPort = 51820
PrivateKey = VPS公钥
# Win10
[Peer]
PublicKey = Win10公钥
AllowedIPs = Win10内网IP/32
注:只有vps的配置自己的内网IP才是24网段,其余都是32网段以便于每个主机不发生冲突,如要增加其它主机,则在最下方添加[Peer]节点
✨4、在VPS修改权限、启动、查看
sudo chmod 600 /etc/wireguard/wg0.conf
sudo systemctl enable –now wg-quick@wg0
注:–now 是两个- restart(重启) stop(停止) start(启动)
sudo wg show
🎉5、到Win10内网WireGuard 客户端配置如下内容
[Interface]
PrivateKey = Win10私钥
Address = Win10的内网IP/32
[Peer]
PublicKey = VPS公钥
AllowedIPs = VPS的内网IP/32
Endpoint = VPS的IP:51820
PersistentKeepalive = 25
注:这里的vps网段也是32确保是vps路由,后续还可以添加其它主机
点击保存、连接
🎃6、互Ping测试(细节)
注:只有双方互评ping之后两个主机才会连通
ping Win10的内网IP
ping VPS的内网IP
查看连接状态:sudo wg show
💥二、配置VPS到第二台Win10内网的WireGuard💦
🎄1、下载地址同上
🎎2、回到 VPS
输入:vim /etc/wireguard/wg0.conf
在内容末尾增加如下:
# Win10-2
[Peer]
PublicKey = Win10-2的公钥
AllowedIPs = Win10-2的内网IP/32
🎏3、在线添加节点,无需重启现有隧道
输入:wg set wg0 peer ‘Win10-2的公钥’ allowed-ips Win10-2的内网IP/32
再输入:sudo ip route replace Win10-2的内网IP/32 dev wg0 src VPS的内网IP
注:之所以有第二条,是因为 wg set 负责 WireGuard 配置,系统路由需要另行设置
🎑4、回到Win10-2的WireGuard客户端进行配置、连接
到vps,查看:sudo wg show wg0 查看新增节点:ip route get 10.10.2.2
🎁续:若遇虚机/本机能Ping通VPS,但是VPSPing不通虚机/本机
🎭管理员身份启动PowerShell,输入:
New-NetFirewallRule -Name “WG-Win10-Ping” -DisplayName “WireGuard Win10 Ping from VPS” -Direction Inbound -Protocol ICMPv4 -IcmpType 8 -LocalAddress 10.10.2.2 -RemoteAddress 10.10.1.1 -Action Allow -Profile Any
注:在win系统上编辑新增其它主机如10.10.2.1/32,不能有空格,编辑完成后,断开,到vps进行重启后,在进行启动连接,即可。
这个世界上肯定有另一个我,做着我不敢做的事情,过着我想过的生活。 ——山本文绪 《蓝另一种蓝》
この世界には、きっと他の自分もいるはずだ。自分がやれないことを行い、自分が望むような人生を送っている。 ——山本文绪『ブルー・アンド・オレンジ』
💥三、配置VPS到Ubuntu内网的WireGuard💦
🧵1、安装WireGuard
sudo apt update -y && sudo apt install -y wireguard
🎨2、生成 Ubuntu 密钥
sudo bash -c ‘umask 077; mkdir -p /etc/wireguard && wg genkey > /etc/wireguard/Ubuntu_private.key && wg pubkey < /etc/wireguard/Ubuntu_private.key > /etc/wireguard/Ubuntu_public.key && cat /etc/wireguard/Ubuntu_public.key’
释意:< 是读取 > 是写入 公钥是从生成的私钥计算出来的
🛒3、在vps编辑配置
sudo vim /etc/wireguard/wg0.conf
在末尾添加:
[Peer]
# Ubuntu
PublicKey = UBUNTU_PUBLIC_KEY
AllowedIPs = 10.10.2.2/32
🦺4、不停止现有隧道,立即添加运行中的节点
sudo wg set wg0 peer Ubuntu的公钥 allowed-ips 10.10.2.2/32
👓5、回到在 Ubuntu
执行:sudo vim /etc/wireguard/wg0.conf
[Interface]
Address = 10.10.2.3/32
PrivateKey = UBUNTU_PRIVATE_KEY
[Peer]
PublicKey = VPS_PUBLIC_KEY
Endpoint = VPS的IP:51820
AllowedIPs = 10.10.1.1/32
PersistentKeepalive = 25
🥼6、设置权限
sudo chmod 600 /etc/wireguard/wg0.conf
启动并设置开机自动连接:sudo systemctl enable –now wg-quick@wg0
查看状态: sudo wg show ip -4 addr show wg0
🎁续:如果 Ubuntu 还要访问其它内网主机(Win10主机也差不多),则💤
🥩步骤一:
编辑 Ubuntu 配置: sudo vim /etc/wireguard/wg0.conf
新添加路由为:AllowedIPs = 10.10.1.1/32, 10.10.2.1/32, 10.10.2.2/32
然后重启 Ubuntu 隧道:sudo systemctl restart wg-quick@wg0
🥟步骤二:
VPS 开启转发:sudo vim /etc/sysctl.d/99-wireguard-forward.conf
写入:net.ipv4.ip_forward=1
🍚步骤三:
应用配置:sudo sysctl –system
允许 WireGuard 节点之间转发:sudo ufw route allow in on wg0 out on wg0
查看:sudo ufw status verbose 之后到其它需要连通的主机修改wireguard配置,也在AllowedIPs增加Xubuntu的内网ip段,重启即可
🎁续: 关于删除Xubuntu的私钥和公钥、重新生成、连接操作💤
🚲1、在 Xubuntu 删除旧密钥
sudo systemctl stop wg-quick@wg0 2>/dev/null || true sudo systemctl disable wg-quick@wg0 2>/dev/null || true sudo rm -f /etc/wireguard/xubuntu_private.key sudo rm -f /etc/wireguard/xubuntu_public.key
确认已经删除: sudo ls -l /etc/wireguard/
🚠2、生成新的密钥
sudo install -d -m 700 /etc/wireguard
sudo sh -c ‘umask 077; wg genkey > /etc/wireguard/xubuntu_private.key; wg pubkey < /etc/wireguard/xubuntu_private.key > /etc/wireguard/xubuntu_public.key’
sudo chmod 600 /etc/wireguard/xubuntu_private.key
sudo chmod 644 /etc/wireguard/xubuntu_public.key
🛫3、查看新的 Xubuntu 公钥
sudo cat /etc/wireguard/xubuntu_public.key
查看新私钥,仅用于填写本机配置:sudo cat /etc/wireguard/xubuntu_private.key
使用记事本进行粘贴复制,防止手动输入出现问题,很重要这一步
🚩4、在VPS更新 Ubuntu 配置
sudo vim /etc/wireguard/wg0.conf
更新 VPS 中的 Ubuntu 公钥,保存后重启 VPS 的 WireGuard
sudo wg show wg0
🗾5、启动 Ubuntu 新隧道
sudo chmod 600 /etc/wireguard/wg0.conf
sudo systemctl enable --now wg-quick@wg0
sudo wg show wg0
🛩最后,互ping测试
鉴赏:
青玉案·元夕
贺铸 [北宋]
凌波不过横塘路,但目送、芳尘去。
锦瑟华年谁与度?月桥花院,琐窗朱户,只有春知处。
飞云冉冉蘅皋暮,彩笔新题断肠句。
试问闲情都几许?一川烟草,满城风絮,梅子黄时雨。
来自:@遥歌
💥附一:内外网远程桌面连接(RDP)内网Win10系统主机的操作💦
🔑最简单的方法
搭建好Wireguard内网穿透后,即可在内网进行远程桌面控制,Win+R输入:mstsc /v:内网IP 输入账户/密码
要特别注意是/v而不是\v
👒1、在 Win10中启用远程桌面,验证后台运行
开始—设置—系统—远程桌面—启用远程桌面
管理员 PowerShell 中添加规则:
New-NetFirewallRule -Name “WG-Win10RDP” -DisplayName “WireGuard Win10 RDP from VPS” -Direction Inbound -Protocol TCP -LocalPort 3389 -LocalAddress 10.10.2.1 -RemoteAddress 10.10.1.1 -Action Allow -Profile Any
这条新增规则允许 VPS 通过隧道访问远程桌面。已有的其他远程桌面规则不会被它自动收紧。
👝2、在 VPS 测试端口
执行:nc -vz -w 5 10.10.2.2 3389
🛶3、外网通过 Xshell 访问Win10内网远程桌面
流量转发路线:外网主机—SSH—阿里云 VPS—WireGuard—Win10
外网打开Xshell,vps——属性——连接——SSH——隧道/Tunneling——添加
填写:本地、127.0.0.1、端口为13389、目标主机为10.10.2.2、目标端口3389,保存、连接
🥁4、在指挥机Win+R输入mstsc /v:127.0.0.1:13389 /prompt
输入正确的账户/密码即可
注:若登一次登录进去出现了系统问题弹窗,那么就去mstsc点击显示选项—本地资源—取消勾选”打印机”
注:若要配置多个隧道则端口不能为同一个13389,可以换成13390、13391等,同时选中该行,点击连接,然后按住Win+R,输入:
mstsc /v:127.0.0.1:13390 /prompt
💥附二:通过vps来RDP连接win10内网的问题解决💦
🍤1. 设置远程桌面和端口
$rdpPath = ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server’
$tcpPath = ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp’
Set-ItemProperty -Path $rdpPath -Name fDenyTSConnections -Type DWord -Value 0
Set-ItemProperty -Path $tcpPath -Name UserAuthentication -Type DWord -Value 1
Set-ItemProperty -Path $tcpPath -Name fEnableWinStation -Type DWord -Value 1
Set-ItemProperty -Path $tcpPath -Name PortNumber -Type DWord -Value 3389
🥣2. 设置 RDP 服务自动启动
Set-Service -Name TermService -StartupType Automatic
Set-Service -Name SessionEnv -StartupType Automatic
Set-Service -Name UmRdpService -StartupType Manual
查看状态:Get-Service TermService,SessionEnv,UmRdpService
🥫3. 保留并启用已有防火墙规则
创建规则:New-NetFirewallRule -Name “WG-Win10” -DisplayName “WG-Win10-RDP” -Direction Inbound -Protocol TCP -LocalPort 3389 -Action Allow -Profile Any -Enabled True
直接执行:Set-NetFirewallRule -Name “WG-Win10” -Enabled True -Action Allow -Profile Any
查看规则:Get-NetFirewallRule -Name “WG-Win10” | Format-List Name,Enabled,Direction,Action,Profile
4. 重启 Windows 宿主机
🍦5、重新进入宿主机管理员
PowerShell:Get-NetTCPConnection -LocalPort 3389 -State Listen
或者:netstat -ano | findstr :3389
🍜6、然后在 VPS 测试
nc -vz -w 5 10.10.2.1 3389
🍗7、之后从有 WireGuard 路由的电脑连接
mstsc /v:10.10.2.1
标明:test1,暂完结
颜色编码:#FFF0F5、#DEE9F7 、#cc99ff、#e9fce9、123
欣赏
来源:via.iron0_0
声明:
评论(0)
暂无评论