LJason

LJason

野生程序猴子
twitter
github
nintendo switch
steam
bilibili
email

Playing with Raspberry Pi 04 - Remote Access

Most of the functions are already set up, but currently it can only be used within the local network. The next step is to make it accessible from the internet, such as accessing your Raspberry Pi at home from your workplace, school, or anywhere else.

Since the IP address provided by the ISP is dynamic, in order to achieve internet access, you must obtain the public IP address.

There are two methods, the first one being the use of dynamic domain name resolution services like "Peanut Shell" (花生壳). This method is quite simple and will not be discussed here. Let's talk about the second method.

First, set a static IP address for the Raspberry Pi in the router: DHCP Server-Static Address Reservation:

00

Bind it to 192.168.1.104, and then set up port forwarding: Port Forwarding-Virtual Server:

01

The server port can be set arbitrarily, and the internal ports are as follows:

  • 22: SSH port.
  • 6800: This is the default port for Aria2 RPC and the only port that must match between the server and the internal port.
  • 5901: This is the VNC port.
  • 80: This is the download management page for Aria2.

Now comes the main part: obtaining the public IP address. Execute:

git clone --depth=1 https://github.com/LJason77/Report-IP-hourly.git ~/rootcrons/

Edit ~/rootcrons/reportip.py and change the values of smtpserver, username, password, sender, receiver, and subject (SMTP service needs to be enabled for the email):

  • smtpserver: SMTP server
  • username: SMTP login username
  • password: Password
  • sender: Sender, make sure it corresponds to the SMTP login account, usually an email account.
  • receiver: List of recipients
  • subject: Email subject

Find:

http://1111.ip138.com/ic.asp

Change it to:

http://members.3322.org/dyndns/getip

Execute:

sudo crontab /home/pi/rootcrons/rootcron
sudo /etc/init.d/cron restart

Automatic IP detection service on startup: Edit /etc/rc.local and add:

/usr/bin/python /home/pi/rootcrons/reportip.py

Modify the frequency of IP detection in /var/spool/cron/crontabs:

*/5 * * * * /usr/bin/python /home/pi/rootcrons/reportip.py

This will check the IP every 5 minutes. Please refer to the specific parameters by searching on Google: crontab. Now, whenever the IP changes, you will receive the latest IP through email within five minutes.

References

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.