本文的目的是将服务器上的流量转发到客户端机器,如果服务器拥有公网ip,则可通过该方式实现内网穿透——访问服务器某个端口/域名 等同于 访问局域网内的客户端的某个端口。
服务器配置frps
下载frp可执行文件并解压,在该目录下,有 frps 和 frpc 两个可执行文件,分别是服务器端和客户端的可执行文件,将服务端移动到 /usr/local/bin
wget https://github.com/fatedier/frp/releases/download/v0.58.0/frp_0.58.0_linux_amd64.tar.gz
tar -vxf frp_0.58.0_linux_amd64.tar.gz
cd frp_0.58.0_linux_amd64
sudo mv frps /usr/local/bin新建 /etc/frps.toml
bindAddr = "0.0.0.0"
bindPort = 7000 # frp 客户端连接端口
vhostHTTPPort = 80 # 代理http
vhostHTTPSPort = 443 # 代理https
transport.tls.force = true
auth.method = "token"
auth.token = "xxxxxxxx" # 设置密码,请自行替换启动frp-server
创建自启动service,新建Systemd服务单元文件 /etc/systemd/system/frps.service
[Unit]
Wants=network-online.target
After=network-online.target
After=time-sync.target
ConditionPathExists=/etc/frps.toml
[Service]
ExecStart=/bin/sh -ec 'frps -c /etc/frps.toml'
[Install]
WantedBy=multi-user.target启动服务
sudo systemctl enable frps
sudo systemctl restart frps本地机配置frpc
下载并安装frp
wget https://github.com/fatedier/frp/releases/download/v0.58.0/frp_0.58.0_linux_amd64.tar.gz
tar -vxf frp_0.58.0_linux_amd64.tar.gz
cd frp_0.58.0_linux_amd64
sudo mv frpc /usr/local/bin新建 /etc/frpc.toml,这只是一个示例,请按需要进行修改。详细配置参见官网文档 https://gofrp.org/zh-cn/docs/ 。
serverAddr = "xx.xx.xx.xx" # 服务器ip
serverPort = 7000 # 服务器fprs端口
transport.tls.enable = true
auth.method = "token"
auth.token = "xxxxxxxx" # 服务器端配置的密码
# TCP 服务,将服务器30002端口的流量转发到本地30002端口
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 30002 # 被转发到本地的端口
remotePort = 30002 # 服务器监听端口
# TLS 终止
[[proxies]]
name = "typecho-https"
type = "https"
customDomains = ["forza0310.cn"]
# https 服务
[[proxies]]
name = "example"
type = "https"
localPort = 30004
customDomains = ["example.forza0310.cn"]创建自启动service,新建Systemd服务单元文件 /etc/systemd/system/frpc.service
[Unit]
After=network-online.target
After=time-sync.target
ConditionPathExists=/etc/frpc.toml
[Service]
ExecStart=/bin/sh -ec 'frpc -c /etc/frpc.toml'
Restart=on-failure
RestartSec=20
[Install]
WantedBy=multi-user.target启动服务
sudo systemctl enable frpc
sudo systemctl restart frpc