侧边栏壁纸
博主头像
Blog博主等级

行动起来,活在当下

  • 累计撰写 211 篇文章
  • 累计创建 94 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

内网隧道ssh搭建方法

一、准备条件:

内网服务器:

假设IP为:192.168.1.189

ssh 端口: 7777

拥有公网IP的云服务器:

假设IP为:100.100.100.100

服务器需要开通两个端口,一个用于frps 和 frpc隧道通信,另一个用于接收内网服务器ssh的流量。

假设:

port1 : 8888

port2 : 9999

frp 客户端、服务端版本为:0.57.0

二、云服务器安装服务端(frps)

下载地址:

https://github.com/fatedier/frp/releases?page=1

选择amd64版本包。

解压到磁盘任意路径。进入frp文件位置。

编辑frps.toml,设置token,加密访问。

bindPort = 55555
auth.method = "token"
auth.token = "123123123123123123"

使用systemd管理frps服务

vi /etc/systemd/system/frps.service

[Unit]
# 服务名称,可自定义
Description = frp server
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
# 启动frps的命令,需修改为您的frps的安装路径
ExecStart = /frp/frps -c /frp/frps.toml

[Install]
WantedBy = multi-user.target

使用 systemd 命令,管理 frps

# 启动frp
systemctl start frps
# 停止frp
systemctl stop frps
# 重启frp
systemctl restart frps
# 查看frp状态
systemctl status frps
# 开机自启
systemctl enable frps

三、内网服务器安装客户端(frpc)

编辑frps.toml,设置token,token值要和服务端保持一致。

serverAddr = "100.100.100.100"
serverPort = 8888
auth.method = "token"
auth.token = "123123123123123123"
[[proxies]]
name = "test-ssh"
type = "tcp"
localIP = "192.168.1.189"
localPort = 2222
remotePort = 9999

local_ip 和 local_port 配置为本地需要暴露到公网的服务地址和端口。remote_port 表示在 frp 服务端监听的端口,访问此端口的流量将会被转发到本地服务对应的端口。

使用systemd管理frpc服务

vi /etc/systemd/system/frpc.service

[Unit]
# 服务名称,可自定义
Description = frp client
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
# 启动frps的命令,需修改为您的frps的安装路径
ExecStart = /frp/frpc -c /frp/frpc.toml

[Install]
WantedBy = multi-user.target

使用 systemd 命令,管理 frpc

# 启动frp
systemctl start frpc
# 停止frp
systemctl stop frpc
# 重启frp
systemctl restart frpc
# 查看frp状态
systemctl status frpc
# 配置开机自启
systemctl enable frpc

四、测试连通性

至此,服务端和客户端都已经正常启动了,我们可以通过 ssh 访问内网机器,假设用户名为 opus:

ssh -p 9999 opus@100.100.100.100

frp 会将请求 100.100.100.100:9999 的流量转发到内网机器 7777 端口。

五、一台内网服务器ssh 和web服务同时映射

外网服务端配置:

frps.toml

bindPort = 33334
vhostHTTPPort = 19091 #映射至公网的端口

内网客户端ssh及http服务配置

启动

systemctl start frps

frpc.toml

serverAddr = "公网IP地址"
serverPort = 33334

[[proxies]]
name = "prometheus"
type = "http"
localIP = "127.0.0.1"
localPort = 9090 #内网服务端口
customDomains = ["test.docker.abc"]

[[proxies]]
name = "ssh110"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22 #内网服务端口
remotePort = 60001

启动

systemctl start frpc

由于内网自定义了域名需要更改hosts

vi /etc/hosts

公网IP test.docker.abc

应用:

source /etc/hosts

其他电脑如果想访问服务也要手动添加hosts。

最后访问测试web:

http://test.docker.abc:19090

ssh测试:

ssh 公网IP:60001

六、配置参考

https://gofrp.org/zh-cn/docs/examples/vhost-http/

0

评论区