Files
doc/docs/nas-skill/5-frpc.md
2024-01-01 14:36:11 +08:00

155 lines
4.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
sidebar_position: 5
---
# 内网穿透
内网穿透就是无论你的盒子所处网络是否有公网IP无论是否在复杂内部网络下只要你的盒子能联通上网就可以做好穿透让你在异地随时访问和管理海纳思系统。
## 系统内置 frpc
海纳思系统hinas内置了一个frpc的穿透客户端软件
但是并没有开启,也没有运行。
终端输入 ```frpc -v``` 可以看到它的版本号
终端输入 ```systemctl enable frpc``` 可以设置为开机自启动
终端输入 ```systemctl start frpc``` 可以运行它
终端输入 ```systemctl status frpc``` 可以查看它运行后的状态是否正确
如果你不喜欢,可以完全删除它
```bash
sudo apt purge frpc-histb
```
当然,如果你哪天又想用了,就安装
```bash
sudo apt update && sudo apt install frpc-histb
sudo reboot
#重新安装可能需要重启系统
```
:::tip
FRP软件的的官方教程[FRP官方教程网站](https://gofrp.org/zh-cn/docs/)
:::
## 开通 frpc 账号
如果你没有自己搭建的 frps 服务器,可以捐赠 25 元1年使用作者搭建的。
未开通前:终端输入 `kaitong-frp`
![](./img/frpc1.jpg)
将你的设备识别码发给作者,捐赠后,继续输入 `kaitong-frp` 即可开通。
## 手动配置案例
如果你开通的是作者的 frpc 账号,首次使用是默认穿透 22 端口和 web 程序的 443 端口。
配置文件位置: `/etc/frp/frpc.toml`
此时,你可以使用两个基本功能:
### 1. 远程 ssh 访问盒子终端后台
```bash
ssh -p xxxxx root@any168.net
```
xxxxx 是指随机分配给你账号的 frps 服务器端口。
配置的模块示例:
```bash
...#前面的是账号信息(不可泄露)
[[proxies]]
name = "ssh-21590"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 21590
#这里的21590端口就是直达你的盒子的网路
```
:::caution
从上面的配置可以看出来一旦你开通了frpc账号别人就可以从扫描作者的frps服务器端口进而入侵你的盒子。
开通后你的22端口就会通过frps的21590暴露在互联网上。
所以:请务必更改你的后台密码为高强度密码!
这个非常重要。修改密码教程看这里:[开始使用-密码修改](/docs/tutorial-extras/start#修改密码)
:::
客户端远程登录示例21590端口是一个例子请填写你的盒子实际分配的端口。
![](./img/frpc2.png)
### 2.远程访问你的盒子首页
开通后,会默认分配一个域名到你的盒子首页:
这个域名可以直达你的盒子首页外网的程序。相当于你的盒子首页就是一个公开的网站。
你可以在 `使用说明` 里找到这个域名;或者终端输入 `kaitong-frp -u` 显示出来。
![](./img/frpc3.jpg)
:::tip
无论你重置系统或者重新刷机海思芯片的机顶盒账号是绑定cpu的(S805盒子重置系统也不会变)
都可以在终端输入 `nasupdate` 然后输入 `kaitong-frp` 命令复通。
:::
注意:一个穿透的域名对应一个穿透的端口。
配置文件里的穿透模块示例:
```bash
[[proxies]]
name = "xxxxx"
type = "https"
subdomain = "nas-xxxxx"
#如果你有自己的域名,可以同时打开这行,你的域名要解析到frps服务器
#customDomains = ["hinas.yourdomain.com"]
[proxies.plugin]
type = "https2http"
localAddr = "127.0.0.1:80"
#如果使用自己的域名,请自行制作你的SSL替换到下面文件位置
crtPath = "/etc/frp/slitaz.tk.crt"
keyPath = "/etc/frp/slitaz.tk.key"
requestHeaders.set.x-from-where = "frp"
```
### 3.增加穿透访问其他端口的程序
你可以通过修改 `/etc/frp/frpc.toml` 配置文件,增加你需要的穿透。
这里举两个例子:
1.穿透盒子的 `青龙面板` 程序5700端口(用默认域名)
```bash
[[proxies]]
name = "zhangsandeqinglong"
type = "http"
localPort = 5700
subdomain = "zhangsandeqinglong"
```
这样你就可以访问域名直达你的青龙面板程序了: `http://zhangsandeqinglong.any168.net`
2.穿透盒子的 `青龙面板` 程序5700端口(用自己的域名)
```bash
[[proxies]]
name = "zhangsandeqinglong"
type = "http"
localPort = 5700
customDomains = ["ql.yourdomain.com"]
```
这样你就可以访问域名直达你的青龙面板程序了: `http://ql.yourdomain.com`