This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14475|Reply: 4

[Source] [Practical Operation] ASP.NET Core 6 deployed on ARM Raspberry Pi to implement DDNS and Wake-on-Network

[Copy link]
Posted on 3/9/2022 10:36:53 PM | | | |
I have a Raspberry Pi 3B (Raspberry Pi 3B Arm architecture 32-bit) at home, and I have been eating dust at home, because .NET Core programs can be cross-platform, so I am going to write a website to deploy on Raspberry Pi. The home broadband has a public IP address, but the IP address will change every time the router is restarted, and the free DDNS of the ASUS router is not very easy to use (the home IP has changed, and the domain name resolution has not taken effect in time). I have a DELL desktop and a DELL EMC server at home, so get ready to write a DDNS service and Wake-on-the-Internet tool with ASP.NET Core.

With DDNS, you canGet the IP address of the Internet at home in time, using the Wake-on-Network function is possibleWake up my DELL desktop computer, which is convenient for consulting information at home.

Sites written using ASP.NET Core 6 are deployed on Raspberry PiIt has been running steadily for more than 3 months, without any problems.



Install the AspNetCore runtime

First, the Raspberry Pi needs to be installed with the Raspberry Pi OS system, and the tutorial is as follows:

Raspberry Pi 3B (Raspberry Pi 3B) is installed with the Raspberry Pi OS system
https://www.itsvse.com/thread-10052-1-1.html

Then install AspNetCore Runtimes on top of the Raspberry Pi, log in to the Raspberry Pi host using SSH, and use itsudo -iSwitch to root and create a /usr/dotnet folder with the following command:

Download aspnetcore-runtime-6.0.1-linux-arm.tar.gz and unzip it with the following command:

To create a soft link, the command is as follows:

At this point, the running environment required by ASP.NET Core website is installed, and the installed runtime is checked, as shown in the figure below:



DDNS Dynamic Domain Name Service

Call the DNSPod interface to implement DDNS dynamic domain name service, interface document:The hyperlink login is visible.

Create a new MVC project ASP.NET Core 6 using VS 2022, create a new DNSPodOptions.cs file to configure the parameters required for the invocation interface, as follows:

appsettings.json Add the following configuration:

Modify the Program.cs file to map the configuration information to the DNSPodOptions class, the code is as follows:

Create a new DDNSWorker.cs file, create a background service, obtain an IP address once a minute, and call the DNSPod interface to update the domain name resolution if the IP address changes. (Note:If more than 5 requests to modify records without any changes are submitted within 1 hour, the records will be locked by the system for 1 hour and will not be allowed to be modified again。 For example, the original record value is already 1.1.1.1, and the new request also requires it to be changed to 1.1.1.1. )

The code is as follows:

Modify the Program.cs file and register the backend service with the following code:

The complete Program.cs code is as follows:


The debugger can call the DNSPod interface normally, as follows:


Wake On LAN

Wake-on-LAN is abbreviated as WOL or WoL, which is mostly translated into Chinese as "online wake-up" and "remote wake-up" technology. WOL is a technology, and it is also the specification of this technology, and its effect is to allow a computer that has entered a dormant or shutdown state to issue orders to it through the other end of the local area network (mostly Ethernet), so that it wakes up from hibernation, resumes to operating state, or switches from shutdown state to boot state. In addition, WOL-related technologies also include remote control mechanisms such as remote shutdown and remote restart.

Modify the HomeController controller and add the Wake-on-Network interface, the code is as follows:


Edit the Index.cshtml page, add the MAC address input box and button, and use Ajax to call the interface, the code is as follows:

Start the project as shown below:



Deployed on the Raspberry Pi

Using VS 2022 to release a project, upload the release package to the Raspberry Pi's /home/pi/wol folder, as shown below:




Create a new nbddns.service file under the /etc/systemd/system folder and register the project as a Linux service, as follows:

Start the nbddns service and set the boot to start auto-start with the following command:

View the service status as shown in the following figure:



Finally, in the router settingsPort mapping, and then access through the domain name and the mapped extranet port, my phoneUse 4G networksdirectYou can access ASP.NET Core apps deployed on top of the Raspberry Pi, as shown in the figure below:



(End)





Previous:ASP.NET Core (XI) endpoint route adds middleware to display all DI services
Next:Linux ssh: command not found
Posted on 3/10/2022 11:16:19 AM |
It can be seen that a lot of ash has been eaten
Posted on 3/12/2022 3:17:50 PM |
Come and learn again
 Landlord| Posted on 9/23/2023 9:25:26 AM |
Linux systemd service manager explained in detail
https://www.itsvse.com/thread-10178-1-1.html
 Landlord| Posted on 6/18/2024 1:06:36 PM |
ASP.NET Core (nineteen) uses BackgroundService to run background tasks
https://www.itsvse.com/thread-10591-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com