10分鍾使用騰訊輕量應用服務器與frp開啟內網穿透實現ssh


下載

客戶端和服務器都要下載這個文件

frp_0.38.0_linux_amd64.tar.gz

解壓

請在客戶機(也就是需要進行內網穿透的本地機)和服務器執行相同操作:

解壓:tar -xvf frp_0.38.0_linux_amd64.tar.gz

放到local目錄下:mv frp_0.38.0_linux_amd64 /usr/local/frp

cd /usr/local/frp

服務器配置

登錄到騰訊雲服務器,下載解壓步驟。

ls查看目錄:

image-20220122115136816

frps是服務器對應的執行文件,frps.ini是服務器配置文件。

修改frps配置文件:vim frps.ini

[common]
bind_port = 33300              

這個 bind_port就是frps的監聽端口,可以修改為你需要制定的端口,在雲服務器中,我們一般不會使用默認端口,因為這可能會導致出現病毒攻擊。

騰訊雲設置:找到防火牆管理規則,開放暴露端口。

注意

如果你要通過frp進行ssh訪問,還要開啟一個ssh訪問端口,也就是要暴露兩個端口,一個 33300端口,一個 33301端口,其中33301端口用於提供ssh服務。

image-20220122121136085

總結,修改配置文件,開放兩個端口。

如果執行報錯,可以執行 chmod 777 frps 增加權限。

執行

/usr/local/frp/frps -c /usr/local/frp/frps.ini

image-20220122122845140

注冊為系統服務

sudo vim /usr/lib/systemd/system/frps.service

[Unit]
Description=frps Service
Documentation=https://github.com/fatedier/frp
After=network.target nss-lookup.target

[Service]
ExecStart=/usr/local/frp/frps -c /usr/local/frp/frps.ini 
Restart=on-failure
RestartPreventExitStatus=23

[Install]
WantedBy=multi-user.target                                

重載服務:systemctl daemon-reload

開啟服務:systemctl start frps

查看服務狀態:systemctl status frps

設置開機自啟動:systemctl enable frps

客戶端

客戶端配置

frpc是客戶端對應的執行文件,frpc.ini是客戶端配置文件。

執行之前相同的下載解壓cd命令

修改客戶端配置:vim frpc.ini,[ssh]設置了ssh端口,remote_port指的是你的服務器應該用33301端口來提供ssh服務,因為我們之前開放了服務器的33301端口。

[common]
server_addr = 你的服務器公網ip
server_port = 33300 

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 33301                                    

同樣,注冊為服務:sudo vim /usr/lib/systemd/system/frpc.service

[Unit]
Description=frps Service
Documentation=https://github.com/fatedier/frp
After=network.target nss-lookup.target

[Service]
ExecStart=/usr/local/frp/frpc -c /usr/local/frp/frpc.ini
Restart=on-failure
RestartPreventExitStatus=23

[Install]
WantedBy=multi-user.target
~                                     

重載服務:systemctl daemon-reload

開啟服務:systemctl start frpc

查看服務狀態:systemctl status frpc

設置開機自啟動:systemctl enable frpc

ssh連接

ok,現在我們可以用ssh來連接到這個內網主機了。

ssh -p 33301 內網機需要登錄的用戶名@服務器的公網ip

完美,這樣我們就完成了內網穿透實現ssh連接了。

---更新---

最近的frpc客戶端突然連接不上去了,而且還報錯:login to server failed: i/o deadline reached i/o deadline

解決辦法:在ini文件中[common]中添加:tls_enable = true,並重啟客戶端機。


免責聲明!

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



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