版本更新:不再需要frp即可客戶端之間相互訪問
注意:阿里云服務(wù)器如果不部署frp發(fā)現(xiàn)無法聯(lián)通,重啟下服務(wù)器就好了,我也不知道為啥
服務(wù)器要求:服務(wù)器版本:centos7,內(nèi)核5.6+最好,有外網(wǎng)ip
總覽
1. wireguard服務(wù)端部署
2. wireguard客戶端配置
3. frps部署
4. frpc配置
wireguard簡(jiǎn)介
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.
wireguard優(yōu)點(diǎn)
● 配置精簡(jiǎn),可直接使用默認(rèn)值
● 只需最少的密鑰管理工作,每個(gè)主機(jī)只需要 1 個(gè)公鑰和 1 個(gè)私鑰。
● 就像普通的以太網(wǎng)接口一樣,以 Linux 內(nèi)核模塊的形式運(yùn)行,資源占用小。
● 能夠?qū)⒉糠至髁炕蛩辛髁客ㄟ^ VPN 傳送到局域網(wǎng)內(nèi)的任意主機(jī)。
frp簡(jiǎn)介
frp 是一個(gè)專注于內(nèi)網(wǎng)穿透的高性能的反向代理應(yīng)用,支持 TCP、UDP、HTTP、HTTPS 等多種協(xié)議??梢詫?nèi)網(wǎng)服務(wù)以安全、便捷的方式通過具有公網(wǎng) IP 節(jié)點(diǎn)的中轉(zhuǎn)暴露到公網(wǎng)。
部署架構(gòu)

如圖所示,客戶端和rdp服務(wù)器不直接聯(lián)通,通過wireguard打通和阿里云server的連接,然后通過frp做對(duì)應(yīng)端口轉(zhuǎn)發(fā)到對(duì)應(yīng)機(jī)器的對(duì)應(yīng)端口
總的來說,wireguard用來組建內(nèi)網(wǎng)環(huán)境:
● 阿里云server:10.0.0.1
● RDP_PC:10.0.0.2
● 其他客戶端:10.0.0.3
frp用來做端口轉(zhuǎn)發(fā):將10.0.0.1:3389 -> 10.0.0.2:3389,然后其他客戶端訪問10.0.0.1:3389即訪問到了遠(yuǎn)程桌面機(jī)器上
版本更新:直接訪問10.0.0.2即可遠(yuǎn)程桌面
wireguard服務(wù)端部署
內(nèi)核升級(jí)
注意:內(nèi)核升級(jí)有風(fēng)險(xiǎn),升級(jí)失敗概不負(fù)責(zé),重要數(shù)據(jù)自行備份!
目前 WireGuard 已經(jīng)被合并到 Linux 5.6 內(nèi)核中了,如果你的內(nèi)核版本 >= 5.6,就可以用上原生的 WireGuard 了,只需要安裝 wireguard-tools 即可,內(nèi)核版本<5.6,可能需要首先更新內(nèi)核,否則可能會(huì)報(bào)錯(cuò):Unable to access interface: Protocol not supported
離線安裝腳本:
鏈接: 百度網(wǎng)盤 請(qǐng)輸入提取碼 提取碼: p3pp
到服務(wù)器上解壓,加權(quán)后sudo sh install.sh,安裝完成后reboot重啟服務(wù)器即可。
也可以自己找網(wǎng)上的例子升級(jí)內(nèi)核;
接下來參考https://www.wireguard.com/ 官網(wǎng)安裝教程安裝
wireguard安裝
sudo yum install -y epel-release elrepo-releasesudo
yum install -y yum-plugin-elreposudo
yum install -y kmod-wireguard wireguard-tools
wireguard配置
開啟內(nèi)核轉(zhuǎn)發(fā)
命令行配置
1. 秘鑰生成:
# 服務(wù)端私鑰
wg genkey > server_privatekey
# 服務(wù)端公鑰
wg pubkey < server_privatekey > server_publickey
# 遠(yuǎn)程桌面服務(wù)器私鑰
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個(gè)文件,對(duì)應(yīng)三個(gè)節(jié)點(diǎn)。
創(chuàng)建虛擬網(wǎng)卡配置wireguard
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
# 查看當(dāng)前wireguard監(jiān)聽端口
wg
# 假設(shè)監(jiān)聽端口為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命令查看當(dāng)前節(jié)點(diǎn)情況:

阿里云防火墻攔截策略放開39184端口
阿里云登錄 - 歡迎登錄阿里云,安全穩(wěn)定的云計(jì)算服務(wù)平臺(tái)
wireguard客戶端配置
windows客戶端配置
將服務(wù)端生成的server_publickey和rdp_pc_privatekey 拷貝到本地
客戶端在https://www.wireguard.com/install/下載安裝
編輯配置文件:
[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
這里AllowedIPs填10.0.0.0/24即可,不再需要frp轉(zhuǎn)發(fā)就能訪問對(duì)面客戶端了
mac客戶端
將服務(wù)端生成的server_publickey和client_privatekey 拷貝到本地
安裝
brew install wireguard-tools
配置 WireGurad 客戶端
sudo mkdir /usr/local/etc/wireguard
sudo touch /usr/local/etc/wireguard/wg0.conf
wg0.conf 文件如下:
[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
這里AllowedIPs填10.0.0.0/24即可,不再需要frp轉(zhuǎn)發(fā)就能訪問對(duì)面客戶端了
啟動(dòng) WireGuard
sudo wg-quick up wg0 # 啟動(dòng)Wireguard
sudo wg-quick down wg0 #關(guān)閉WIreguard
sudo wg # 查看Wireguard狀態(tài)
wireguard效果驗(yàn)證
可以在本地ssh root@10.0.0.1查看是否連通;可以在三臺(tái)機(jī)器上各起一個(gè)http服務(wù)器,然后分別在rdp-pc機(jī)器/client機(jī)器上 curl 10.0.0.1:port;驗(yàn)證client -> server的連通性;
在server上curl 10.0.0.2:port;curl 10.0.0.3:port 驗(yàn)證 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不能直接連通,這時(shí)候就需要通過frp來做內(nèi)網(wǎng)穿透了。
上面的AllowedIPs填10.0.0.0/24即可,不再需要frp轉(zhuǎn)發(fā)客戶端之間就能互通了
frps部署
官方下載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
frps啟動(dòng)
# 默認(rèn)監(jiān)聽端口為7000,可以在frps.ini中修改
nohup /usr/local/frp/frps -c /usr/local/frp/frps.ini > /usr/local/frp/frps.log 2 > &1 &
frpc配置啟動(dòng)
frp配置文件修改
vim /usr/local/frp/frpc.ini文章來源:http://www.zghlxwxcb.cn/news/detail-808384.html
[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
frpc啟動(dòng)
nohup /usr/local/frp/frpc -c /usr/local/frp/frpc.ini > /usr/local/frp/frpc.log 2 > &1 &
至此全部部署完畢。在其他客戶端上配置遠(yuǎn)程桌面地址為10.0.0.2即可訪問rdp機(jī)器。文章來源地址http://www.zghlxwxcb.cn/news/detail-808384.html
到了這里,關(guān)于使用wireguard+frp實(shí)現(xiàn)內(nèi)網(wǎng)穿透遠(yuǎn)程桌面的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!