Internal network IP External network IP NIC router communication process (full)

       In the past few days, I have been taking a computer network class, and I am ignorant about the content of the teacher's speech. After the class, google supplemented some things to be able to get a general understanding, but the summaries on the Internet are scattered and point to point. After collecting the summaries of many big guys, I finally got some insights of my own. Therefore, I will summarize it here, and I hope that the bloggers who see it will also have some gains.
Not much to say, as usual, list a directory first:
external network ip
, internal network ip
, internal card
gateway
router

IP address:
IPV4 is 4 segments, each segment is 8 bits , represented by decimal numbers, and each segment number ranges from 0 to 255 . Such as 192.134.11.3. The IP address can be regarded as two parts: the network identification number and the host identification number, so the IP address can be divided into two parts, one part is the network address and the other part is the host address . IP addresses are divided into A, B, C, D, and E5 categories, and their applicable types are: large network; medium network; small network; multi-purpose address; standby. Commonly used are B and C categories. The default subnet mask is
to distinguish the network address and the host address. In the
future , there will be IPV6
. The IPv4 private address will not be discussed here . 255.0.0.0 (meaning that the first segment is the network number and the last three segments are the host address) Class B 128.0.0.0-191.255.255.255 default subnet mask: 255.255.0.0 Class C 192.0.0.0-223.255.255.255 default subnet mask Code: 255.255.255.0 The broadcast address is the IP address (“255.255.255.255”) that can send information to all computers in the network segment and each byte in the IP address is 1 (“ 255.255.255.255 ”) is the broadcast of the current subnet address;








An address where each byte is 0 (" 0.0.0.0 ") corresponds to the current host;

All class E IP addresses starting with "11110" in the IP addresses are reserved for future and experimental use.

The IP address cannot start with decimal "127". The numbers 127.0.0.1 to 127.255.255.255 in this type of address are used for loopback testing. For example, 127.0.0.1 can represent the local IP address. " http://127.0.0.1 " can test the Web server configured in this machine.
The special IP address
127.0.0.1 represents the local loopback address

The reserved internal private addresses are listed below
**Class A 10.0.0.0–10.255.255.255
Class B 172.16.0.0–172.31.255.255
Class C 192.168.0.0–192.168.255.255**

