Raspberry Pi Quick Start - Remote Access to Raspberry Pi at Home

A brief summary

In the previous article on turning the Raspberry Pi into a personal Linux computer, it was mentioned that I was using the Raspberry Pi 2 Model B, which has been in the dust for a long time, and the processor does not have the capability of a Wi-Fi wireless network card. , so if you want to connect the Raspberry Pi to the Internet before, you can only connect it to the LAN port of the router through a network cable. It is still troublesome to use, because of the wired connection, the mobility of the Raspberry Pi becomes poor, and it can only be near the router, which greatly reduces the flexibility.

So, I found two USB Wi-Fi network cards I bought before, one of which is a very small USB Wi-Fi adapter from EDUP. The chip used is RTL8188CUS, which can be connected to the Linux system without drive, supports 2.4G frequency band, 802.11 n (Wi-Fi 4).

The other one used to come with the development board, Bilian BL-LW05-AR5, with an external omnidirectional antenna, which is larger than the EDUP. The chip used is also RTL8188CUS, which can be connected to the Linux system without drive, and supports 2.4G frequency band. 802.11n (Wi-Fi 4).

Therefore, there should be little difference between the two USB Wi-Fi adapter chips and firmware. The EDUP is small in size, but the signal of the built-in antenna (such a small size may be a ceramic antenna) should be better than that of the external antenna of Bilian BL-LW05-AR5. It is slightly worse, but I still choose to use the EDUP to connect to the USB port of the Raspberry Pi:

 

In addition to the configuration of the Wi-Fi router ssid and password and the ssh connection method introduced in the previous article on turning the Raspberry Pi into a personal Linux computer, after starting the Raspberry Pi, log in through the ssh tool, and use the ifconfig command to see My Raspberry Pi has connected to the router via Wi-Fi and has obtained an IP address.

Two, the need for remote access

Through the previous method, although I can log in to the Raspberry Pi system through my computer ssh, there is a premise that my computer must be connected to the same router as the Raspberry Pi, because the Raspberry Pi I saw earlier The IP address 192.168.1.12 is a LAN address. Once I connect the computer to another router or go out, I cannot log in to the Raspberry Pi through ssh.

Of course, what's more serious is that it's not just ssh. If I use the Raspberry Pi Linux system to build some small services later, such as sensor data collection, website sites, or code warehouses, when I want to access my Raspberry Pi Linux , can only be done when the computer is connected to the same router, which is actually meaningless. We often need the Raspberry Pi Linux system to run stably for a long time, and no matter where we are, as long as we pass through the network Only by logging in and accessing our Raspberry Pi system can we maximize the role of Raspberry Pi.

Implementation of three remote access

Because the Raspberry Pi is currently connected to the router and has no public IP, although the Raspberry Pi can access the Internet through the router, it is impossible to find and access my Raspberry Pi from the outside. In order to solve the problem of being able to access the Raspberry Pi at home from the external network, it is necessary to use an internal network penetration tool, and cpolar is recommended here.

3.1 Installation of cpolar

First, log in to my Raspberry Pi via ssh in the LAN, and use the following one-click installation script:

# Domestic one-key installation 
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash 

# Overseas one-key installation 
curl -sL https://git.io/cpolar | sudo bash

3.2 Authtoken authentication

First, you can go to cpolar - secure introspectable tunnels to localhost to register a cpolar account for free. If you already have an account, you can log in. Then copy your Authtoken in the verification location on the login page as shown in the figure below.

# Enter the copied Authtoken xxxxxxx on the Raspberry Pi ssh login interface just now 
cpolar authtoken xxxxxxx 

# Then configure the cpolar service to start automatically at boot 
sudo systemctl enable cpolar 

# Start cpolar as a daemon 
sudo systemctl start cpolar 

# View the started cpolar daemon Status, after entering the following command, you will see Active: active (running) indicating that the startup is successful 
sudo systemctl status cpolar

3.3 use

Through the above steps, cpolar will install three tunnels by default, two Website tunnels, and one ssh tunnel. You can see the specific address in the "status" after logging in to the cpolar background.

By checking the ssh URL in the above "status", the example here is tcp://3.tcp.vip.cpolar.cn:10901, which is a tcp address of the Raspberry Pi on the external public network after penetrating the internal network through cpolar and port number, then you can use this information to use the computer outside, and you can remotely log in to the Raspberry Pi at home with the following command:

ssh [email protected] -p 10901

The ssh URL in the "status" here will change after the Raspberry Pi is restarted and powered on. In addition, according to the cpolar official website, it seems to change randomly after 24 hours, so after a period of time, remote ssh access to the Raspberry Pi , you need to check the address of the "status" in the background of cpolar again, and use the new address to ssh to log in to the Raspberry Pi.

five at the end

Remote ssh login, or other ways to access the Raspberry Pi at home, is just the beginning, the key is to use the Raspberry Pi's low power consumption, small size, flexibility, and space-saving features, and place it at home or other places as a lightweight The real charm of Raspberry Pi lies in solving problems and satisfying needs in specific scenarios such as server, remote assistance to complete tasks, or execution monitoring.

For more exciting content, please search and pay attention to the official account of "Technology and Plastic Future".

References

"cpolar Getting Started Guide": Documentation - cpolar Pole Cloud

Guess you like

Origin blog.csdn.net/suxiang198/article/details/127002210