Linux-frp内网穿透

本文详细指导如何在Linux环境下使用frp实现内网穿透,包括服务端和客户端的配置,开机自启动设置,以及注意事项。重点讲解了frps.ini和frpc.ini的配置参数,并演示了如何创建系统服务来自动运行。
摘要由CSDN通过智能技术生成

说明

  • Linux搭建frp实现内网穿透

操作步骤

  • 安装步骤省略(下载解压拷贝到server服务器和client服务器完事)具体移步:github

    • 注意程序文件需要追加可执行权限!
    • 注意相关端口放行!
  • 服务端配置文件:frps.ini

    [common]
    bind_port = 7777
    authentication_method = token
    token = 12345678
    tls_only = true
    kcp_bind_port = 7777
    max_pool_count = 10
    log_file = /path/to/frp/frps.log
    ### trace, debug, info, warn, error
    log_level = error
    log_max_days = 3
    
    # allow_ports = 1,4-5
    
    vhost_http_port = 80
    vhost_https_port = 443
    
    dashboard_port = 10
    dashboard_user = admin
    dashboard_pwd = 12345678
    
    
  • 客户端配置文件:frpc.ini

    [common]
    server_addr = 8.8.8.8
    server_port = 7777
    tls_enable = true
    token = 12345678
    protocol = kcp
    # pool_count = 5
    log_file = /root/frp/frpc.log
    log_level = trace
    log_max_days = 3
    
    [ssh]
    type = tcp
    local_ip = 127.0.0.1
    local_port = 22
    remote_port = 1
    
    [http:test]
    type = http
    local_ip = 127.0.0.1
    local_port = 80
    custom_domains = test.top
    proxy_protocol_version = v2
    
    [https:test]
    type = https
    local_port = 443
    custom_domains = test.top
    proxy_protocol_version = v2
    use_encryption = true
    use_compression = true
    #plugin = https2http
    #plugin_local_addr = 127.0.0.1:80
    #plugin_crt_path = /path/to/test.pem
    #plugin_key_path = /path/to/test.key
    #plugin_host_header_rewrite = test.top
    #plugin_header_X-From-Where = frp
    
    
  • 服务端开机自启动

    # 添加系统服务
    sudo vim /lib/systemd/system/frps.service
    
    # 服务内容
    [Unit]
    Description=frps service
    After=network.target syslog.target
    Wants=network.target
    
    [Service]
    Type=simple
    ExecStart=/path/to/frp/frps -c /path/to/frp/frps.ini
    
    [Install]
    WantedBy=multi-user.target
    
    # 启动
    sudo systemctl start frps
    
    # 开机启动
    sudo systemctl enable frps
    
    # 其它命令
    sudo systemctl restart frps
    sudo systemctl stop frps
    sudo systemctl status frps
    
    
  • 客户端开机自启动

    # 添加系统服务
    sudo vim /lib/systemd/system/frpc.service
    
    # 服务内容
    [Unit]
    Description=frpc service
    After=network.target syslog.target
    Wants=network.target
    
    [Service]
    Type=simple
    ExecStart=/path/to/frp/frpc -c /path/to/frp/frpc.ini
    
    [Install]
    WantedBy=multi-user.target
    
    # 启动
    sudo systemctl start frpc
    
    # 开机启动
    sudo systemctl enable frpc
    
    # 其它命令
    sudo systemctl restart frpc
    sudo systemctl stop frpc
    sudo systemctl status frpc
    
    
  • 定时任务,每天定时重启server和client