Other IPs are considered external IPs.
write picture description here
write picture description here
Q:
If I use a router, is the IP under the router, such as 192.168.1.101, the intranet IP, and the IP 100.64.0.30 assigned by the router is the external network IP? Is the router only accessible from the outside, if port mapping is not used? Are you unable to access the IP 192.168.1.101?"
Answer:
The first two guesses are correct. The third one feels inaccurate and should be the technology of NAT. (
To communicate with hosts outside the gateway, you must use NAT, PROXY Or tunnel technology for address translation (
mask ) (see the router below for details)
Summary:
1. The external network IP is the address of the entire Internet, unique, and there is no duplicate
2. The internal network IP is the IP address in the local area network, and only the local area network can be used. For internal resources, if you want to use Internet resources, you need to have an external network IP as an exit, and different internal networks can reuse IP, for example, network A has 192.168.0.1, and network B can also have it without conflict.
3. Under a router There can be multiple computers and each of these computers has its own internal network IP address. The internal network computer needs to share the external IP address of the router through the router. There is a NAT protocol that records the external network corresponding to the internal network computer ip and port number. ip and port number. When two computers in an intranet access Baidu NAT at the same time, the intranet ip will be parsed into an external network ip and then accessed to Baidu. For Baidu, two ports of one ip access itself. Then the two access The result is returned to the router The router returns to the computer that does not pass through the internal network according to the port number (that is, the corresponding computer is mapped to the NAT)
4. The internal network IP address is dynamically allocated and the external network IP address is fixed
5. 127.0 .0.1to 127.255.255.255 for loopback test address
6. " 255.255.255.255 is the broadcast address
7. 0.0.0.0 means the local address when not assigned
8. The subnet mask cannot exist alone, it Must be used in conjunction with IP addresses
9. All network space calculations must be "minus 2" because two reserved addresses are deducted: "0" for the network number and "255" for the broadcast. Addresses 1-254 are assigned to hosts 10.
Send to the broadcast address, all computers in this network segment can receive it. For example, if you send information to 192.168.1.255, then the network segment starting with 192.168.1.255.ip can receive the message you send.
11. The broadcast address is only available in UDP There is no broadcast address in TCP. The next blog will talk about the
network card :

Almost every computer has a network card which also has a unique identifier that is the MAC address not just computer routers etc. The MAC is the physical address that is the destination of the link layer transfer .
Then there is a question, what is the role of the network card?
It is for computer networking services . Specifically, let me explain how it works.
An IP address is required when a computer needs to be connected to the Internet. (The cornerstone of communication with the outside world is equivalent to the address for sending and receiving mail. How to send and receive without an address?)
How is the IP allocated? At this time, DHCP (Dynamic Host Configuration Protocol) is required. Routers all come with this protocol, so Generally, it is based on the principle of proximity to find the router connected to this computer to allocate. Then how to notify the DHCP server (router)? At this time, the network card comes in handy:
it is actually a DHCP discovery message (requested information) of the application layer, which is then encapsulated by a UDP packet and then encapsulated by an IP datagram as shown below:
write picture description here
(UDP is the transport layer responsible for data The operation IP is responsible for the network layer responsible for the transportation of data)
and then the network card wraps the data frame into an Ethernet frame and sends it out, but to send a letter, you always need to know the MAC address of the other party. If you don't know it at this time, the broadcast is broadcast to the same child. All computers in the network then pass the information through the switch to all devices connected to the switch and then find the DHCP server. At this time
1. The DHCP server (router) will dynamically assign an IP address to the computer, but this address is an intranet IP address commonly known as private Address (specifically introduced below)
2. The network card sends a confirmation letter to tell the DHCP server that I want this IP
3. The network card receives a confirmation letter including IP 192.168.1.3 (the last two digits are optional) The gateway router is 192.168.1.1 The address of the DNS server is 202.102.224.69 The
above steps are all completed automatically. The
gateway router is actually a router that is equivalent to a gate guard. The gateway to the Internet
DNS server is a server that can convert the IP address according to the domain name.
For example, we want to go to Baidu.com but only know the IP domain name. We need to know the IP address of Baidu, but how do we know it is to find the DNS server through the gateway router The address of Baidu is obtained by parsing.
Then the problem comes again. The actual transmission is that the data link layer needs to know the MAC address before it can be transmitted. What should I do at this time?
ARP came out. It is an address resolution protocol. You can find the corresponding MAC address through ip, and then the computer broadcasts it to find the MAC address of the router and sends the information (by the way, record the mac in the memory and you don’t need to search it repeatedly next time) The matter of coming out of the LAN It was handed over to the router. The router repeatedly found the DNS server and returned Baidu's ip address, and then obtained Baidu information through TCP GET and other requests by establishing a TCP connection.
write picture description here
Later , a wireless network card appeared. . That's not much to explain

Gateway
So what exactly is a gateway? A gateway is essentially an IP address from one network to other networks. For example, there are network A and network B, the IP address range of network A is "192.168.1.1~192.168.1.254", the subnet mask is 255.255.255.0; the IP address range of network B is "192.168.2.1~192.168. 2.254” and the subnet mask is 255.255.255.0. In the absence of a router, TCP/IP communication cannot be performed between the two networks. Even if the two networks are connected to the same switch (or hub), the TCP/IP protocol will be based on the subnet mask (255.255 .255.0) determines that the hosts in the two networks are in different networks. To realize the communication between these two networks, it must go through the gateway. If the host in network A finds that the destination host of the data packet is not in the local network, it forwards the data packet to its own gateway, and then the gateway forwards it to the gateway of network B, and the gateway of network B forwards it to a certain gateway of network B. host. The same goes for the process of network B forwarding packets to network A. Therefore, only by setting the IP address of the gateway, the TCP/IP protocol can realize the mutual communication between different networks. So which machine's IP address is this IP address? The IP address of the gateway is the IP address of the device with routing function. The device with routing function includes a router, a server with routing protocol enabled (essentially equivalent to a router), and a proxy server (also equivalent to a router).
The server serving as the gateway has an IP address of the gateway (server/router), and the IP of other intranet computers can be arbitrarily set according to it, provided that the first three numbers of the IP are the same as it, and the fourth one can be from 0-255 Optional but different from the server's IP. The
default gateway IP address is 192.168.1.1 , which is the router's IP address in the intranet. The IP address in the LAN should be 192.168.1, followed by a field of 0 to 255. If the router is also connected to the external network, the router will obtain another ip address, which is the so-called external network ip

Router:
Why is it called a gateway because it is a major gateway from the gate to the outside world.
Each router will be assigned an external network ip address, which is different from the internal network ip address.
Q: How many addresses does a router have?
Answer : Generally, two IP addresses can be set inside the home router itself, one is the gateway IP address of the LAN port, and the other is the IP address of the WAN port. This address is obtained according to the static IP or ADSL dial-up method given to you by the telecom operator.

Why do you need an intranet ip address?
Because the intranet ip in different LANs can be repeated, it can relieve the address pressure, otherwise it is not enough. The
router will take off the coat of the data link layer and find the address of the ip data packet. ip address range mentioned above)

For example, when sending a request to
the external network 1. It will replace the source address with its own external network address, which is the internal network address
. 2. It will create a new port number and replace the source port in the TCP packet.
Completed These two steps are ok, so that the external network thinks it is a request sent by the router. When the router receives the result, it checks the routing table to determine which port to forward to, and then returns the result to the corresponding computer. This is network address translation called NAT
. This is achieved by using one external network IP to support the Internet access requirements of multiple computers in the local area network, thus realizing the internal network access to the external network.
How can the external network access the internal network?
It is also through NAT to notify the external network that I am here, and then the external network accesses the router ip and port correspondence and sends the request to the corresponding internal computer.
To check the IP address of your computer, that is, the internal network ip:
1. Press and hold the menu key + R to enter the run
2. Enter cmd to enter the command line
3. ipconfig to view the IP address and
attach your own query results.
write picture description here
According to the results, I know that my default gateway is 192.168.2.1
. My computer ip is 192.168.2.226
. If I want to broadcast, change it to 192.168.2.255. But machines with the same network number can receive my message
How to check the IP address of this router?
https://ip.cn/
This website can be attached to mine: It is emphasized that the default gateway is the IP subnet
write picture description here
of the intranet . Please also point out

Recently, I want to build a local server, which is different from those remote servers of Alibaba Cloud. The local server is only valid locally. It means that it is valid in the same network segment under a router. The
local server is the communication between two computers in the local area network is relayed through the router but not through the external network. You
need to download tomcat Let's do it later. First of all, there is a concept that the ip allocated by the local server is the internal network ip instead of the public network ip.

Reference:
Intranet and extranet communication
What is extranet IP intranet IP
intranet subnet LAN extranet
IP address classification, the difference between intranet and extranet
About intranet IP and extranet IP
TCP/IP network layer
LAN IP address segment
ip address intranet

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325933306&siteId=291194637