Linux Technology: Understanding loopback interfaces with the use of IP addresses

Source: Internet
Author: User
Tags socket port number

1. The question

Does the IP address belong to the host or is it a network card? This problem is a bit too college pie, in reality, as long as you know the concept of IP address and IP routing, basically no problem. IP as a network layer protocol, it is more important to address rather than identify the host, so you can think that IP is a network card.

However, different people have different views on IP address, in the programmer's opinion, the IP address is a host, because they always use a socket to represent a service, the IP address in the socket represents a host, the protocol and the port number represent a specific process on the host, and for network engineers, They would think that the IP address belonged to a network segment, that is, written on the network card, if a host has more than one network card, then it's each card can have more than one IP address, IP address in the network engineer, more is to be based on IP routing results to the packet sent down a jump.

2.Local routing Table

Each host that implements TCP/IP has a local routing table, although the implementation is not necessarily the same. The so-called local routing table, is marked to reach all of the local network card IP address of the route, including physical network card and virtual network card, of course, including the Opback network card, these routes are the next jump is the last jump, in fact, is this machine, that is, locally received! After the article will mention that on any one network card configured with an IP address, the kernel will automatically add a local table of the routing items.

Therefore, as long as the local table in the configuration of a route, the packet will be received by the three-tier, as to whether to receive success, look at the fourth and higher levels.

3. IP address for addressing

IP address in the upper body of TCP/IP network and two posts, both the host, and is responsible for addressing. The IP is stateless and connectionless, and the packet is gradually approaching the destination by a hop, its important role is IP routing, each intermediary device will have a routing table, the packet reached the intermediary device, according to the longest mask matching principle (regardless of the class IP addressing), find the next jump IP address, and then proceed to " The next hop resolution, such as ARP, implements the addressing at the link layer and then sends the packet down.

4. Indicate the IP address of the host itself

IP address in the upper body of TCP/IP network and two posts, not only responsible for addressing, but also marked host. As a result of the two-yuan confrontation, the IP address of the host can not be configured on any physical network card, and will not rely on the physical network card up and down, as long as the host itself has not down (crash or power off, etc.), any one of the physical network card down will not prevent the host However, the premise is that the packet can reach the host from another network card.

5. Configure the IP address on the physical network card to indicate the host

Configure the IP address on the physical network card to indicate the host, because this physical network card is configured with IP, the routing table will have an impact, the first effect is to generate a direct link route, the other effect is to generate a local route, as long as the local route can be generated to indicate the host, But the physical network card IP label host is the premise of the physical network card is up state, but this reasonable? The physical network card up state remains dependent on a lot of external conditions, and even rely on the NIC to the end of the equipment up state, so this labeling method is unreasonable, under normal circumstances, should not use the physical network card IP address to mark the host, the physical network card IP address should only be responsible for addressing!

6.IP Address Planning

The IP address consists of a host bit and a network bit, the number of host bits describes the size of the network, when planning the network, the network can accommodate the number of card address of the main capacity minus 2, so as long as planning a network will waste two addresses, avoid broadcast address and network address is the way to use the 32-bit prefix, Because the IP address of the 32-bit prefix no longer represents a network, therefore, it is not possible to have the so-called direct-link routing (that is, chain-level routing), so the price of using a 32-bit prefix IP address is to manually add a clear route to the target of 32-bit IP address as the last hop.

So far, I have divided the IP address into two uses, the first one used to mark the host, I use the 32-bit prefix address, and the second purpose I used for addressing, performing standard IP routing. According to the previous description, the IP address of the host can not be configured on the physical network card, then where is the configuration? The answer is the loopback interface.

7.Loopback interface

Loopback interface is a special virtual network card, many people think its address is 127.0.0.1, used to test the protocol stack is not a fault, but things that most people take for granted so simple.

First of all, I can say with certainty that the IP configured on the loopback interface belongs to the host, and the IP address configured on the physical network card can be considered as a host and a NIC in different levels. In addition, this loopback does not rely on any physical link state and Link layer protocol, will never down, as long as there is a NIC is up state and route to reach, the loopback interface configured on the IP address of the host can be reached.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.