本处高能:因Frp作者更换新的模块,导致Frp v0.18.0与之前的版本不兼容,如果升级请服务器端同步升级。升级命令: wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh bash install-frps.sh update 首先感谢@sadoneli S大的帮助完成了frp插件web页面的制作。 WARNING:请仔细阅读完本教程1楼和2楼后再动手安装! frp 是一个高性能的反向代理应用,可以帮助您轻松地进行内网穿透,对外网提供服务,支持 tcp, http, https 等协议类型,并且 web 服务支持根据域名进行路由转发。 *因为frp是go语言写的,所以在路由器上使用的时候,请使用虚拟内存,请使用虚拟内存,请使用虚拟内存。 脚本是业余爱好,英文属于文盲,写的不好,欢迎您批评指正。 安装平台:CentOS、Debian、Ubuntu。 已测试过的平台: CentOS 6 32/64bit CentOS 7 32/64bit Debian 6 32/64bit Debian 7 32/64bit Debian 8 32/64bit Ubuntu 14 32/64bit 一、安装命令这个命令是在你自己的服务器上运行的!是在你自己的服务器上运行的!是在你自己的服务器上运行的!不是在路由器里运行的!不是在路由器里运行的!不是在路由器里运行的! wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh chmod 700 ./install-frps.sh ./install-frps.sh install 二、安装步骤 Loading network version for frps, please wait... frps Latest release file frp_0.8.1_linux_amd64.tar.gz #此步骤会自动获取frp最新版本,自动操作,无需理会 Loading You Server IP, please wait... You Server IP:12.12.12.12 #自动获取你服务器的IP地址 Please input your server setting: Please input frps bind_port [1-65535](Default Server Port: 5443): #输入frp提供服务的端口,用于服务器端和客户端通信 Please input frps dashboard_port [1-65535](Default dashboard_port: 6443): #输入frp的控制台服务端口,用于查看frp工作状态 Please input frps vhost_http_port [1-65535](Default vhost_http_port: 80): #输入frp进行http穿透的http服务端口 Please input frps vhost_https_port [1-65535](Default vhost_https_port: 443): #输入frp进行https穿透的https服务端口 Please input privilege_token (Default: WEWLRgwRjIJVPx2kuqzkGnvuftPLQniq): #输入frp服务器和客户端通信的密码,默认是随机生成的 Please input frps max_pool_count [1-200](Default max_pool_count: 50): #设置每个代理可以创建的连接池上限,默认50 ##### Please select log_level ##### 1: info 2: warn 3: error 4: debug ##################################################### Enter your choice (1, 2, 3, 4 or exit. default [1]): #设置日志等级,4个选项,默认是info Please input frps log_max_days [1-30] (Default log_max_days: 3 day): #设置日志保留天数,范围是1到30天,默认保留3天。 ##### Please select log_file ##### 1: enable 2: disable ##################################################### Enter your choice (1, 2 or exit. default [1]): #设置是否开启日志记录,默认开启,开启后日志等级及保留天数生效,否则等级和保留天数无效 设置完成后检查你的输入,如果没有问题按任意键继续安装 ============== Check your input ============== You Server IP : 12.12.12.12 Bind port : 5443 Dashboard port : 6443 vhost http port : 80 vhost https port: 443 Privilege token : WEWLRgwRjIJVPx2kuqzkGnvuftPLQniq Max Pool count : 50 Log level : info Log max days : 3 Log file : enable ============================================== 安装结束后显示: Congratulations, frps install completed! ============================================== You Server IP : 12.12.12.12 Bind port : 5443 Dashboard port : 6443 vhost http port : 80 vhost https port: 443 Privilege token : WEWLRgwRjIJVPx2kuqzkGnvuftPLQniq Max Pool count : 50 Log level : info Log max days : 3 Log file : enable # 将上面信息添加到你的路由器frp穿透插件中吧 ============================================== frps Dashboard: http://12.12.12.12:6443/ # 这个是frp控制台访问地址 ============================================== 三、更新命令 ./install-frps.sh update 四、卸载命令 ./install-frps.sh uninstall 五、服务器端管理命令 /etc/init.d/frps start /etc/init.d/frps stop /etc/init.d/frps restart /etc/init.d/frps status /etc/init.d/frps config /etc/init.d/frps version 七、更多帮助请移步官方帮助文件 https://github.com/fatedier/frp/blob/master/README_zh.md
在两个Linux系统上使用frp进行内网穿透,需要准备一台公网服务器、内网客户端和服务端,然后按照以下步骤进行安装和配置。 1. 在公网服务器上下载并解压frp压缩包。可以从官方网站或其他可信来源下载适用于Linux系统的frp压缩包。解压缩后,你将得到frps和frpc两个可执行文件。这两个文件分别用于服务端和客户端。 2. 在公网服务器上配置frps服务端。编辑frps.ini配置文件,设置监听的端口和其他相关参数,例如token和log_file等。确保配置文件中的部分与你的需求相匹配。 3. 在内网客户端上下载并解压frp压缩包。同样地,你可以从官方网站或其他可信来源下载适用于Linux系统的frp压缩包。解压缩后,你将得到frpc可执行文件。 4. 在内网客户端上配置frpc客户端。编辑frpc.ini配置文件,设置通信方式、服务器地址和端口等参数。确保配置文件中的部分与你的需求相匹配。 5. 在公网服务器上启动frps服务端。使用命令行运行以下命令来启动frps: ``` ./frps -c frps.ini ``` 6. 在内网客户端上启动frpc客户端。使用命令行运行以下命令来启动frpc: ``` ./frpc -c frpc.ini ``` 通过以上步骤,你就可以在两个Linux系统上使用frp进行内网穿透了。确保公网服务器与内网客户端都正常运行,并且配置文件中的参数正确设置。这样,你就可以通过frp实现公网服务器和内网客户端之间的网络穿透连接。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [内网穿透工具frp_0.41.0_Linux+Windows的amd64](https://download.csdn.net/download/object_admin/85170961)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [frp实现内网穿透Linux->Linux(详细)](https://blog.csdn.net/weixin_49764009/article/details/122018688)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值