frp内网穿透配置教程

title: "frp内网穿透配置教程" date: 2023-08-04T16:05:25+08:00 tags: ["Linux运维", "frp"] categories: [] draft: false 
$ tree /opt/frp /opt/frp ├── frpc ├── frpc_full.ini ├── frpc.ini ├── frps ├── frps_full.ini ├── frps.ini └── LICENSE 

1.1.Server配置

在具有公网 IP 的机器上部署 frps,修改 frps.ini 文件,这里使用了最简化的配置,设置了 frp 服务器用户接收客户端连接的端口。

#/opt/frp/frps.ini [common] bind_port = 7000 # 注意:需要在云服务设置开放7000端口 # 身份验证(可选) token = i*RY2KI9^A7H # web界面 dashboard_port = 7500 # dashboard 用户名密码,可选,默认为空 dashboard_user = admin dashboard_pwd = admin 

运行方式:/opt/frp/frps -c /opt/frp/frps.ini

1.2.Client配置

在需要被访问的内网机器上(SSH 服务通常监听在 22 端口)部署 frpc,修改 frpc.ini 文件,假设 frps 所在服务器的公网 IP 为 x.x.x.x。
local_ip 和 local_port 配置为本地需要暴露到公网的服务地址和端口。remote_port 表示在 frp 服务端监听的端口,访问此端口的流量将会被转发到本地服务对应的端口。

#/opt/frp/frpc.ini [common] server_addr = x.x.x.x server_port = 7000 # 身份验证(可选) token = i*RY2KI9^A7H [ssh] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 6000 # 注意:需要在云服务器上开放6000端口 

运行方式:/opt/frp/frpc -c /opt/frp/frpc.ini
访问内网机器的方式:ssh -p 6000 test@x.x.x.x

1.3.设置frps开机自启动

$ sudo vim /etc/systemd/system/frps.service $ systemctl cat frps # /etc/systemd/system/frps.service [Unit] # 服务名称,可自定义 Description = frp server After = network.target syslog.target Wants = network.target [Service] Type = simple # 启动frps的命令,需修改为您的frps的安装路径 ExecStart = /opt/frp/frps -c /opt/frp/frps.ini [Install] WantedBy = multi-user.target 
# 配置 frps 开机自启 systemctl enable frps # 启动frp systemctl start frps # 停止frp systemctl stop frps # 重启frp systemctl restart frps # 查看frp状态 systemctl status frps 

1.4.设置frpc开机自启动

$ sudo systemctl cat frpc # /etc/systemd/system/frpc.service [Unit] # 服务名称,可自定义 Description = frp client After = network.target syslog.target Wants = network.target [Service] Type = simple # 启动frps的命令,需修改为您的frps的安装路径 ExecStartPre = /bin/sleep 10 ExecStart = /opt/frp/frpc -c /opt/frp/frpc.ini [Install] WantedBy = multi-user.target 
$ systemctl get-default graphical.target $ cd /etc/systemd/system $ sudo vim frpc.service $ sudo systemctl enable frpc Created symlink /etc/systemd/system/multi-user.target.wants/frpc.service → /etc/systemd/system/frpc.service. $ sudo systemctl status frpc ● frpc.service - frp client Loaded: loaded (/etc/systemd/system/frpc.service; enabled; vendor preset: enabled) Active: inactive (dead) $ sudo systemctl restart frpc $ sudo systemctl status frpc ● frpc.service - frp client Loaded: loaded (/etc/systemd/system/frpc.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2023-08-06 05:13:52 UTC; 8s ago Main PID: 1361 (frpc) CGroup: /system.slice/frpc.service └─1361 /opt/frp/frpc -c /opt/frp/frpc.ini Aug 06 05:13:52 firefly systemd[1]: Started frp client. Aug 06 05:13:52 firefly frpc[1361]: 2023/08/06 05:13:52 [I] [root.go:220] start frpc service for config file [/opt/frp/frpc.ini] Aug 06 05:13:53 firefly frpc[1361]: 2023/08/06 05:13:53 [I] [service.go:301] [f8d3384fbb8c1471] login to server success, get run id [f8d3384fbb8c1471] Aug 06 05:13:53 firefly frpc[1361]: 2023/08/06 05:13:53 [I] [proxy_manager.go:150] [f8d3384fbb8c1471] proxy added: [ssh] Aug 06 05:13:53 firefly frpc[1361]: 2023/08/06 05:13:53 [I] [control.go:172] [f8d3384fbb8c1471] [ssh] start proxy success 

原文链接:https://www.cnblogs.com/devin1024/p/17604929.html

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享