内网穿透的搭建工具

查看主机cpu架构

1
arch

下载frp工具

SSH连接上外网主机后,使用wget指令下载frp。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
https://github.com/fatedier/frp
wget https://github.com/fatedier/frp/releases/download/v0.xx.0/frp_0.xx.0_linux_amd64.tar.gz
arch // 查看CPU架构选择以下版本
# 版本选择说明:
# frp_0.xx.0_darwin_amd64.tar.gz —— 适用于Mac OS系统
# frp_0.xx.0_freebsd_386.tar.gz —— 适用于FreeBSD 32位系统
# frp_0.xx.0_freebsd_amd64.tar.gz —— 适用于FreeBSD 64位系统
# frp_0.xx.0_linux_386.tar.gz —— 适用于Linux 32位系统
# frp_0.xx.0_linux_amd64.tar.gz —— 适用于Linux 64位系统
# frp_0.xx.0_linux_arm.tar.gz —— 适用于Linux 32位嵌入式系统
# frp_0.xx.0_linux_arm64.tar.gz —— 适用于Linux 64位嵌入式系统
# frp_0.xx.0_linux_mips.tar.gz
# frp_0.xx.0_linux_mips64.tar.gz
# frp_0.xx.0_linux_mips64le.tar.gz
# frp_0.xx.0_linux_mipsle.tar.gz
# frp_0.xx.0_windows_386.zip —— 适用于Windows 32位系统
# frp_0.xx.0_windows_amd64.zip —— 适用于Windows 64位系统

安装frp工具

使用tar指令解压tar.gz文件

1
tar -zxvf frp_0.20.0_linux_amd64.tar.gz

使用tar指令解压tar.gz文件

1
2
3
4
5
tar -zxvf frp_0.20.0_linux_amd64.tar.gz
cd frp_0.20.0_linux_amd64/
#外网主机作为服务端,可以删掉不必要的客户端文件,使用rm指令删除文件。
rm -f frpc
rm -f frpc.ini

接下来要修改服务器配置文件,即frps.ini文件。使用vi指令对目标文件进行编辑。

[common]部分是必须有的配置,其中bind_port是自己设定的frp服务端端口,vhost_http_port是自己设定的http访问端口。
保存上面的配置后,使用以下指令启动frp服务端。(如果需要在后台运行,请往下翻阅关于后台运行的部分。)

1
2
3
4
5
6
7
8
9
10
11
vi frps.ini
########################################
# frps.ini 文件配置
[common]
bind_port = 7000
vhost_http_port = 8000
vhost_https_port = 443
auto_token =lancema.com
########################################
#启动服务
./frps -c ./frps.ini

客户端的配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[common]
server_addr = 113.31.113.211
server_port = 7000
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000
; [web]
; type = http
; local_port = 80
; custom_domains = frps.lancema.com
[web_htts2http]
type = https
custom_domains = frps.lancema.com
plugin = https2http
plugin_local_addr = 127.0.0.1:80
# HTTPS 证书相关的配置
plugin_crt_path = .\frps.lancema.com\ssl\frps.lancema.com.crt // .crt windows下文件及路径, Liunx下为.pem
plugin_key_path = .\frps.lancema.com\ssl\frps.lancema.com.key
plugin_host_header_rewrite = 127.0.0.1
plugin_header_X-From-Where = frp

开机启动windows

  • 新建frps.service文件可以复制,也可以自己新建
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cp ./**/systemd/frps.service /usr/lib/systemd/system/frps.service
vi /usr/lib/systemd/system/frps.service

[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/frps/frps -c /usr/local/frps/frps.ini

[Install]
WantedBy=multi-user.target

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#加载开机配置文件 
systemctl daemon-reload

# 设定开机启动
systemctl enable frps

# 启动服务
systemctl start frps

# 停止服务
systemctl stop frps

# 重启服务
systemctl restart frps

# 取消开机启动
systemctl disable frps

# 查看服务状态
systemctl status frps
  • docker-compose下配置
    • frpc.ini
1
2
3
4
5
6
7
8
9
[common]
server_addr = 113.31.113.211
server_port = 7000
privilege_token = frp_lancema

[frps-web]
type = http
local_port = 80
custom_domains = frps.lancema.com
  • frps.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 服务端和客户端通信的连接端口
bind_port = 7000

# 连接验证的密码
privilege_token = frp_lancema

# 控制面板的端口 用户名 密码配置
dashboard_port = 7400
dashboard_user = admin_lancema
dashboard_pwd = Mfrp224330.?

# web服务端口
vhost_http_port = 8866
#vhost_https_port = 4443
  • docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
version: '3.6'

networks:
  nginx_bridge:
    driver: bridge

services:
  nginx:
    container_name: nginx-frps
    image: nginx:1.19.5
    #build: /usr/local/docker-compose/frps
    links:
      - frps
    ports:
      - 80:80
      - 443:443
    restart: always
    #working_dir: /data/www/frps
    volumes:
      #- /data/www/frps:/usr/local/nginx/html
      - ./nginx/conf:/etc/nginx/conf.d
      - ./nginx/cert:/etc/nginx/cert
    networks:
      - nginx_bridge
  frps:
    image: snowdreamtech/frps:0.34.0
    container_name: frps
    hostname: frp
    restart: always
    #expose:
    #  - 8866
    #ports:
    #  - 7000:7000
    #  - 8866:8866
    volumes:
      - ./frps/frps.ini:/etc/frp/frps.ini
    network_mode: host