外網(wǎng)環(huán)境下检眯,連接windows遠(yuǎn)程桌面時(shí),目標(biāo)主機(jī)必須有外網(wǎng)IP昆淡。然而很多情況下轰传,我們的主機(jī)都是沒(méi)有外網(wǎng)IP的,因此我通過(guò)Frp和一個(gè)具有外網(wǎng)IP的vps實(shí)現(xiàn)內(nèi)網(wǎng)穿透進(jìn)而進(jìn)行遠(yuǎn)程桌面瘪撇。
我所用的VPS為Vultr的主機(jī),有ipv4的公網(wǎng)ip港庄。配置為CentOS7x64,512M,20GB倔既。每月3.5刀。
首先將內(nèi)網(wǎng)windows主機(jī)的遠(yuǎn)程桌面打開(kāi)并配置防火墻鹏氧,這里不再細(xì)說(shuō)渤涌。
##一、VPS端部署Frp服務(wù)器端
首先使用如下命令從官方github下載服務(wù)器端frp并解壓:
~~~bash
wget https://github.com/fatedier/frp/releases/download/v0.16.1/frp_0.16.1_linux_amd64.tar.gz
tar -zxvf frp_0.16.1_linux_amd64.tar.gz
~~~
進(jìn)入frp所在的目錄:
~~~bash
cd frp_0.16.1_linux_amd64
~~~
使用命令nano frps.ini修改frps.ini文件:
~~~bash
[common]
bind_port = 7000
privilege_token = xxxxxx
dashboard_port = 7001
dashboard_user = user
dashboard_pwd = 123456
~~~
privilege_token是特權(quán)模式下與客戶端連接的密碼
dashboard_port是web控制頁(yè)面也可以不設(shè)置把还。
設(shè)置完成,后臺(tái)運(yùn)行frps并將日志寫(xiě)入logs文件:
./frps -c ./frps.ini -L logs &
可以使用如下命令實(shí)時(shí)查看日志文件:
tail -f logs
服務(wù)器端配置完成实蓬!
##二茸俭、windows主機(jī)上安裝Frp客戶端
下載windows版Frp:
https://github.com/fatedier/frp/releases/download/v0.16.1/frp_0.16.1_windows_amd64.zip
修改frpc.ini文件:
[common]
server_addr = xx.xx.xx.xx
server_port = 7000
privilege_token = xxxxxx
[RemoteDesktop]
type = tcp
local_addr = 127.0.0.1
local_port = 3389
remote_port = 7002
其中:
server_addr 是外網(wǎng)vps的ip地址
server_port要與設(shè)置服務(wù)器端時(shí)的bind_port一致,
privilege_token與服務(wù)器端一致
remote_port注意不要沖突
然后運(yùn)行frpc.exe安皱。
注意:
這里有一個(gè)坑调鬓,如果卡在以上界面,一段時(shí)間后報(bào)錯(cuò)酌伊,并且服務(wù)器logs沒(méi)有任何響應(yīng):
[W] [control.go:109] login to server failed: dial tcp 108.61.23.7:7000: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
dial tcp 108.61.23.7:7000: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
這時(shí)說(shuō)明服務(wù)器的防火墻沒(méi)有打開(kāi)該端口腾窝,centos7默認(rèn)為firewall防火墻,我這里還用iptables防火墻居砖。
注意到以下關(guān)于防火墻的命令:
我們需要將7000(服務(wù)器端中的bind_port)端口放行虹脯,再vps中輸入以下命令:
iptables -F
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 7000 -j ACCEPT
然后重新連接windows客戶端
連接成功!
現(xiàn)在就可以用vps的ip:端口號(hào)連接遠(yuǎn)程桌面了(本文為xx.xx.xx.xx:7002)奏候。