胖蒜

分享有价值的资源

利用vps+frp实现访问公司内网windows远程桌面

使用frp内网穿透工具使处于内网中的电脑能够像访问公网电脑一样方便,比如将公司或个人电脑里面的web项目让别人能够访问以便于自己及时修改,或者是进行远程或ssh连接。

主要分三个步骤:

一、购买VPS,注意开通入站规则:

入站规则

二、下载frp软件,设置服务端参数,并上传运行:

下载地址:https://github.com/fatedier/frp/releases

~]# vim frps.ini 
[common]
bind_port = 7000  # vps需要监听的端口,用于和frp 客户端连接。

启动服务,作为后台运行。

nohup frp/frps -c frp/frps.ini & &> /dev/null

三、windows安装、配置、开机自启动运行frp client:

配置frpc.ini, 表示frp client端配置文件。

[common]
server_addr = 107.172.67.xx #服务器的IP
server_port = 7000                #服务器监听的port,同上面bind_port的值
[rdp]
type = tcp
local_ip = 127.0.0.1           
local_port = 3389                 # 当用户连接以下 frp server的5200端口时,会被转发到frp client的3389端口(远程桌面的默认端口)。 
remote_port = 5200              # frpc 在与frps建立连接后,server会监听于此端口用于被用户连接。需要打开frps的防火墙给此端口。

写一个bat脚本用于启动frp client。
编辑一个内容如下的文件,文件名为frp.bat。

@echo off  
start  "C:\Windows\System32\cmd.exe"   
cd C:\Users\Administrator\Desktop\frp_0.20.0_windows_amd64\frp_0.20.0_windows_amd64 
frpc -c frpc.ini
exit  
* start  "C:\Windows\System32\cmd.exe"   表示打开一个cmd命令行
* 命令段
* exit  退出打开的命令行

注意:
1)C:\Users\Administrator\Desktop\frp_0.20.0_windows_amd64\frp_0.20.0_windows_amd64 此处目标目录是frpc程序所在的目录;
2)脚本中的命令应该先测试能正常执行;
3)这里有一个坑,如果卡在以上界面,一段时间后报错,并且服务器logs没有任何响应:

[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.

这时说明服务器的防火墙没有打开该端口,centos7默认为firewall防火墙,我这里还用iptables防火墙。
注意到以下关于防火墙的命令:
我们需要将7000(服务器端中的bind_port)端口放行,再vps中输入以下命令:

iptables -F
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 7000 -j ACCEPT

然后重新连接windows客户端。

本文转载自:
https://blog.51cto.com/sonlich/2126175
https://www.cnblogs.com/zhanggaoxing/p/9221705.html
https://www.jianshu.com/p/a6e9627dbe29
https://www.jianshu.com/p/4c6c1564a610

感觉很棒,欢迎点赞 OR 打赏~

分享到:

评论 (0)

立即登录评论
可联系QQ744272645咨询
马上咨询 自媒体号