内网穿透工具frp使用

366 阅读1分钟

frp使用

frp是golang开发的内网穿透工具,日常我们本地的服务由于公网ip不固定,外网无法访问,有了内网穿透工具,就可以很轻松的把我们的服务暴露给外网使用。

下载

github.com/fatedier/fr…

这里我下载的是linux_amd64版本,根据自己需要下载

使用

frp分为服务端和客户端

Alt text

解压后 frp + sserver
解压后 frp + cclient

其中.ini为配置文件

frps.ini

[common]
bind_port = 7000 # frp 服务端暴露端口
vhost_http_port = 8099 # frp 客户端监听端口

frpc.ini

[common]
server_addr = your.remote.ip # 你的服务器ip
server_port = 7000 # 暴露端口

[web]
type = http # 类型
local_port = 8099 # 客户端端口
custom_domains = your.domain # 自定义域名

我们在 客户端上起一个服务

const http = require('http')

http.createServer(function(req, res){
   res.writeHead(200, { 'content-type': 'application/json' })
   res.end(JSON.stringify({
      data: 'success',
      code: 200
   }))
})
.listen(8099, function() {
    console.log(`listening at port 8099`)
})

在其他机器上访问 http://your.domain:8099 即可访问到原本本地的web服务

加入到系统命令中

systemd目录为自动脚本, 即linux中 service 命令对应的脚本

frps为例

  • 把可执行脚本frp 移动到 /usr/bin目录下

$ mv ./frps /usr/bin

  • 创建frp配置目录, 把 frps.ini 移动到该目录下

$ mkdir /etc/frp && mv frps.ini /etc/frp

  • 把相关自动执行脚本移动到systemd/system目录下

$ cd systemd && mv frps*service /etc/systemd/system

  • 启动

$ service frps start