当前位置:网站首页>移动办公时如何使用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秒不到
边栏推荐
- Appium自动化测试基础 — APPium基础操作API(二)
- Fundamentals of data communication - Principles of IP routing
- list使用Stream流进行根据元素某属性数量相加
- sql中查询最近一条记录
- keep-alive
- list集合根据对象某属性求和,最大值等
- 数学建模之层次分析法(含MATLAB代码)
- Summary of the third class
- Appium自动化测试基础 — APPium基础操作API(一)
- The visual experience has been comprehensively upgraded, and Howell group and Intel Evo 3.0 have jointly accelerated the reform of the PC industry
猜你喜欢
Arduino控制微小的六足3D打印机器人
Replknet: it's not that large convolution is bad, but that convolution is not large enough. 31x31 convolution. Let's have a look at | CVPR 2022
Which keywords will conflict with the abstract keyword
一文搞定vscode编写go程序
wxml2canvas
F. Min cost string problem solving Report
D-snow halo solution
【简记】解决IDE golang 代码飘红报错
Batch update in the project
Information collection of penetration test
随机推荐
MySQL5.7的JSON基本操作
Data communication foundation - routing communication between VLANs
对象和类的关系
Object. defineProperty() - VS - new Proxy()
String modification problem solving Report
17. [stm32] use only three wires to drive LCD1602 LCD
sql中set标签的使用
抽象类中子类与父类
Good article inventory
list去重并统计个数
17.[STM32]仅用三根线带你驱动LCD1602液晶
Quick completion guide for manipulator (IX): forward kinematics analysis
Analytic hierarchy process of mathematical modeling (including Matlab code)
Defining strict standards, Intel Evo 3.0 is accelerating the upgrading of the PC industry
Modify PyUnit_ Time makes it support the time text of 'xx~xx months'
我们为什么要学习数学建模?
RLock锁的使用
Explanation report of the explosion
vant popup+其他组件的组合使用,及避坑指南
Subclasses and superclasses of abstract classes