NAT
Network Address Translation (NAT) is a method used by routers or firewalls to translate private, internal IP addresses to a single, public IP address to enable multiple devices on a private network to share a single internet connection. This process masks the internal network, provides security by hiding internal IP addresses, conserves public IP addresses, and allows devices with private IPs to connect to the internet.
How it works
Private to Public: When a device on a private network (like your home) sends a request to the internet, the router receives it. The router modifies the packet's header, replacing the private source IP address with its own public IP address.
Port Forwarding: To handle multiple devices and connections, the router also translates the port number. It creates a table that maps each internal device's private IP and port to a specific outgoing port on its public IP.
Public to Private: When a response comes back from the internet to the router's public IP address, the router uses its translation table to look up the original private IP address and port and forwards the packet to the correct internal device.
Destination NAT: NAT can also be used to make a local server accessible from the internet by permanently linking a public IP and port to a specific internal IP and port. This is called port forwarding and is often used to host servers.