公網訪問內網實現(內網穿透)


內網穿透是什么?

內網穿透是把內網主機連接具有公網IP的設備,使得內網設備代理公網設備,易於 telnet、ssh、ftp等連接

 

怎么實現內網穿透?

frp采用c/s架構,

內網穿透的工具有很多如

花生殼

net123

ngrok

frp

 

花生殼和nat123屬於服務商提供的穿透所以會收取費用(一月40-50 / 128Kb)

ngrok 和 frp 屬於需要手動配置搭建的程序

frp github :https://github.com/fatedier/frp/blob/master/README_zh.md

 

 准備工作:

下載地址: https://github.com/fatedier/frp/releases

1、帶有公網地址的 VPS(例如公網地址為 111.111.222.111 ):后邊將會把內網的主機映射到這個 IP 地址

2、內網主機(可聯網)


那該如何去做?

這里演示內網windows下穿透成到公網linux主機的端口

 

Linux端(server):

修改frps.ini

bind_port = 7000

# 服務器端監聽http請求的端口(由於80端口被nginx占用,因此指定其他端口)
vhost_http_port = 81 

# 服務器用以顯示連接狀態的站點端口,以下配置中可以通過訪問IP:7500登錄查看frp服務端狀態等信息
dashboard_port = 7500

# dashboard對應的用戶名/密碼
dashboard_user = use
dashboard_pwd = pwd

# 日志文件路徑
#log_file = /root/net-ct/frp/frps.log


# 日志記錄錯誤級別,分為:trace, debug, info, warn, erro
#log_level = warn

# 日志保存最大天數
#log_max_days = 3

# 客戶端連接校驗碼(客戶端需與之相同)
privilege_token = token123

# heartbeat configure, it's not recommended to modify the default value
# the default value of heartbeat_timeout is 90
# heartbeat_timeout = 90

# only allow frpc to bind ports you list, if you set nothing, there won't be any limit
# privilege_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

# authentication_timeout means the timeout interval (seconds) when the frpc connects frps
# if authentication_timeout is zero, the time is not verified, default is 900s
authentication_timeout = 900

# 支持外部訪問的域名(需要將域名解析到IP)
#subdomain_host = frps.domain.com

由於github上有中文解釋且解釋的比較全面所以這邊就不復述了

啟動:./frps -c ./frps.ini

windows端(client):

配置frpc.ini

[common]
server_addr = 41.91.143.88 #服務器地址
server_port = 7000 #服務器開放連接的端口
privilege_token = token123 #服務器token
auth_token = auth_token
[RDP]
type = tcp #使用tcp連接
local_ip = 127.0.0.1 #本地地址
local_port = 3389 #穿透到的本地端口(遠程桌面端口)
remote_port = 7001 #開發到公網連接的端口

啟動:frpc.exe -c frpc.ini

 

即可

來實驗下吧

mstsc下

服務器地址:7001 就可以了

 

轉載自:http://www.forever121.cn/?p=253


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM