由于办公室是内网ip,以前一直用teamviewer连接办公室电脑。但2019年开始teamviewer软件被国内某公司代理了,老是弹出窗口要购买商业版,而且价格不便宜,于是果断抛弃。

要在家里控制办公室的电脑其实也很简单,主要的障碍是网络,由于ip问题,家里的电脑A找不到办公室的电脑B。但其实AB电脑都是接入因特网的,所以我们只要找一台同样接入因特网的中转机C,当作桥梁,让A和B电脑通过C连起来问题就解决了。

这时候我们需要一个中转机(可以买个VPS,价格比teamviewer便宜多了)还要一个连接工具frp 。

https://github.com/fatedier/frp

我们在中转机C(以linux的vps为例)上配置好ssh,考虑安全问题禁止密码,只用key登录。然后配置frp的server端frps

https://github.com/fatedier/frp/releases/download/v0.34.1/frp_0.34.1_linux_amd64.tar.gz

编辑frps.ini 修改

[common]
bind_addr=中转机的IP
bind_port = 你的端口
auto_token= anytoken
token = anytoken123

然后把frps注册成系统服务

vi /usr/lib/systemd/system/frps.service
写入
[Unit]
Description=frps
After=network.target

[Service]
TimeoutStartSec=30
ExecStart=/usr/local/bin/frps -c /etc/frp/frps.ini
ExecStop=/bin/kill $MAINPID

[Install]
WantedBy=multi-user.target


systemctl enable frps
systemctl start frps
systemctl status frps

到此服务端初步配置好,接下来配置客户端,办公室电脑B的frpc(windows)

下载 https://github.com/fatedier/frp/releases/download/v0.34.1/frp_0.34.1_windows_amd64.zip

由于安全问题,开始配置前修改windows的远程登陆端口,运行注册表编辑器regedit

修改两个键值

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\Tcp 下PortNumber
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TerminalServer\WinStations\RDP-TCP 下PortNumber

测试无误后我们要和中转机C和办公室电脑B连起来

编辑frpc.ini

[common]
server_addr = 中转机C的ip

server_port = 你的端口 (和C机一致)
token = anytoken(和C机一致)

[frprdp] 
type = tcp 
local_ip = 127.0.0.1 
local_port = 注册表修改后的远程登录端口 
remote_port = 任意一个比如12345 
use_encryption = true 
use_compression = true

到此B和C机连起来了,但还没完。

接下来配置B机frpc自启动,我们可以用Winsw.exe 将frpc注册为服务

https://github.com/winsw/winsw

编辑 WinSW.xml

<configuration>
    <!-- ID of the service. It should be unique accross the Windows system-->
  <id>frp-rdp</id>
  <!-- Display name of the service -->
  <name>frp-rdp</name>
  <!-- Service description -->
  <description>frp-rdp</description>
  
  <!-- Path to the executable, which should be started -->
    <executable>frpc</executable>
    <arguments>-c frpc.ini</arguments>
    <logmode>reset</logmode>
</configuration>

运行 Winsw.exe install注册,然后在系统服务里启动,并设置自启动以及启动失败后的自启动。

到此B和C机frp连接以及自启动搞定,最后配置安全问题。

由于C机暴露于公网,任意电脑都可以通过 中转机C的ip:端口 的方式用rdp连接你的工作机B机。而B机windows一般都是用户密码登录,密码简单的话容易被攻击破解,网上有很多被攻击然后加密勒索的例子。所以我们可以在C机上限制ip连接。

比如,只让家里电脑A的公网ip连接。

iptables -I INPUT -p tcp --dport 12345 -j DROP  

iptables -I INPUT -s A机的ip -ptcp --dport 12345 -j ACCEPT

到此位置A机通过C连接到B,安全问题也解决了。

标签: , , ,

留下回复(本站有评论邮件通知功能)