1. 程式人生 > >利用阿里雲和frps做內網穿透,支援mstsc遠端桌面,ssh,linux連線,所有的tcp 連線都可以轉發 整理by qiweb 2018 1107

利用阿里雲和frps做內網穿透,支援mstsc遠端桌面,ssh,linux連線,所有的tcp 連線都可以轉發 整理by qiweb 2018 1107

準備工作和操作過程:

1、先要有一臺阿里雲或者其他vps 這裡假設外網唯一ip是: 另外要開放一個一個區間的埠號 比如1701 -1750 這些供客戶使用

47.98.195.221

frp官網

到官網下載需要的版本,我這裡都是linux版本 window也能用

2、ssh連線到vps伺服器 安裝frp伺服器端 

d修改fprs.in配置檔案

# [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"
bind_addr = 0.0.0.0
bind_port = 7000
# 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
# if you want to configure or reload frps by dashboard, dashboard_port must be set
dashboard_port = 7005
# dashboard assets directory(only for debug mode)
dashboard_user = admin
dashboard_pwd = admin
# assets_dir = ./static
vhost_http_port = 7003
#vhost_https_port = 700
# console or real logFile path like ./frps.log
log_file = ./frps.log
# debug, info, warn, error
log_level = info
log_max_days = 3
#authentication_timeout = 0
# auth token
#privilege_token=123456
#token = 123456

privilege_mode = true

privilege_token = 12345678
# only allow frpc to bind ports you list, if you set nothing, there won't be any limit
#allow_ports = 1-65535
# pool_count in each proxy will change to max_pool_count if they exceed the maximum value
max_pool_count = 50

啟動方法見下面客戶端啟動方法一樣的設定

啟動後訪問http://47.98.195.221:7005   管理密碼是admin 在上面的配置檔案

看3、在直接電腦或者區域網上任何一臺電腦上安裝frp客戶端,並設定開機自啟動

d修改fprc.in配置檔案 前面是連線伺服器,後面兩個分別映射了區域網的一臺window和一個linux伺服器到外網

[common]
server_addr =47.98.195.222
server_port =7000
privilege_token=12345678

#linux
[ssh]
type = tcp

local_ip = 192.168.0.6
local_port = 3389
remote_port = 1723

[mstsc-pc]
type = tcp
local_ip = 192.168.0.8
local_port = 3389
remote_port = 7002

1使用nohup來啟動 這是frps的後臺啟動(路徑寫你伺服器上的絕對路徑),如果要檢視日誌的話,就直接使用cat nohup.out,就可以查看了。 

nohup /path/to/your/fprs -c-c /path/to/your/frps.ini 

這是frpc的後臺啟動 

nohup /path/to/your/fprc -c-c /path/to/your/frpc.ini 

2使用systemctl來控制啟動 這個方法比較好用,很方便 sudo vim /lib/systemd/system/frps.service  在frps.service裡寫入以下內容

[Unit]
Description=fraps service
After=network.target syslog.target
Wants=network.target

[Service]
Type=simple
#啟動服務的命令(此處寫你的frps的實際安裝目錄)
ExecStart=/your/path/frps -c /your/path/frps.ini

[Install]
WantedBy=multi-user.target

然後就啟動frps  sudo systemctl start frps  再開啟自啟動  sudo systemctl enable frps

如果要重啟應用,可以這樣,sudo systemctl restart frps 如果要停止應用,可以輸入,sudo systemctl stop frps 如果要檢視應用的日誌,可以輸入,sudo systemctl status frps  

其他類似軟體

先說下內外穿透工具,我用過下面這些

內網穿透工具 Localtunnel  nodejs語言 Nrgok  go 語言 Frp  go  語言 Onmp N2n

對映公網(花生殼、PubYun、No-IP、DynDNS、Ngrok、Tunnel、localtunnel、pagekite)