Setting Up a Raspberry Pi Server with Port Forwarding for Remote Access

Content Preview

In the previous article, we set up an Ubuntu server system for Raspberry Pi on the SD card using Raspberry Pi Imager. After inserting it into the Raspberry Pi slot and connecting the network cable and power, we have a Raspberry Pi server✌🏻.Setting Up a Raspberry Pi Server with Port Forwarding for Remote Access

However, many users wish to easily access the Raspberry Pi from the external network during daily use, whether you are in the office or traveling. Port forwarding is the key to achieving this goal. This article will focus on implementing this function through router port forwarding.

1. Comparison of Port Forwarding Technologies

Before we start configuring, let’s understand several common port forwarding technologies and their pros and cons to choose the most suitable solution:

Technology Advantages Disadvantages Applicable Scenarios
FRP (Fast Reverse Proxy) Open source, supports multiple protocols (e.g., HTTP, TCP, UDP), flexible configuration Requires your own server for relay, slightly complex configuration, higher learning curve Suitable for users with self-built servers needing stable long-term use
ngrok Ready to use, simple and easy, supports HTTP/HTTPS, suitable for quick testing Free version has traffic and connection limits, uses official relay server, privacy is poorer Short-term development debugging or temporary external access
ZeroTier Creates a virtual LAN, no relay server needed, high security and privacy Configuration is relatively complex, relies on ZeroTier service, may have network latency Remote management of multiple internal devices or creating cross-regional virtual networks
Peanut Shell Chinese interface, easy to use, suitable for beginners Free version has many restrictions (e.g., traffic and port limits), relies on external servers Beginners or users needing a Chinese interface
Router Port Forwarding Simple and efficient, fully controlled, no reliance on external services, stable and reliable Requires manual router configuration, firewall settings may cause access issues Suitable for home and small office users, especially those needing long-term external access

2. Why Choose Router Port Forwarding?

Among many port forwarding technologies, router port forwarding is favored for its simplicity and efficiency, complete control, and stability and reliability. You don’t need extra servers or services; just configure the router to easily achieve external access.Setting Up a Raspberry Pi Server with Port Forwarding for Remote Access

3. Steps to Operate

Step 1: Fixed IP Setting

First, you need to assign a fixed IP address to the Raspberry Pi. This step is very important because the port forwarding rules need to bind to a specific IP address. If the Raspberry Pi’s IP address changes frequently, the port forwarding rules will fail.

Setting Up a Raspberry Pi Server with Port Forwarding for Remote Access
Step 2: Confirm the Raspberry Pi Device’s IP Address

Find your Raspberry Pi device within the local network and confirm its IP address. This can be done by accessing the router’s DHCP client list.

Setting Up a Raspberry Pi Server with Port Forwarding for Remote Access
Step 3: Configure Port Forwarding

Enter the router’s port forwarding configuration page and add a new forwarding rule. Here are the specific steps:

  1. Select Forwarding Protocol: Usually choose TCP or UDP, depending on the type of service you need.
  2. External Port: Enter the port number used to access from the external network.
  3. Internal IP Address: Fill in the fixed IP address of the Raspberry Pi.
  4. Internal Port: Enter the port number of the actual service running on the Raspberry Pi, for example, port 80 for HTTP service.
Setting Up a Raspberry Pi Server with Port Forwarding for Remote Access

Tip: Ensure that the router’s firewall settings allow the port you configured. Otherwise, it may not be possible to successfully access the Raspberry Pi from the external network.

Step 4: Save and Apply Settings

On the port forwarding page, click the add button to save the above information as a new forwarding rule.

Setting Up a Raspberry Pi Server with Port Forwarding for Remote Access

Make sure all settings are correct, then apply the configuration.

Setting Up a Raspberry Pi Server with Port Forwarding for Remote Access

4. Test if Port 22 Achieves Internal Network Penetration

We use the laptop command line to test whether we can SSH remotely log into our Raspberry Pi server using the external IP addressSetting Up a Raspberry Pi Server with Port Forwarding for Remote AccessSuccess! 🎉 🎉 🎉

5. Summary and Next Steps

Through the router’s port forwarding function, you can successfully achieve internal network penetration for Raspberry Pi. This method is simple and provides a stable remote access experience, making it very suitable for home and small office environments.

Next Step: In the next article, we will discuss how to deploy a secure web server on Raspberry Pi after configuring internal network penetration. Stay tuned!

Occasional updates on professional knowledge and interesting things, feedback, likes, and stars are welcome

Your encouragement and support are my greatest motivation to continue creating! ღ( ´・ᴗ・` )Setting Up a Raspberry Pi Server with Port Forwarding for Remote Access

References

  1. FRP GitHub: https://github.com/fatedier/frp

  2. ngrok Documentation: https://ngrok.com/docs

  3. ZeroTier Documentation: https://docs.zerotier.com/

  4. Peanut Shell: https://hsk.oray.com/

  5. How to Forward Ports on Your Router: https://www.howtogeek.com/66214/how-to-forward-ports-on-your-router/

  6. Raspberry Pi Documentation: https://www.raspberrypi.org/documentation/

  7. Port Forwarding and NAT Basics: https://www.homenethowto.com/port-forwarding-and-nat-basics/

Leave a Comment

×