frp代理上网
BioNote 2021-09-08
frp
# 参考
# 简介
frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网。
# 安装
下载软件
wget https://github.com/fatedier/frp/releases/download/v0.38.0/frp_0.38.0_linux_amd64.tar.gz
1
2
2
文件说明:
- frps.ini: 服务端配置文件
- frps: 服务端软件
- frpc.ini: 客户端配置文件
- frpc: 客户端软件
实现内网穿需要有一台公网服务器、域名。 公网服务器称为服务端,内网服务器称为客户端
# 文件配置
# 服务端
修改frps.ini
[common] #必须设置
bind_port = 7000 #是自己设定的frp服务端端口
vhost_http_port = 80 #是自己设定的http访问端口
token = 123 #核实身份用,加了更安全
[ssh] #ssh反向代理(不是必须设置)
listen_port = 6000 是自己设定的ssh访问端口
[web] #http反向代理[]里的内容可以自己设定,但是客户端和服务端必须要对应(如[aaa],[bbb]);
type = http #为服务类型,可以设为http,https
custom_domains = test1.a.com #为要映射的域名,记得域名的A记录要解析到外网主机的IP。
[web2] #同上(可设置多个)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
启动
./frps -c ./frps.ini
1
# 客户端
修改frpc.ini
[common]
server_addr = 远程frp服务器ip
server_port = 远程frp服务器端口
token = 远程frp服务器token
[http]
type = http
local_ip = 127.0.0.1
local_port = 本地端口号
remote_port = 远程frp服务器的http服务端口号
custom_domains = 自定义配置的域名
subdomain = 匹配服务端配置的subdomain_host
[ssh_test001]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 1111
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# systemctl启动
使用 systemctl 控制 frp
vim /usr/lib/systemd/system/frp.service
1
写入以下内容,注意软件路径和此处有关。这里是启动的客户端
[Unit]
Description=frpc daemon
[Service]
Type=simple
ExecStart=/home/pengbing/frp/frpc -c /home/pengbing/frp/frpc.ini
Restart=always
RestartSec=20s
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
启动/停止/重启,查看状态,设置开机自启/关闭开机自启
systemctl start frp
systemctl stop frp
systemctl restart frp
systemctl status frp
systemctl enable frp
systemctl disable frp
1
2
3
4
5
6
2
3
4
5
6