Trusted answers to developer questions

What is port forwarding?

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

Port forwarding allows external devices to connect to devices in a private network.

The need for port forwarding

Small networks (e.g., home networks) have a single external IP address, and each device in the network has a unique internal IP address. Internal IP addresses are not routable on the internet; hence, a router uses Network Address Translation (NAT) to map internal IP addresses and port numbers to external IP addresses and port numbers. The port numbers that NAT uses are randomly selected, which poses a problem when you want a host to connect to a server in your internal network that uses a standard port.

The router translates private IP addresses and ports to public IP addresses and ports (and vice versa) so that external devices can connect to the devices in the private network.
The router translates private IP addresses and ports to public IP addresses and ports (and vice versa) so that external devices can connect to the devices in the private network.

How port forwarding works

Suppose you have a web server running on your private network ​and external clients expect to connect to port 80. To enable this, you need to use port forwarding. In this example, port forwarding would involve statically mapping the external IP address and port 80 to the internal IP address and port 80.

How to enable port forwarding

To enable port forwarding, log in as an admin on the desired router, and enter the external port numbers that need to be mapped to the internal port number.

RELATED TAGS

networks
ip
nat
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?