赞
踩
注意:阿里云服务器如果不部署frp发现无法联通,重启下服务器就好了,我也不知道为啥
服务器要求:服务器版本:centos7,内核5.6+最好,有外网ip
1. wireguard服务端部署
2. wireguard客户端配置
3. frps部署
4. frpc配置
<code class="language-plaintext hljs">WireGuard® is an extremely simple yet fast and modern VPN that utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more useful than IPsec, while avoiding the massive headache. It intends to be considerably more performant than OpenVPN. WireGuard is designed as a general purpose VPN for running on embedded interfaces and super computers alike, fit for many different circumstances. Initially released for the Linux kernel, it is now cross-platform (Windows, macOS, BSD, iOS, Android) and widely deployable. It is currently under heavy development, but already it might be regarded as the most secure, easiest to use, and simplest VPN solution in the industry.</code>
● 配置精简,可直接使用默认值
● 只需最少的密钥管理工作,每个主机只需要 1 个公钥和 1 个私钥。
● 就像普通的以太网接口一样,以 Linux 内核模块的形式运行,资源占用小。
● 能够将部分流量或所有流量通过 VPN 传送到局域网内的任意主机。
<code class="language-plaintext hljs">frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网。</code>
如图所示,客户端和rdp服务器不直接联通,通过wireguard打通和阿里云server的连接,然后通过frp做对应端口转发到对应机器的对应端口
总的来说,wireguard用来组建内网环境:
● 阿里云server:10.0.0.1
● RDP_PC:10.0.0.2
● 其他客户端:10.0.0.3
frp用来做端口转发:将10.0.0.1:3389 -> 10.0.0.2:3389,然后其他客户端访问10.0.0.1:3389即访问到了远程桌面机器上
版本更新:直接访问10.0.0.2即可远程桌面
注意:内核升级有风险,升级失败概不负责,重要数据自行备份!
目前 WireGuard 已经被合并到 Linux 5.6 内核中了,如果你的内核版本 >= 5.6,就可以用上原生的 WireGuard 了,只需要安装 wireguard-tools 即可,内核版本<5.6,可能需要首先更新内核,否则可能会报错:Unable to access interface: Protocol not supported
离线安装脚本:
链接: 百度网盘 请输入提取码 提取码: p3pp
到服务器上解压,加权后sudo sh install.sh,安装完成后reboot重启服务器即可。
也可以自己找网上的例子升级内核;
接下来参考https://www.wireguard.com/ 官网安装教程安装
<code class="language-plaintext hljs">sudo yum install -y epel-release elrepo-releasesudo
yum install -y yum-plugin-elreposudo
yum install -y kmod-wireguard wireguard-tools</code>
1. 秘钥生成:
- # 服务端私钥
- wg genkey > server_privatekey
- # 服务端公钥
- wg pubkey < server_privatekey > server_publickey
- # 远程桌面服务器私钥
- wg genkey > rdp_pc_privatekey
- wg pubkey < rdp_pc_privatekey > rdp_pc_publickey
- # 其他客户端私钥
- wg genkey > client_privatekey
- wg pubkey < client_privatekey > client_publickey
- ls -l
可以看到6个文件,对应三个节点。
- ip link add wg0 type wireguard
- ip addr add 10.0.0.1/32 dev wg0
- wg set wg0 private-key ./server_privatekey
- ip link set wg0 up
- # 查看当前wireguard监听端口
- wg
- # 假设监听端口为30843
- # 配置客户端ip
- wg set wg0 peer $(cat './rdp_pc_publickey') allowed-ips 10.0.0.2/32 endpoint 118.36.79.121:30843
- wg set wg0 peer $(cat './client_publickey') allowed-ips 10.0.0.3/32 endpoint 118.36.79.121:30843
使用wg命令查看当前节点情况:
将服务端生成的server_publickey和rdp_pc_privatekey 拷贝到本地
客户端在https://www.wireguard.com/install/下载安装
编辑配置文件:
<code class="language-plaintext hljs">[Interface]
PrivateKey = (填rdp_pc_privatekey)
Address = 10.0.0.2/32
[Peer]
PublicKey = (填server_publickey)
AllowedIPs = 10.0.0.1/32
Endpoint = 118.36.79.121:30843
PersistentKeepalive = 25</code>
这里AllowedIPs填10.0.0.0/24即可,不再需要frp转发就能访问对面客户端了
将服务端生成的server_publickey和client_privatekey 拷贝到本地
<code class="language-plaintext hljs">brew install wireguard-tools</code>
- sudo mkdir /usr/local/etc/wireguard
- sudo touch /usr/local/etc/wireguard/wg0.conf
wg0.conf 文件如下:
<code class="language-plaintext hljs">[Interface]
Address = 10.0.0.3/32
PrivateKey = (填client_privatekey)
[Peer]
PublicKey = (填server_publickey)
Endpoint = 118.36.79.121:30843
AllowedIPs = 10.0.0.1/32
PersistentKeepalive = 25</code>
这里AllowedIPs填10.0.0.0/24即可,不再需要frp转发就能访问对面客户端了
- sudo wg-quick up wg0 # 启动Wireguard
- sudo wg-quick down wg0 #关闭WIreguard
- sudo wg # 查看Wireguard状态
可以在本地ssh root@10.0.0.1查看是否连通;可以在三台机器上各起一个http服务器,然后分别在rdp-pc机器/client机器上 curl 10.0.0.1:port;验证client -> server的连通性;
在server上curl 10.0.0.2:port;curl 10.0.0.3:port 验证 server -> peer1 / server -> peer2的连通性
如此一来,从10.0.0.2和10.0.0.3上就能访问10.0.0.1上的所有资源了,从10.0.0.1上也可以直接访问10.0.0.2,10.0.0.3上的资源。不过10.0.0.2和10.0.0.3不能直接连通,这时候就需要通过frp来做内网穿透了。
上面的AllowedIPs填10.0.0.0/24即可,不再需要frp转发客户端之间就能互通了
官方下载Releases · fatedier/frp · GitHub
- wget https://github.com/fatedier/frp/releases/download/v0.47.0/frp_0.47.0_linux_amd64.tar.gz
- tar -xvf frp_0.47.0_linux_amd64.tar.gz
- mv -f frp_0.47.0_linux_amd64 /usr/local/frp
- chmod +x /usr/local/frp/frpc
- chmod +x /usr/local/frp/frps
- # 默认监听端口为7000,可以在frps.ini中修改
- nohup /usr/local/frp/frps -c /usr/local/frp/frps.ini > /usr/local/frp/frps.log 2 > &1 &
vim /usr/local/frp/frpc.ini
<code class="language-plaintext hljs">[common]
server_addr = 127.0.0.1
server_port = 7000
[rdp]
type = tcp
local_ip = 10.0.0.2
local_port = 3389
remote_port = 3389</code>
nohup /usr/local/frp/frpc -c /usr/local/frp/frpc.ini > /usr/local/frp/frpc.log 2 > &1 &
至此全部部署完毕。在其他客户端上配置远程桌面地址为10.0.0.2即可访问rdp机器。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。