Skip to content

Commit 4fd0339

Browse files
committed
全网最全frp内网穿透
1 parent 5e8bc61 commit 4fd0339

2 files changed

Lines changed: 216 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
> - 微服务项目(SpringBoot+Mybatis+Dubbo+Mysql+Redis+RocketMQ)
1717
> - 数据结构与算法(Leetcode/剑指Offer)
1818
> - 常用工具
19+
>
1920
> **如果观看不流畅,可以去我的博客浏览面试知识点[dreamcat.ink](http://dreamcat.ink/)**
2021
2122
## 常用网站
@@ -365,6 +366,7 @@
365366

366367
## 工具篇
367368
- [IDEA开发的26个常用的配置](https://juejin.im/post/5e4d33abe51d4526f76eb2d3)
369+
- [全网最全frp内网穿透(ssh及web)](/Tools/frp/全网最全frp内网穿透(ssh及web).md)
368370

369371

370372

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
---
2+
title: frp内网穿透
3+
date: 2019-05-25 22:24:46
4+
author: DreamCat
5+
tags: frp
6+
id: frp1
7+
categories: Tool
8+
---
9+
10+
​ frp内网穿透,非常详细的步骤说明。
11+
12+
## 1. 准备工作
13+
14+
- vps(云服务器一台)
15+
- 访问目标设备(就是你最终要访问的设备)
16+
- 简单的Linux基础(会用cp等几个简单命令即可)
17+
18+
<!-- more -->
19+
20+
## 2. 下载frp
21+
22+
- [frp-github](<https://github.com/fatedier/frp>)
23+
- 选择release中对应的版本
24+
- 比如linux:[frp_0.27.0_linux_amd64.tar.gz](https://github.com/fatedier/frp/releases/download/v0.27.0/frp_0.27.0_linux_amd64.tar.gz)
25+
26+
27+
28+
## 3. 配置frp
29+
30+
### 1. 简单介绍
31+
32+
- frps(服务端启动)
33+
- frps.ini(服务器启动配置文件)
34+
- frpc(客户端启动)
35+
- frpc.ini(客户端启动配置文件)
36+
- 配置前先备份哦`cp`
37+
38+
### 2. 服务端
39+
40+
1. `vim frps.ini`
41+
42+
2. 有以下内容
43+
44+
```shell
45+
[common]
46+
bind_port = 7000
47+
dashboard_port = 7500
48+
token = 12345678
49+
dashboard_user = admin
50+
dashboard_pwd = admin
51+
```
52+
53+
- “bind_port”表示用于客户端和服务端连接的端口,这个端口号我们之后在配置客户端的时候要用到。
54+
- “dashboard_port”是服务端仪表板的端口,若使用7500端口,在配置完成服务启动后可以通过浏览器访问 x.x.x.x:7500 (其中x.x.x.x为VPS的IP)查看frp服务运行信息。
55+
- “token”是用于客户端和服务端连接的口令,请自行设置并记录,稍后会用到。
56+
- “dashboard_user”和“dashboard_pwd”表示打开仪表板页面登录的用户名和密码,自行设置即可。
57+
58+
3. `./frps -c frps.ini`
59+
60+
4. 若出现以下内容
61+
62+
```shell
63+
2019/01/12 15:22:39 [I] [service.go:130] frps tcp listen on 0.0.0.0:7000
64+
2019/01/12 15:22:39 [I] [service.go:172] http service listen on 0.0.0.0:10080
65+
2019/01/12 15:22:39 [I] [service.go:193] https service listen on 0.0.0.0:10443
66+
2019/01/12 15:22:39 [I] [service.go:216] Dashboard listen on 0.0.0.0:7500
67+
2019/01/12 15:22:39 [I] [root.go:210] Start frps success
68+
```
69+
70+
- 此时访问 x.x.x.x:7500 并使用自己设置的用户名密码登录,即可看到仪表板界面
71+
72+
5. 后台运行`nohup ./frps -c frps.ini &`
73+
74+
### 3. 客户端
75+
76+
1. `vim frpc.ini`
77+
78+
2. 有以下内容
79+
80+
```shell
81+
[common]
82+
server_addr = x.x.x.x # 服务器地址
83+
server_port = 7000 # 和服务器端口对应
84+
token = 12345678 # 和服务器token对应
85+
[ssh]
86+
type = tcp
87+
local_ip = 127.0.0.1
88+
local_port = 22
89+
remote_port = 2222
90+
```
91+
92+
- “server_addr”为服务端IP地址,填入即可。
93+
- “server_port”为服务器端口,填入你设置的端口号即可,如果未改变就是7000
94+
- “token”是你在服务器上设置的连接口令,原样填入即可。
95+
96+
3. `./frpc -c frpc.ini`
97+
98+
4. 后台运行如服务器同上
99+
100+
## 映射web项目的端口
101+
102+
### 服务端
103+
104+
`vim frps.ini`
105+
106+
```shell
107+
[common]
108+
bind_port = 6000
109+
token = mai
110+
vhost_http_port = 2020 # 这里很重要哈
111+
```
112+
113+
`./frps -c frps.ini`
114+
115+
### 客户端
116+
117+
`vim frpc.ini`
118+
119+
```shell
120+
[common]
121+
server_addr = 39.108.xx.xxx
122+
server_port = 6000
123+
token = mai
124+
125+
#[ssh]
126+
#type = tcp
127+
#local_ip = 127.0.0.1
128+
#local_port = 22
129+
#remote_port = 6000
130+
131+
# 举例第一个
132+
[web-flask]
133+
type = http
134+
local_port = 5000
135+
custom_domains = flask.dreamcat.ink
136+
137+
# 举例第二个
138+
[web-flask2]
139+
type = http
140+
local_port = 5001
141+
custom_domains = flask2.dreamcat.ink
142+
```
143+
144+
`./frpc -c frpc.ini`
145+
146+
**注意:custom_domains的域名需要去域名系统解析上述外网地址**
147+
148+
**访问:flask.dreamcat.ink**
149+
150+
**访问:flas2.dreamcat.ink**
151+
152+
## 4. 开机自启
153+
154+
### 1. 第一种
155+
156+
最简单粗暴的方式直接在脚本`/etc/rc.d/rc.local`(和`/etc/rc.local`是同一个文件,软链)末尾添加自己的**脚本**
157+
然后,增加脚本执行权限。
158+
159+
```shell
160+
nohup /home/dsp/config/frp/frpc -c /home/dsp/config/frp/frpc.ini &
161+
```
162+
163+
164+
165+
```shell
166+
chmod +x /etc/rc.d/rc.local
167+
```
168+
169+
### 2. 第二种
170+
171+
```shell
172+
crontab -e
173+
@reboot /home/user/test.sh
174+
```
175+
176+
### 每次登陆自动执行
177+
178+
也可以设置每次登录自动执行脚本,在`/etc/profile.d/`目录下新建sh脚本,
179+
`/etc/profile`会遍历`/etc/profile.d/*.sh`
180+
181+
### 第三种
182+
183+
**压缩包中有systemd,可利用这个服务开机自启**
184+
185+
**比如,将frps.server复制到`etc/systemd/system/`**
186+
187+
```shell
188+
[Unit]
189+
Description=Frp Server Service
190+
After=network.target
191+
192+
[Service]
193+
Type=simple
194+
User=nobody
195+
Restart=on-failure
196+
RestartSec=5s
197+
ExecStart=/usr/bin/frps -c /etc/frp/frps.ini ##这里记得对应的路径
198+
199+
[Install]
200+
WantedBy=multi-user.target
201+
```
202+
203+
**接着可以利用systemd命令,比如**
204+
205+
```shell
206+
systemctl start frps #启动
207+
systemctl stop frps #停止
208+
systemctl restart frps #重启
209+
systemctl status frps #查看状态
210+
systemctl enable frps #开机启动frp
211+
systemctl disable frps # 禁止启动
212+
```
213+
214+

0 commit comments

Comments
 (0)