内网穿透 --- frp
中文文檔:https://github.com/fatedier/frp/blob/dev/README_zh.md
手機+frp內網穿透搭建隨身攜帶的服務器:https://blog.csdn.net/sinat_27938829/article/details/73604722
軟路由 通過 Openwrt 自帶的 Frp 插件:https://zhuanlan.zhihu.com/p/367894569
手機搭建個人網站 (?KSWEB+TERMUX+FRP內網穿透 ):https://www.jianshu.com/p/9981d27c0350
玩轉內外網互通 (?Ngrok、釘釘、花生殼、frp ):https://www.it235.com/實用工具/內網穿透/pierce.html
內網穿透
什么是內網穿透?
內網穿透,又叫 NET 穿透,是計算機用語。用通俗的說法就是你家里的個人電腦,可以直接被外網的人訪問。例如你在公司,不通過遠程工具,直接也可以訪問到家里的電腦。內網穿透就是把局域網的 端口暴露給 公網,然后通過公網就可以訪問局域網暴露端口的服務
通常實現內網穿透,是通過路由器上端口映射來實現的。但是路由器通常不是每個人都有權限可以訪問和設置,而且可能存在多級路由器較為復雜的網絡結構。端口映射也無法實現。
正常來說我們的個人電腦是無法被別人訪問到的(有固定 ip 除外!),而且現在固定 ip 資源稀缺,運營商也不會隨便給你分配了,個人申請也挺難。
為什么需要內網穿透?就個人而已,需要用到內網穿透的原因:一是方便訪問公司的內網環境,不喜歡使用遠程工具,挺麻煩的。二是方便把個人電腦上的應用開放到外網進行訪問。
1、Frp 介紹
FRP 全名:Fast Reverse Proxy。FRP 是一個使用 Go 語言開發的開源、簡潔易用、高性能的內網穿透和反向代理軟件,支持 tcp, udp, http, https 等協議。frp 項目官網是:https://github.com/fatedier/frp
使用 frp工具有以下優勢:
- 1. 利用處于內網或防火墻后的機器,對外網環境提供 HTTP 或 HTTPS 服務。
- 2. 對于 HTTP, HTTPS 服務支持基于域名的虛擬主機,支持自定義域名綁定,使多個域名可以共用一個 80 端口。
- 3. 利用處于內網或防火墻后的機器,對外網環境提供 TCP 和 UDP 服務,例如在家里通過 SSH 訪問處于公司內網環境內的主機。
frp 工作原理
- 服務端運行,監聽一個主端口,等待客戶端的連接;
- 客戶端連接到服務端的主端口,同時告訴服務端要監聽的端口和轉發類型;
- 服務端fork新的進程監聽客戶端指定的端口;
- 外網用戶連接到客戶端指定的端口,服務端通過和客戶端的連接將數據轉發到客戶端;
- 客戶端進程再將數據轉發到本地服務,從而實現內網對外暴露服務的能力。
?
2、配置教程
想要配置 frp 穿透,首先必須先要有一臺具有外網 ip ( 即:可以外網訪問 ) 的服務器。如果沒有,接下來的教程就不用看了。
配置教程主要分為兩個部分,
- 1:服務器端 (外網服務器) 的配置;服務端通常部署在具有公網 IP 的機器上
- 2:客戶端 (內網服務器) 配置。客戶端通常部署在需要穿透的內網服務所在的機器上
服務端 (?外網服務器 ) 配置
linux 版:
下載地址:https://github.com/fatedier/frp/releases
下載好后上傳到服務器上:scp frp_0.39.0_linux_amd64.tar.gz 用戶名@服務端ip:~/
這樣就放到了服務端的家目錄了?;蛘邎绦忻?#xff1a;wget https://github.com/fatedier/frp/releases/download/v0.39.0/frp_0.39.0_linux_amd64.tar.gz
如果覺得速度很慢,可以使用 mwget 安裝:mwget https://github.com/fatedier/frp/releases/download/v0.39.0/frp_0.39.0_linux_amd64.tar.gz
解壓 frp 壓縮包:tar -zxvf frp_0.39.0_linux_amd64.tar.gz
frp 目錄下的文件分為兩部分:
- frpc 開頭的代表著 客戶端 使用。
- frps 開頭的代表 服務端 使用。
- .ini 結尾的文件是 frp 的配置文件,也是需要進行修改的文件。
frps_full.ini? 文件內容:
# [common] is integral section [common] # A literal address or host name for IPv6 must be enclosed # in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80" # For single "bind_addr" field, no need square brackets, like "bind_addr = ::". bind_addr = 0.0.0.0 bind_port = 7000# udp port to help make udp hole to penetrate nat bind_udp_port = 7001# udp port used for kcp protocol, it can be same with 'bind_port' # if not set, kcp is disabled in frps kcp_bind_port = 7000# specify which address proxy will listen for, default value is same with bind_addr # proxy_bind_addr = 127.0.0.1# if you want to support virtual host, you must set the http port for listening (optional) # Note: http port and https port can be same with bind_port vhost_http_port = 80 vhost_https_port = 443# response header timeout(seconds) for vhost http server, default is 60s # vhost_http_timeout = 60# tcpmux_httpconnect_port specifies the port that the server listens for TCP # HTTP CONNECT requests. If the value is 0, the server will not multiplex TCP # requests on one single port. If it's not - it will listen on this value for # HTTP CONNECT requests. By default, this value is 0. # tcpmux_httpconnect_port = 1337# set dashboard_addr and dashboard_port to view dashboard of frps # dashboard_addr's default value is same with bind_addr # dashboard is available only if dashboard_port is set dashboard_addr = 0.0.0.0 dashboard_port = 7500# dashboard user and passwd for basic auth protect dashboard_user = admin dashboard_pwd = admin# enable_prometheus will export prometheus metrics on {dashboard_addr}:{dashboard_port} in /metrics api. enable_prometheus = true# dashboard assets directory(only for debug mode) # assets_dir = ./static# console or real logFile path like ./frps.log log_file = ./frps.log# trace, debug, info, warn, error log_level = infolog_max_days = 3# disable log colors when log_file is console, default is false disable_log_color = false# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true. detailed_errors_to_client = true# authentication_method specifies what authentication method to use authenticate frpc with frps. # If "token" is specified - token will be read into login message. # If "oidc" is specified - OIDC (Open ID Connect) token will be issued using OIDC settings. By default, this value is "token". authentication_method = token# authenticate_heartbeats specifies whether to include authentication token in heartbeats sent to frps. By default, this value is false. authenticate_heartbeats = false# AuthenticateNewWorkConns specifies whether to include authentication token in new work connections sent to frps. By default, this value is false. authenticate_new_work_conns = false# auth token token = 12345678# oidc_issuer specifies the issuer to verify OIDC tokens with. # By default, this value is "". oidc_issuer =# oidc_audience specifies the audience OIDC tokens should contain when validated. # By default, this value is "". oidc_audience =# oidc_skip_expiry_check specifies whether to skip checking if the OIDC token is expired. # By default, this value is false. oidc_skip_expiry_check = false# oidc_skip_issuer_check specifies whether to skip checking if the OIDC token's issuer claim matches the issuer specified in OidcIssuer. # By default, this value is false. oidc_skip_issuer_check = false# heartbeat configure, it's not recommended to modify the default value # the default value of heartbeat_timeout is 90. Set negative value to disable it. # heartbeat_timeout = 90# user_conn_timeout configure, it's not recommended to modify the default value # the default value of user_conn_timeout is 10 # user_conn_timeout = 10# only allow frpc to bind ports you list, if you set nothing, there won't be any limit allow_ports = 2000-3000,3001,3003,4000-50000# pool_count in each proxy will change to max_pool_count if they exceed the maximum value max_pool_count = 5# max ports can be used for each client, default value is 0 means no limit max_ports_per_client = 0# tls_only specifies whether to only accept TLS-encrypted connections. By default, the value is false. tls_only = false# tls_cert_file = server.crt # tls_key_file = server.key # tls_trusted_ca_file = ca.crt# if subdomain_host is not empty, you can set subdomain when type is http or https in frpc's configure file # when subdomain is test, the host used by routing is test.frps.com subdomain_host = frps.com# if tcp stream multiplexing is used, default is true tcp_mux = true # specify keep alive interval for tcp mux. # only valid if tcp_mux is true. # tcp_mux_keepalive_interval = 60# custom 404 page for HTTP requests # custom_404_page = /path/to/404.html# specify udp packet size, unit is byte. If not set, the default value is 1500. # This parameter should be same between client and server. # It affects the udp and sudp proxy. udp_packet_size = 1500[plugin.user-manager] addr = 127.0.0.1:9000 path = /handler ops = Login[plugin.port-manager] addr = 127.0.0.1:9001 path = /handler ops = NewProxyfrpc_full.ini 文件內容
# [common] is integral section [common] # A literal address or host name for IPv6 must be enclosed # in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80" # For single "server_addr" field, no need square brackets, like "server_addr = ::". server_addr = 0.0.0.0 server_port = 7000# if you want to connect frps by http proxy or socks5 proxy or ntlm proxy, you can set http_proxy here or in global environment variables # it only works when protocol is tcp # http_proxy = http://user:passwd@192.168.1.128:8080 # http_proxy = socks5://user:passwd@192.168.1.128:1080 # http_proxy = ntlm://user:passwd@192.168.1.128:2080# console or real logFile path like ./frpc.log log_file = ./frpc.log# trace, debug, info, warn, error log_level = infolog_max_days = 3# disable log colors when log_file is console, default is false disable_log_color = false# for authentication, should be same as your frps.ini # authenticate_heartbeats specifies whether to include authentication token in heartbeats sent to frps. By default, this value is false. authenticate_heartbeats = false# authenticate_new_work_conns specifies whether to include authentication token in new work connections sent to frps. By default, this value is false. authenticate_new_work_conns = false# auth token token = 12345678# oidc_client_id specifies the client ID to use to get a token in OIDC authentication if AuthenticationMethod == "oidc". # By default, this value is "". oidc_client_id =# oidc_client_secret specifies the client secret to use to get a token in OIDC authentication if AuthenticationMethod == "oidc". # By default, this value is "". oidc_client_secret =# oidc_audience specifies the audience of the token in OIDC authentication if AuthenticationMethod == "oidc". By default, this value is "". oidc_audience =# oidc_token_endpoint_url specifies the URL which implements OIDC Token Endpoint. # It will be used to get an OIDC token if AuthenticationMethod == "oidc". By default, this value is "". oidc_token_endpoint_url =# set admin address for control frpc's action by http api such as reload admin_addr = 127.0.0.1 admin_port = 7400 admin_user = admin admin_pwd = admin # Admin assets directory. By default, these assets are bundled with frpc. # assets_dir = ./static# connections will be established in advance, default value is zero pool_count = 5# if tcp stream multiplexing is used, default is true, it must be same with frps tcp_mux = true # specify keep alive interval for tcp mux. # only valid if tcp_mux is true. # tcp_mux_keepalive_interval = 60# your proxy name will be changed to {user}.{proxy} user = your_name# decide if exit program when first login failed, otherwise continuous relogin to frps # default is true login_fail_exit = true# communication protocol used to connect to server # now it supports tcp, kcp and websocket, default is tcp protocol = tcp# set client binding ip when connect server, default is empty. # only when protocol = tcp or websocket, the value will be used. connect_server_local_ip = 0.0.0.0# if tls_enable is true, frpc will connect frps by tls tls_enable = true# tls_cert_file = client.crt # tls_key_file = client.key # tls_trusted_ca_file = ca.crt # tls_server_name = example.com# specify a dns server, so frpc will use this instead of default one # dns_server = 8.8.8.8# proxy names you want to start seperated by ',' # default is empty, means all proxies # start = ssh,dns# heartbeat configure, it's not recommended to modify the default value # The default value of heartbeat_interval is 10 and heartbeat_timeout is 90. Set negative value # to disable it. # heartbeat_interval = 30 # heartbeat_timeout = 90# additional meta info for client meta_var1 = 123 meta_var2 = 234# specify udp packet size, unit is byte. If not set, the default value is 1500. # This parameter should be same between client and server. # It affects the udp and sudp proxy. udp_packet_size = 1500# include other config files for proxies. # includes = ./confd/*.ini# By default, frpc will connect frps with first custom byte if tls is enabled. # If DisableCustomTLSFirstByte is true, frpc will not send that custom byte. disable_custom_tls_first_byte = false# 'ssh' is the unique proxy name # if user in [common] section is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh' [ssh] # tcp | udp | http | https | stcp | xtcp, default is tcp type = tcp local_ip = 127.0.0.1 local_port = 22 # limit bandwidth for this proxy, unit is KB and MB bandwidth_limit = 1MB # true or false, if true, messages between frps and frpc will be encrypted, default is false use_encryption = false # if true, message will be compressed use_compression = false # remote port listen by frps remote_port = 6001 # frps will load balancing connections for proxies in same group group = test_group # group should have same group key group_key = 123456 # enable health check for the backend service, it support 'tcp' and 'http' now # frpc will connect local service's port to detect it's healthy status health_check_type = tcp # health check connection timeout health_check_timeout_s = 3 # if continuous failed in 3 times, the proxy will be removed from frps health_check_max_failed = 3 # every 10 seconds will do a health check health_check_interval_s = 10 # additional meta info for each proxy meta_var1 = 123 meta_var2 = 234[ssh_random] type = tcp local_ip = 127.0.0.1 local_port = 22 # if remote_port is 0, frps will assign a random port for you remote_port = 0# if you want to expose multiple ports, add 'range:' prefix to the section name # frpc will generate multiple proxies such as 'tcp_port_6010', 'tcp_port_6011' and so on. [range:tcp_port] type = tcp local_ip = 127.0.0.1 local_port = 6010-6020,6022,6024-6028 remote_port = 6010-6020,6022,6024-6028 use_encryption = false use_compression = false[dns] type = udp local_ip = 114.114.114.114 local_port = 53 remote_port = 6002 use_encryption = false use_compression = false[range:udp_port] type = udp local_ip = 127.0.0.1 local_port = 6010-6020 remote_port = 6010-6020 use_encryption = false use_compression = false# Resolve your domain names to [server_addr] so you can use http://web01.yourdomain.com to browse web01 and http://web02.yourdomain.com to browse web02 [web01] type = http local_ip = 127.0.0.1 local_port = 80 use_encryption = false use_compression = true # http username and password are safety certification for http protocol # if not set, you can access this custom_domains without certification http_user = admin http_pwd = admin # if domain for frps is frps.com, then you can access [web01] proxy by URL http://web01.frps.com subdomain = web01 custom_domains = web01.yourdomain.com # locations is only available for http type locations = /,/pic host_header_rewrite = example.com # params with prefix "header_" will be used to update http request headers header_X-From-Where = frp health_check_type = http # frpc will send a GET http request '/status' to local http service # http service is alive when it return 2xx http response code health_check_url = /status health_check_interval_s = 10 health_check_max_failed = 3 health_check_timeout_s = 3[web02] type = https local_ip = 127.0.0.1 local_port = 8000 use_encryption = false use_compression = false subdomain = web01 custom_domains = web02.yourdomain.com # if not empty, frpc will use proxy protocol to transfer connection info to your local service # v1 or v2 or empty proxy_protocol_version = v2[plugin_unix_domain_socket] type = tcp remote_port = 6003 # if plugin is defined, local_ip and local_port is useless # plugin will handle connections got from frps plugin = unix_domain_socket # params with prefix "plugin_" that plugin needed plugin_unix_path = /var/run/docker.sock[plugin_http_proxy] type = tcp remote_port = 6004 plugin = http_proxy plugin_http_user = abc plugin_http_passwd = abc[plugin_socks5] type = tcp remote_port = 6005 plugin = socks5 plugin_user = abc plugin_passwd = abc[plugin_static_file] type = tcp remote_port = 6006 plugin = static_file plugin_local_path = /var/www/blog plugin_strip_prefix = static plugin_http_user = abc plugin_http_passwd = abc[plugin_https2http] type = https custom_domains = test.yourdomain.com plugin = https2http plugin_local_addr = 127.0.0.1:80 plugin_crt_path = ./server.crt plugin_key_path = ./server.key plugin_host_header_rewrite = 127.0.0.1 plugin_header_X-From-Where = frp[plugin_https2https] type = https custom_domains = test.yourdomain.com plugin = https2https plugin_local_addr = 127.0.0.1:443 plugin_crt_path = ./server.crt plugin_key_path = ./server.key plugin_host_header_rewrite = 127.0.0.1 plugin_header_X-From-Where = frp[plugin_http2https] type = http custom_domains = test.yourdomain.com plugin = http2https plugin_local_addr = 127.0.0.1:443 plugin_host_header_rewrite = 127.0.0.1 plugin_header_X-From-Where = frp[secret_tcp] # If the type is secret tcp, remote_port is useless # Who want to connect local port should deploy another frpc with stcp proxy and role is visitor type = stcp # sk used for authentication for visitors sk = abcdefg local_ip = 127.0.0.1 local_port = 22 use_encryption = false use_compression = false# user of frpc should be same in both stcp server and stcp visitor [secret_tcp_visitor] # frpc role visitor -> frps -> frpc role server role = visitor type = stcp # the server name you want to visitor server_name = secret_tcp sk = abcdefg # connect this address to visitor stcp server bind_addr = 127.0.0.1 bind_port = 9000 use_encryption = false use_compression = false[p2p_tcp] type = xtcp sk = abcdefg local_ip = 127.0.0.1 local_port = 22 use_encryption = false use_compression = false[p2p_tcp_visitor] role = visitor type = xtcp server_name = p2p_tcp sk = abcdefg bind_addr = 127.0.0.1 bind_port = 9001 use_encryption = false use_compression = false[tcpmuxhttpconnect] type = tcpmux multiplexer = httpconnect local_ip = 127.0.0.1 local_port = 10701 custom_domains = tunnel1進入解壓后的目錄,打開配置文件:vi frps.ini??將文件內容修改為如下:
[common]bind_port = 7000 # frp 監聽的端口,默認是7000,可以改成其他的 token = mytoken_12345 # 授權碼,可以改成更復雜,這個token之后在客戶端會用到 dashboard_port = 7500 # frp 管理后臺端口,請按自己需求更改 dashboard_user = admin # frp 管理后臺用戶名和密碼,請改成自己的 dashboard_pwd = admin enable_prometheus = true# frp 日志配置 log_file = /var/log/frps.log log_level = info log_max_days = 3- bind_port? 表示客戶端和服務端連接的端口,客戶端也需同樣設置并一致(必填)
- token? 是用于客戶端和服務端連接的口令,客戶端也需同樣設置并一致(必填)
- dashboard_port? 是服務端儀表板的端口,服務端儀表板查看frp服務運行信息。(按需)
- dashboard_user 和 dashboard_pwd 是打開儀表板頁面登錄用的用戶名和密碼(按需)
?啟動 frp 服務
sudo mkdir -p /etc/frp sudo cp frps.ini /etc/frp sudo cp frps /usr/bin sudo cp systemd/frps.service /usr/lib/systemd/system/ sudo systemctl enable frps sudo systemctl start frps如果上述命令依次執行完沒有任何錯誤出現,則說明啟動成功。
防火墻開放端口
# 添加監聽端口 sudo firewall-cmd --permanent --add-port=7000/tcp # 添加管理后臺端口 sudo firewall-cmd --permanent --add-port=7500/tcp sudo firewall-cmd --reload注意:
- 1:如果是 ubuntu 或者 centos 6,請使用 ufw / iptables 工具放行端口;
- 2:7000 和 7500 兩個端口分別對應 frps.ini 配置中的 bind_port 和 dashboard_port
驗證服務端是否啟動成功
訪問:http://服務器IP:后臺管理端口?,輸入 用戶名、密碼 可以查看連接狀態。如:http://62.244.114.4:7500/,用戶名和密碼分別對應 frps.ini 文件中的 dashboard_user 和dashboard_pwd 登錄之后界面如下:
客戶端 (?內網服務器 )?配置
把 frpc 開頭的文件復制到內網服務器上(?就是要把內網端口暴露給外網的訪問的服務器上 ),
打開配置文件進行配置:vi frpc.ini (注意:不是frps.ini)
將文件內容修改為如下:
# 客戶端配置 [common] server_addr = 服務器ip server_port = 7000 # 與frps.ini的bind_port一致 token = 52010 # 與frps.ini的token一致# 配置ssh服務 [ssh] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 6000 # 這個自定義,之后再ssh連接的時候要用[ssh2] # 不同客戶端需要不同的名字 type = tcp local_ip = 127.0.0.1 local_port = 3389 #SSH使用22端口 windows系統使用3389端口 remote_port = 6006 #這個端口是指通過x.x.x.x:6000訪問內網機子的轉發端口[rdb] type = tcp local_ip = 127.0.0.1 local_port = 3389 remote_port = 6000# 配置 http 服務,可用于小程序開發、遠程調試等,如果沒有可以不寫下面的 [web] type = http local_ip = 127.0.0.1 local_port = 8080 subdomain = test.hijk.pw # web域名 remote_port = 自定義的遠程服務器端口,例如8080- server_addr 就是服務器的外網IP(必填)
- bind_port 表示客戶端和服務端連接的端口,服務端也需同樣設置并一致(必填)
- token 是用于客戶端和服務端連接的口令,服務端也需同樣設置并一致(必填)
- [rdb] 是一個規則名稱,可自定義
- type 是轉發的協議類型
- local_port 是本地應用的端口號,本例子的3389是遠程桌面的默認端口
- remote_port 是該條規則在服務端開放的端口號,在公司電腦win10電腦開始里輸入mstsc,調出遠程桌面連接,輸入服務器 IP 加 remote_port 就可遠程家里電腦了
注意:[ssh] 這樣的名稱必須全局唯一,即就算有多個客戶端,也只能使用一次,其他的可以用[ssh2]、[ssh3] 等;意思就是說,如果你要配置多個客戶端,必須將另外的客戶端的 [ssh] 改為[ssh2]、[ssh3] 等,并且 remote_port 也要變,比如 6002,6003 等
防火墻開放端口
sudo firewall-cmd --permanent --add-port=6000/tcp sudo firewall-cmd --permanent --add-port=8080/tcp sudo firewall-cmd --reload啟動客戶端:./frpc -c frpc.ini
測試穿透是否配置成功
找另外一臺不同網段的電腦,在終端執行:ssh 用戶名@服務端ip -p 端口號
這里一定要注意,這里用的是服務端的ip和用戶名,端口號用的frpc.ini文件中的remote_port。如果你登錄成功,那么,恭喜你,你已經學會了利用frc怎么配置內網穿透了!!!
3、frp 應用
ssh 遠程訪問
由于以上?家里的電腦(frp客戶端)安裝在win10系統上,使用3389可實現遠程桌面,對標linux系統,遠程訪問軟件就要用到FinalShell或Xshell,因此在linux系統上安裝客戶端需要在frpc.ini,加上以下內容:
[ssh] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 7001在 FinalShell 或 Xshell 中輸入騰訊云服務器 IP:7001 加上 linux 的賬密就可訪問
web 服務連接
在?家里的電腦(frp客戶端)開啟了一個web服務,比如啟動tomcat,那么客戶端的配置文件frpc.ini 需要填入以下內容
[web] type = http local_ip = 127.0.0.1 local_port = 8080 custom_domains = www.youdomain.com上面的 custom_domains 是域名設置,必須要有,www.youdomain.com 可以在騰訊云買最便宜5塊錢一年,域名注冊-我的域名-注冊域名中即可購買,然后解析域名,將騰訊云服務器IP和自定義的域名綁定,以后訪問騰訊云服務器就直接輸入域名就可以了,比如用百度,就直接輸入 www.baidu.com
然后?公司電腦瀏覽器?輸入www.youdomain.com:10080 即可(此處的10080就是服務端設置的vhost_http_port),查看到家里電腦(frp客戶端)啟動的 web 服務
HTTP 穿透
HTTP 穿透,也就是我們應用層面的通信協議,http協議;穿透它是為了方便我們訪問內網的 web 應用,例如我在內網機器,起了一個 tomcat 部署了一個網站,我想讓其他人外網的人來訪問我,那就需要進行 HTTP 的穿透;
服務端
[common] bind_port = 7000 vhost_http_port = 80 # 將服務器的 80 端口用作 http 協議的通信 vhost_https_port = 443 # 進服務器的 443 端口用作 https 協議通信 privilege_token = token123456789 # frp的認證,對應的客戶也需要配置一樣,才可以進行通信客戶端
[common] server_addr = 云服務器ip server_port = 7000 privilege_token = token123456789 #frp的認證[web_http] type=http #通信類型為http local_ip = 127.0.0.1 local_port = 8080 custom_domains = 二級域名/公網ip[ssh] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 6000http 的穿透,我們看到服務端和客戶端的配置文件都進行了改動,我們重點來看下客戶單中的配置;type = http : 這個是因為我們想要創建的隧道是進行 http 通信的,也就是用來訪問本地 web 應用;custom_domains = 二級域名/公網ip :這個配置一般使用一個二級域名來配置,用于通過域名來訪問你的穿透服務器,如果沒有域名,那么我們寫上一個服務器的公網 ip 也是可以的,用 ip 的話,在外網訪問的時候,就只能通過 ip 進行訪問了,效果都一樣;
文件訪問服務
在家里電腦(frp客戶端)的frpc.ini添加以下內容
[my_static_file] type = tcp remote_port = 6001 plugin = static_file plugin_local_path = E:\\temp plugin_strip_prefix = static plugin_http_user = abc plugin_http_passwd = 123plugin 是需要用到的插件
plugin_local_path是要對外暴露的文件目錄
plugin_strip_prefix訪問url攜帶的前綴
plugin_http_user訪問賬號
plugin_http_passwd訪問密碼
在 公司電腦?的瀏覽器輸入:http://1.1.1.1:6001/static/
輸入賬號密碼就可查看家里電腦分享的文件,其中1.1.1.1是騰訊云服務器對外的IP
綜合 配置
frp內網穿透,可以使用域名,也可使用IP, 一般來講,域名比較好記。所以有域名的話盡量使用域名,實在沒有域名的話才使用IP。
由于web服務一般均會使用80端口,如果80端口是否被nginx或其它web 服務占用的話,則要改成其他端口,如8080,也可使用nginx的反向代理實現frp服務端與nginx共用80端口。
frp實現內網穿透(沒有公網IP的利器)
以下 frps就是服務器端(server),frpc就是客戶端(client)。
1.有自己域名的FRP配置
# frps.ini服務端配置
[common]
bind_addr = 0.0.0.0
bind_port = 7000
privilege_token = abcdefghijk
vhost_http_port = 80
vhost_https_port = 443
#frpc.ini客戶端配置
[common]
server_addr = 服務端IP
server_port = 7000
privilege_token = abcdefghijk
[httpname]
type = http
local_port = 80
local_ip = 127.0.0.1
custom_domains =?www.52help.net
[httpsname]
type = https
local_port = 443
local_ip = 127.0.0.1
custom_domains =?52help.net? ?
這里的?www.52help.net? ?52help.net兩個域名要真實存在,且要在域名解析里將指定域名解析到frps服務端的IP上。
custom_domains = 這里填寫你已經解析到frps服務端IP上的域名,自己每個穿透對應服務,都可以綁定一個專屬域名用于訪問,包括使用tcp和udp協議。
然后就可以通過這個已經自定義域域名訪問到自己的對應HTTP服務。
2.只有IP,沒有自己域名的配置
如果自己沒有域名,但又想使用FRP實現內網穿透到我的HTTP服務
frps.ini服務端配置
# frps.ini
[common]
bind_addr = 0.0.0.0
bind_port = 7000
privilege_token = abcdefghijk
# frpc.ini客戶端配置
[common]
server_addr = 服務端IP
server_port = 7000
privilege_token = abcdefghijk
[httpname]
type = tcp
local_port = 80
local_ip = 127.0.0.1
remote_port = 8080
然后就可以通過 服務端IP地址:8080 來訪問訪問到對應穿透的服務。
總結
以上是生活随笔為你收集整理的内网穿透 --- frp的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 的 grep 命令 和 ng
- 下一篇: PHP 学习