1, the introduction

Programmers who develop network communication applications may often hear about extranet IP(Internet IP address) and Intranet IP(LAN IP address), but what is the difference? What does it matter? In addition, we all know that when it comes to external and internal IP addresses, we have to mention NAT and routing translation. Here’s how it all works.

2. Must every computer have a public IP address?

Answer: No.

IPv4, as we all know, the number of the IP address is limited (IPv6) are now doing so, each part of his address assignment out, that means can be used to assign IP addresses and even fewer, and as now, the rapid development of computers, if every mobile phone or computer requires an IP address, So obviously IP addresses are not enough.

To solve this problem, we can adopt the following strategy: for example, for a company, each company will have its own Intranet (also known as LAN).

An Intranet (Local Area Network (LAN)) is a computer communication Network that connects various computers, external devices, and databases within a Local geographical Area. It can be within a few meters (for example, a home Intranet) or within a radius of several thousand meters (for example, a university Intranet).

The Intranet provides the following functions:

1) Shared transmission channel: it is simply understood that each computer does not need an external IP address; 2) High transmission rate: because the computers between the Intranet are not as complex as the topology of the external network, the network can communicate with each other quickly. For example, it may only take tens of seconds to copy a file of several gigabytes from one computer to another. 3) low ber: because the communication distance is very close, so the error rate is very low, in other words, the network is stable (older programmers know, when I was in college dormitories play C/S network network, rarely face offline or caton, unless someone rushes or give pulled out the network, ha ha).

3. How to assign and manage Intranet IP addresses?

Suppose we assign company A an IP=192.168.1.1. Let’s use this IP address as the gateway to the Intranet of the company.

There are three computers in company A’s Intranet. If these three computers want to access the Internet, we need to assign them an IP address. As mentioned in the previous section, do we need to apply for three IP addresses to use them?

A no. We don’t necessarily need to apply for 3 IP addresses, in our Intranet, we can specify our own rules, for example, we can randomly assign 3 IP addresses to these three computers (please note that these three IP addresses are not applied for, and I randomly assign them). Computer A = 192.168.1.2 COMPUTER B = 192.168.1.3 computer C = 192.168.1.4.

This rule can be managed by our Intranet gateway, as follows:

4. NAT technology: the ability of Intranet computers to access the Internet

Suppose computer A wants to access Baidu, baidu’s IP address is assumed to be 172.168.30.3:

As we all know, computer A’s IP is our fictitious, in fact there may not be such an IP, if you use computer A’s IP to visit Baidu, it certainly won’t work.

We also know that baidu and computer A are not in the same LAN, so A must go through the gateway to access Baidu. The gateway IP address, is real, is access to Baidu.

In order to enable A to access Baidu, we can take such A method: let the gateway to help A access, and then Baidu to pass the result to the gateway, and the gateway to pass the result to A, so that can not be solved?

However, computer A, B, and C may ask the gateway to help them access Baidu, and the destination IP of the result returned by Baidu is the gateway IP=192.168.1.1. How does the gateway distinguish between the results of A, B, or C?

When we go to visit Baidu, isn’t it necessary to specify a port? As long as we map THE IP+ port of A to the IP+ port of the gateway, can’t we uniquely determine the identity?

For example, if A uses port 60 to access Baidu, the gateway can map IP+ port 60 of A to IP+ port 80 of the gateway.

After Baidu returns the result to port 80 of the gateway, the gateway, through the mapping table, can return the result to port 60 of A.

If B also uses port 60 to access Baidu, it is the same, and it can be mapped to port 90.

This method of Address mapping Translation, we also called Network Address Translation, English for Network Address Translation, abbreviated NAT.

IP addresses such as A, B, and C are also called Intranet IP addresses. And IP addresses like gateway and Baidu are called extranet IP.

Therefore, a typical Intranet access to the public network can be achieved as follows:

So now you know the extranet IP and the internal IP?

5. Summary of this paper

In order to solve the shortage of IP addresses, technical experts invented the Intranet technology, and the theoretical support of the Intranet technology is NAT technology. Therefore, it is necessary for programmers engaged in network communication to have a deep understanding of NAT technology.

Reference article:

Network.51cto.com/art/201809/… Network.51cto.com/art/201901/…