frp 是一个专注于内网穿透的高性能的反向代理应用。
场景:通过 SSH 访问内网机器
1 2 3 wget https://github.com/fatedier/frp/releases/download/v0.70.0/frp_0.70.0_linux_amd64.tar.gz tar -zxvf frp_0.70.0_linux_amd64.tar.gz cd frp_0.70.0_linux_amd64/
在具有公网 IP 的机器上部署 frps
1 2 bindPort = 7000 auth.token = "<token>" // 可选,提高安全性
1 nohup ./frps -c frps.toml > frps.out 2>&1 &
1 $ sudo vim /etc/systemd/system/frps.service
写入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 [Unit] # 服务名称,可自定义 Description = frp server After = network.target syslog.target Wants = network.target [Service] Type = simple # 启动frps的命令,需修改为您的frps的安装路径 ExecStart = /path/to/frps -c /path/to/frps.toml [Install] WantedBy = multi-user.target
1 2 3 4 5 6 7 8 9 10 # 启动frp sudo systemctl start frps # 停止frp sudo systemctl stop frps # 重启frp sudo systemctl restart frps # 查看frp状态 sudo systemctl status frps # 设置开机自启 sudo systemctl enable frps
在需要被访问的内网机器上部署 frpc
1 2 3 4 5 6 7 8 9 10 11 serverAddr = "x.x.x.x" // frps所在的公网IP serverPort = 7000 auth.token = "<token>" // 若服务端开启认证功能,则此项必填 [[proxies]] name = "ssh" type = "tcp" localIP = "127.0.0.1" // 内网服务地址 localPort = 22 // 内网服务端口 remotePort = 6000 // 服务端监听端口~
1 nohup ./frpc -c frpc.toml > frpc.out 2>&1 &
通过 SSH 访问内网机器
1 ssh -o Port=6000 user@x.x.x.x