參考:[frp安裝教程 穿透SSH | 月小升網絡筆記](https://java-er.com/blog/frp-install/ )]
frp安裝包選擇
frp 的安裝包地址
https://github.com/fatedier/frp/releases
看到很多包
386 amd64 啥意思,差了下,簡單區分下386就是32位系統 amd64 就是64位系統。
好了,下載個frp_0.27.0_linux_amd64.tar.gz
執行下,解壓縮,改成frpc 目錄 cd 進去下
./frpc
-bash: ./frpc: cannot execute binary file
大量資料說明,出來這個玩意是版本錯了。
frp是go語言寫的,安裝下go
https://dl.google.com/go/go1.11.darwin-amd64.pkg
安裝完畢,執行go -version
go version
go1.11 darwin/amd64
瞬間明白了,要下載第一個,那個什么linux_amd64.tar.gz 似乎都是對着go的版本對應的。所以先看你電腦的go語言的版本才好決定下載哪個, 重新下載我電腦對應的darwin/amd64版本
./frpc 2019/05/22 10:03:26 [W] [service.go:82] login to server failed: dial tcp 127.0.0.1:7000: connect: connection refused dial tcp 127.0.0.1:7000: connect: connection refused
這反應才是正確了版本,但是配置不對的反應。
frp基本配置,啟動
帶着配置啟動
服務端啟動測試
./frps -c ./frps.ini 2019/05/22 10:06:33 [I] [service.go:139] frps tcp listen on 0.0.0.0:7000 2019/05/22 10:06:33 [I] [root.go:204] Start frps success
默認的配置是好的,不用改。
[common] bind_port = 7000
frps 表示frp server
frpc 表示frp client
客戶端啟動測試
frpc.ini
默認指向本地,直接測試好了。自己玩自己
[common] server_addr = 127.0.0.1 #服務器IP server_port = 7000 #服務器開出來的端口,等着客戶端來連接 [ssh] # ssh 超級轉發 type = tcp #類型tcp udp local_ip = 127.0.0.1 #本地IP local_port = 22 #本地端口 remote_port = 6000 #本地轉發端口
./frpc -c ./frpc.ini 2019/05/22 10:13:53 [I] [service.go:221] login to server success, get run id [b1247b7334ecc4a0], server udp port [0] 2019/05/22 10:13:53 [I] [proxy_manager.go:137] [b1247b7334ecc4a0] proxy added: [ssh] 2019/05/22 10:13:53 [I] [control.go:144] [ssh] start proxy success
客戶端也啟動了,測試下
ssh -oPort=6000 xx@127.0.0.1 -v
xx 表示客戶端機器的賬戶名字 @127.0.0.1 表示服務端的IP
OpenSSH_7.8p1, LibreSSL 2.6.2 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 48: Applying options for * debug1: Connecting to 127.0.0.1 [127.0.0.1] port 6000. debug1: Connection established. debug1: identity file /Users/ge/.ssh/id_rsa type -1 debug1: identity file /Users/ge/.ssh/id_rsa-cert type -1 debug1: identity file /Users/ge/.ssh/id_dsa type -1 debug1: identity file /Users/ge/.ssh/id_dsa-cert type -1 debug1: identity file /Users/ge/.ssh/id_ecdsa type -1 debug1: identity file /Users/ge/.ssh/id_ecdsa-cert type -1 debug1: identity file /Users/ge/.ssh/id_ed25519 type -1 debug1: identity file /Users/ge/.ssh/id_ed25519-cert type -1 debug1: identity file /Users/ge/.ssh/id_xmss type -1 debug1: identity file /Users/ge/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_7.8 ssh_exchange_identification: Connection closed by remote host
出現這個是因為我的本地mac電腦沒有開啟ssh共享服務
ssh -oPort=6000 xx@127.0.0.1 -v
自己本地的服務端和客戶端都好了。
現在要把服務端丟到服務器了。才能實現家里電腦訪問公司的電腦
服務器中轉,真正的外網穿透
服務器(CENTOS)上
yum install go
go version go1.11.5 linux/amd64
下載文件對應go語言返回的版本 linux_amd64
一般雲服務器都有端口控制,如果您啟動了iptables防火牆,也要打開,或者關閉防火牆。
啟動,打開阿里雲的防火牆端口
./frps -c frps.ini
成功了。
服務器frps.ini 采用默認配置即可
本地的機器修改frpc.ini的ip
[common] server_addr = 42.20.2.111 #服務器IP server_port = 7000 #服務器開出來的端口,等着客戶端來連接 [ssh] # ssh 超級轉發 type = tcp #類型tcp udp local_ip = 127.0.0.1 #本地IP local_port = 22 #本地端口 remote_port = 6000 #本地轉發端口
重啟動本地
自己的電腦
ssh -oPort=6000 xx@42.20.2.11
重點的事情再說一遍 前面的賬戶xx是本地客戶端的用戶名,后面的IP42.20.2.11是服務器的IP
隨便找一台其他電腦,這么訪問也可以登錄,這樣就實現了外網穿透ssh