当前位置:网站首页>移动办公时如何使用frp内网穿透+teamviewer方式快速连入家中内网主机
移动办公时如何使用frp内网穿透+teamviewer方式快速连入家中内网主机
2022-07-05 15:33:00 【yuanfan2012】
移动办公时如何使用frp内网穿透+teamviewer方式快速连入家中内网主机
之前有写过腾讯云主机上部署FRP+Teamviewer穿透内网进行远程运维
本文基于该文章做了进一步优化
一、场景描述
如图所示
(图片可点击放大查看)
家中有一台24小时开机的NUC
操作系统为VMware ESXi7.0虚拟化平台
上面部署了如下虚拟机
(图片可点击放大查看)
其中CentOS7.9 虚拟机上部署了frpc内网穿透客户端
将内网Win7虚拟机(192.168.31.239)的Teamviewer(端口为5938)映射到了公网的腾讯云服务器
frpc与frps配置部分截图
(图片可点击放大查看)
(图片可点击放大查看)
这时如果需要在外办公的笔记本想通过Teamviewer访问家中内网的Win7虚拟机 需要云主机firewalld开放5938端口
需要输入命令
firewall-cmd --permanent --zone=public --add-port=5938/tcp
firewall-cmd --reload
然后云主机安全组也放开5938端口
(图片可点击放大查看)
这样在外办公的笔记本随时随时,只用Teamviewer连接云主机公网IP即可访问家中Win7虚拟机
(图片可点击放大查看)
(图片可点击放大查看)
二、安全考量
但是基于安全考量:安全组0.0.0.0过大,担心会有安全风险
所以这时想实现只允许当前笔记本所在网络的公网IP加入5938端口安全组白名单中
但是这样每次都要登录云服务器控制台手动加白,操作过于麻烦,并且耗时费力,一次操作下来估计得2~3分钟不止
所以想到一个相当较安全的方式
1、云控制台上安全组还是保持5938端口 允许0.0.0.0/0的安全组规则
2、已经移除public zone全局开放的5938端口
firewall-cmd --permanent --zone=public --remove-port=5938/tcp
firewall-cmd --reload
3、通过firewalld的rich-rule来实现加白
SSH登录后who am i 查看当前笔记本的出口公网IP
并将此公网IP使用rich-rule加白
[[email protected] ~]# who am i
root pts/1 2022-06-19 20:04 (XX.XX.XX.XX)
[[email protected] ~]#
[[email protected] ~]# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="XX.XX.XX.XX" port port="5938" protocol="tcp" accept'
success
[[email protected] ~]# firewall-cmd --reload
success
(图片可点击放大查看)
三、优化过程
能否将上面步骤的时间缩短一点呢?比如我在外办公的笔记本SSH登录一下云服务器执行个脚本就自动加白呢,这样是不是更方便
通过不断修改与反复测试脚本,最终实现了这一效果
脚本如下
[[email protected] ~]# vim teamviewer_add_loginIP.sh
[[email protected] ~]# cat teamviewer_add_loginIP.sh
#!/bin/bash
#清除Teamviewer_5938端口的历史rich-rules并重载
firewall-cmd --list-rich-rules| grep 5938 > /tmp/5938_richrules.txt
while read -r line
do
Temp_Rule=`echo $line`
echo $Temp_Rule
firewall-cmd --permanent --remove-rich-rule "$Temp_Rule"
firewall-cmd --reload
done < /tmp/5938_richrules.txt
#获取当前登陆服务器的IP地址,并对当前IP添加开放Teamviewer5938端口的rich-rule
LoginIP=$(who am i | awk '{print $5}' | sed 's/(//g' | sed 's/)//g')
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address='$LoginIP' port port="5938" protocol="tcp" accept'
firewall-cmd --reload
(图片可点击放大查看)
四、验证
在MacOS系统下使用方式
1、iTerm2下登录云服务器SSH(密钥方式免密登录)
2、执行脚本teamviewer_add_loginIP.sh
3、即可直接通过Teamviewer连接云服务器公网IP,即可连入家中Win7虚拟机 耗时10秒不到
边栏推荐
- Detailed explanation of C language branch statements
- 【 note 】 résoudre l'erreur de code IDE golang
- Summary of the second lesson
- Xiao Sha's arithmetic problem solving Report
- Parameter type setting error during batch update in project SQL
- 研发效能度量指标构成及效能度量方法论
- Intelligent metal detector based on openharmony
- Dataarts studio data architecture - Introduction to data standards
- Exception com alibaba. fastjson. JSONException: not match : - =
- 事务回滚异常
猜你喜欢
obj集合转为实体集合
Analytic hierarchy process of mathematical modeling (including Matlab code)
Verilog realizes the calculation of the maximum common divisor and the minimum common multiple
Xiao Sha's arithmetic problem solving Report
Appium自动化测试基础 — APPium基础操作API(一)
Codasip adds verify safe startup function to risc-v processor series
keep-alive
Research and practice of super-resolution technology in the field of real-time audio and video
Appium automation test foundation - appium basic operation API (I)
Good article inventory
随机推荐
Codasip为RISC-V处理器系列增加Veridify安全启动功能
MySQL overview
F. Min cost string problem solving Report
wyt 。。
Basic JSON operations of MySQL 5.7
keep-alive
Five common negotiation strategies of consulting companies and how to safeguard their own interests
19.[STM32]HC_ SR04 ultrasonic ranging_ Timer mode (OLED display)
抽象类和接口的区别
一文搞定vscode编写go程序
Xiao Sha's arithmetic problem solving Report
RLock锁的使用
Data communication foundation smart_ Link_&_ Monitor_ Link
The list set is summed up according to a certain attribute of the object, the maximum value, etc
Go language programming specification combing summary
力扣今日题-729. 我的日程安排表 I
MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
Temporary cramming before DFS examination
SQL injection sqllabs (basic challenges) 1-10
Data communication foundation - dynamic routing protocol rip