温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux系统内网穿透工具FRP该怎么用

发布时间:2022-01-26 16:41:08 来源:亿速云 阅读:369 作者:柒染 栏目:开发技术
# Linux系统内网穿透工具FRP该怎么用 ## 一、FRP简介 FRP(Fast Reverse Proxy)是一款高性能的反向代理工具,专为解决内网穿透需求而设计。它通过将内网服务暴露到公网,实现远程访问内网设备的功能,支持TCP/UDP/HTTP/HTTPS等多种协议,广泛应用于以下场景: - 远程访问家庭NAS或树莓派 - 调试微信/支付宝本地开发环境 - 暴露内网Web服务到公网 - 跨网络访问公司内部系统 ## 二、核心概念 ### 1. 角色划分 - **服务端(frps)**:部署在具有公网IP的服务器上 - **客户端(frpc)**:运行在内网环境的设备上 ### 2. 配置文件 - `frps.ini`:服务端配置文件 - `frpc.ini`:客户端配置文件 ## 三、安装与配置 ### 1. 服务端安装(Linux) ```bash # 下载最新版本(示例为0.52.3) wget https://github.com/fatedier/frp/releases/download/v0.52.3/frp_0.52.3_linux_amd64.tar.gz # 解压并进入目录 tar -zxvf frp_0.52.3_linux_amd64.tar.gz cd frp_0.52.3_linux_amd64 

2. 服务端基础配置

编辑frps.ini文件:

[common] bind_port = 7000 # 客户端连接端口 dashboard_port = 7500 # 控制台端口 dashboard_user = admin # 控制台用户名 dashboard_pwd = yourpassword # 控制台密码 token = your_token_123 # 认证令牌 

3. 启动服务端

./frps -c frps.ini 

4. 客户端配置

编辑frpc.ini文件:

[common] server_addr = your_server_ip # 服务端公网IP server_port = 7000 # 对应服务端bind_port token = your_token_123 # 与服务端一致 [ssh] # 自定义服务名称 type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 6000 # 公网访问端口 

5. 启动客户端

./frpc -c frpc.ini 

四、典型应用场景

1. SSH穿透

[ssh] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 6000 

连接命令:

ssh -p 6000 username@server_ip 

2. HTTP/HTTPS服务穿透

[web] type = http local_port = 8080 custom_domains = your.domain.com 

3. 远程桌面(Windows)

[rdp] type = tcp local_ip = 192.168.1.100 local_port = 3389 remote_port = 7001 

五、进阶配置

1. 开机自启(Systemd)

创建服务文件/etc/systemd/system/frps.service

[Unit] Description=Frp Server Service After=network.target [Service] Type=simple ExecStart=/path/to/frps -c /path/to/frps.ini [Install] WantedBy=multi-user.target 

启用服务:

systemctl enable frps systemctl start frps 

2. 多端口映射

[range:test_tcp_ports] type = tcp local_ip = 127.0.0.1 local_port = 10000-10010 remote_port = 10000-10010 

3. 负载均衡

[load_balance] type = tcp local_port = 80 remote_port = 6001 group = web group_key = 123456 

六、安全建议

  1. 强密码策略:使用复杂token和dashboard密码

  2. 防火墙配置

    # 开放必要端口 ufw allow 7000/tcp ufw allow 7500/tcp 
  3. 限制访问IP

    [common] allow_ports = 6000-6005 
  4. HTTPS加密(配置示例):

    [common] tls_enable = true tls_cert_file = server.crt tls_key_file = server.key 

七、常见问题解决

  1. 连接失败

    • 检查服务端防火墙设置
    • 验证token是否一致
    • 使用telnet server_ip 7000测试端口连通性
  2. 端口冲突

    netstat -tunlp | grep 7000 
  3. 日志查看

    journalctl -u frps -f 
  4. 版本兼容: 确保客户端和服务端使用相同大版本

八、性能优化

  1. 启用压缩(客户端配置):

    [common] tcp_mux = true compression = true 
  2. 调整心跳参数:

    [common] heartbeat_interval = 30 heartbeat_timeout = 90 

通过以上配置,您可以在Linux系统上快速搭建稳定的内网穿透服务。FRP的灵活配置能满足各种复杂场景需求,建议通过官方文档(https://gofrp.org/docs/)获取最新功能信息。 “`

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI