Frp-内网穿透反向代理安装配置

Frp-内网穿透反向代理安装配置

frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网。

测试环境

1
2
3
4
5
公网服务器(server端):
IP:68.79.111.111,centos7
内网服务器(client端):
IP:192.168.8.211,centos7
frp v0.43.0

下载网址,按需下载对应操作系统版本

https://github.com/fatedier/frp/

server配置

1
2
3
4
5
6
7
8
9
vi frps.ini

[common]
bind_port = 7111

## 启动
./frps -c frps.ini
## 或后台启动:
nohup /data/frp/frps -c /data/frp/frps.ini >>/data/frp/frps.log 2>&1 &

client配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
## 配置端口映射,这里server端7112映射到client端22端口,其他端口同理。
vi frpc.ini

[common]
server_addr = 68.79.111.111
server_port = 7111
## ssh 这个标签不能重复,建议用服务+端口命名
[ssh_7112]
type = tcp
local_ip = 68.79.111.111
local_port = 22
remote_port = 7112

## 启动:
./frpc -c frpc.ini
## 或后台启动:
nohup /data/frp/frpc -c /data/frp/frpc.ini >>/data/frp/frpc.log 2>&1 &

client service 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cat <<EOF > /usr/lib/systemd/system/frp.service
[Unit]
Description=frp
After=network.target

[Service]
Type=forking
User=root

ExecStart=/data/frp/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable frp
systemctl restart frp

登录测试

访问server的外网IP+7112端口,等于访问client端22端口,达到内网穿透的效果。