Introduction
Through Port forwarding, we redirect the LAN IP address and port number of a device located within the internal network (connected to the network protected by the router) to the WAN IP address and port number of the router (located on the external network).
By doing this, we can connect to the device within the router’s domain using the configured WAN IP and port number.
To understand Port Forwarding better, let’s go over a few key concepts:
- IP Address
IP is a set of numbers used to identify and locate a device on the Internet. For example: 192.168.0.1. This format is called an IPv4 address and it consists of 32 bytes. However, due to the development of the Internet, IPv4 is near exhaustion. Therefore, IPv6 addresses were introduced, which consist of 128 bytes to provide more address space.
In addition, there are two main types of IP addresses:
Public IP Address:
A public IP address is globally unique and routable. These IP addresses are used for direct connections to the Internet and can be used to access various services and websites on the Internet.
Private IP Address:
A private IP address is used within a private network, such as a home, office, or corporate local area network (LAN). They are used by routers for communication within the private network. Common private IP address ranges include 192.168.x.x. - Port
Also known as protocol port. Within a device, different applications or services listen for data on specific port numbers. For example, The Secure Shell protocol that will be used later is to use port 22.
https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
Let’s get started!
1. Go to the Raspberry Pi and enable SSH.
Afterward, you can return to your PC to proceed with the next steps.
2. AP configuration
Click http://tplinkwifi.net,enter the password (default: admin).
(Using the TP-Link website as an example, but everyone still needs to configure their own router accordingly.)
Go to “Advanced” and click on “DHCP Server” in the “Network” section.
In order to ensure that the connection will not be interrupted by floating IP, bind the Raspberry Pi’s MAC Address to a static IP.
To add some more information here, using the TP-Link website as an example, the default address lease time is set to 2 hours. Once this time elapses, the IP address will be changed. You also have the option to modify the address lease time, with a maximum limit of 48 hours.
After binding the IP, click on “Port Forwarding” in the “NAT Forwarding” section.
Select the Raspberry Pi, then enter the external port (custom) and input 22 for the internal port.
Don’t forget to check the router’s public IP!!!
3. Use terminal
ssh user@180.180.87.87 -p 69
user: Raspberry Pi user name
Router’s public IP: 180.180.87.87
external port: 69
After entering the Raspberry Pi password, follow the instructions in the terminal to complete the process.