Frp internal network penetrates external network remote desktop and ssh to connect to campus network server

What is frp?

frp is a fast reverse proxy to help you expose a local server behind a
NAT or firewall to the Internet. As of now, it supports TCP and UDP,
as well as HTTP and HTTPS protocols, where requests can be forwarded to internal services by domain name.frp also has a P2P connect mode.

frp is a fast reverse proxy that can help you expose the local server behind a NAT or firewall to the Internet. So far, it supports TCP and UDP as well as HTTP and HTTPS protocols. In these protocols, requests can be forwarded to internal services through domain names. Frp also has a P2P connection mode. frp source code address

This article mainly talks about using RDP (remote desktop) and ssh to connect to the school server through frp.

Needs: 1. Cloud server (server)
2. Networked on-campus server (the server we need to connect to) (client)
3. A computer that can use the Internet or a tablet or mobile phone that can be connected remotely. (User test)
Insert picture description here
You can set a security group for the cloud server and open all ports, so you don't need to open one port by one.
As shown in the figure,
Insert picture description here
Insert picture description here
then click the new management of the management instance to associate the newly added security group to your server.

Frp installation and configuration

frp download address (https://github.com/fatedier/frp/releases)

Download the latest version of
Insert picture description here
Ubuntu Download frp and save to the command line of the current folder

wget  https://github.com/fatedier/frp/releases/download/v0.31.1/frp_0.31.1_linux_amd64.tar.gz

Unzip tar.gz

tar -zxvf frp_0.31.1_linux_arm64.tar.gz

Enter folder

cd frp_0.31.1_linux_arm64

Insert picture description here

Server

The main use is frps executable file and frps.ini configuration file. frps_full.ini is all configuration files without modification, just modify in frps.ini.
The configuration file can view the Chinese document in the source code .
Configure frps.ini file

vim frps.ini

This is the configuration on my cloud server.

[common]
#bind_addr = 0.0.0.0
bind_port = 7000  //7000端口是和客户端连接时使用的端口。
auto_token = frp  //和客户端保持一致就行

//服务器查看端口账号
dashboard_port = 7500
dashboard_user = admin
dashboard_pwd = admin

Enter the server ip:7500 in the browser to view the port. After
Insert picture description here
setting the frps.ini file, run the frps executable file. Execute under the current path.

 ./frps -c ./frps.ini 

Screenshot of successful operation (windows system)
Insert picture description here
can also write systemctl to control startup. For example, " Several Methods of Frp Background Automatic Start "

View frps process:

ps -e | grep frps

Insert picture description here

Client

Just use the frpc executable file and frpc.ini configuration file in the compressed package. frpc_full.ini is all configuration files without modification, just modify in frpc.ini.
If the client is also an ubuntu system, the operation is the same as the server above.
The frpc.ini file is modified

[common]
server_addr = xx.xx.xx.xx   //服务端的IP地址
server_port = 7000          和服务端端口一致

[RDP]                   //远程桌面配置,具体的可以查看源代码给的readme
type = tcp
local_ip = 0.0.0.0     //没太弄懂  填0.0.0.0和127.0.0.1都可以
local_port = 5900      //随便填,但是不能和其他端口重合,两边服务器都把这些端口打开
remote_port = 6001      //这个端口是远程连接的用户所使用的端口


[ssh]                   //这个是用做ssh连接的
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000     远程连接的用户使用这个端口

Start after setting

 ./frpc -c ./frpc.ini 

Insert picture description here
Windows system as a client (one server can also correspond to multiple clients, because there are not enough Internet accounts, the server cannot access the Internet, and all windows servers are not configured as clients.) But the settings are similar to the above.
Download the frp compressed package suitable for windows system and configure the frpc.ini file.
Insert picture description here

[common]
server_addr = x.x.x.x     //服务端ip
server_port = 7000        //和服务端端口保持一致

[ssh80]   //这个名称不要和另外一个客户端的重合
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6080       //这个也不要重合

[RDP02]         //这个名称也不要和另外一个客户端的重合
type = tcp
local_ip = 0.0.0.0
local_port = 6002
remote_port = 6002

As long as the name in the configuration does not coincide with the name of another client, one server can correspond to multiple clients.

Windows10 run frp command
, directly enter cmd in the frp folder to open the command prompt,
Insert picture description here
windows run the client reference article

Run frp service commands in the background

Reference article

服务端: nohup ./frps -c frps.ini >/dev/null 2>&1 &

客户端: nohup ./frpc -c frpc.ini >/dev/null 2>&1 &

说明:>/dev/null 2>&1 &,表示丢弃。

systemctl control startup

Reference article

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

Write

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

[Service]
Type=simple
#启动服务的命令(此处写你的frps的实际安装目录)
ExecStart=/你的frp安装路径/frps -c /你的frp安装路径/frps.ini

[Install]
WantedBy=multi-user.target

Both server and client can write like this. Only need to change ExecStartthe execution path of frp (note frps and frpc)

Then start frps

sudo systemctl start frps

Self-start

sudo systemctl enable frps

Restart the application: sudo systemctl restart frps
stop the application: sudo systemctl stop frps
view the application log, enter:sudo systemctl status frps

Note: The ports set above must be opened on the client and server.
ubuntu open port instructions

sudo ufw allow 22   //tcp 允许所有的外部IP访问本机的22/tcp (ssh)端口

External network test

Both ssh connection and remote desktop connection require the school server to be able to use ssh and remote desktop connection on the intranet. I won't go into details here.
ssh connection
I use putty connection
Insert picture description here

Insert picture description here
Enter the school's server account and password, and you can log in to the intranet server through the Ali server.

Remote desktop connection
Insert picture description here
Remote desktop input ip:6001, 6001. This is the port number I set. You can also set other port numbers, but don't overlap with other port numbers.
Insert picture description here
Enter account and password to log in

Note:
Pay attention to whether the port is open. Closing and restarting the firewall may affect the port. (I used to mount the disk, closed and restarted the firewall, which caused the remote connection to fail. After looking for the cause for two hours, the result was that port 3389 was not opened)

Guess you like

Origin blog.csdn.net/qq_38469784/article/details/104031367
Recommended