Some description of ip addr (full turn)

该系列文章均源自极客时间——刘超《趣谈网络协议》

ip addr is in addition to ifconfig, another view ip command, you can take a look at the output of this command under linux:

[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:e7:d7:08 brd ff:ff:ff:ff:ff:ff
    inet 192.168.3.9/24 brd 192.168.3.255 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fee7:d708/64 scope link 
       valid_lft forever preferred_lft forever

Usually this command we are most concerned about is the ip address that is 192.168.3.9, then we first talk about ip. This is a first IPv4 address, such ip is divided into four parts, each part a byte (8bit), so ip is 32, but the number of such addresses is not enough to produce immediately, and when the original design did not think now there are so many computer, then later gave birth to IPv6, which is above the output of fe80 :: 20c: 29ff: fee7: d708, that there are 128, now it appears to be sufficient.

IPv4 early in the design is divided to five classes, as:

4202450-047a149c53b74845.png
image.png

For the first three categories, each of which is divided into two parts, the network number and host number, why should distinguish between the two? Like we all live in the No.6 unit 1001, I was six cell A unit 1001, and you six unit cell B 1001. Equivalent cell network number, host number corresponding to the specific house number.

The following table, shows in detail the number of A, B, C can contain three types of host addresses.


4202450-7459e5fc07358102.png
image.png

And there are awkward things, the maximum number of hosts is a Class C address can contain too little, only 254. At that time, when I am afraid that the design did not expect, now estimated at a cafe not enough of it. The maximum number of Class B host address can contain another too much. More than 60,000 machines in a network under the general basic business reach this scale, idle address is a waste.

Then turn generates a compromise approach Classless Inter-Domain Routing, CIDR referred to, this solution breaks the original practice of ip divided into five categories, directly to 32-bit address is divided into two, the front is the network number , followed by host number, divide it from where to start? Note that the above inet 192.168.3.9/24,ip output after more than a / 24, which represents the first 24 bits is the network number, the number 8 is the host.

Along with a broadcast address 192.168.3.255 presence of CIDR, if sent to this address, 192.168.3 is the network of all the machines can receive, the other is the subnet mask of 255.255.255.0, the subnet mask and ip address aND operation, since the first three segments are 255, 1, 1 are converted into binary aND operation with any number is the original value, so the same number or three 192.168.3, last paragraph 0,0 with any number and is 0, so the final is 0, the end result is 192.168.3.0, which is the network number, so the result of the operation and the subnet mask and ip is the network number.
In their daily work, almost no division of Class A, Class B or Class C, so a long time, a lot of people forget this classification, but just remember CIDR. But one thing still have to pay attention to, it is the public IP address and private IP addresses.


4202450-a7bb8919a498931c.png
image.png

The rightmost column of the table is private IP addresses. Usually we see the data center, office, home or school of IP addresses, usually private IP addresses. Because these addresses within the organization to allow IT staff to manage their own distribution, and can be repeated. Therefore, a private IP address segment of your school and my school can be the same.

Table 192.168.0.x is the most common private IP address. Your home has Wi-Fi, there will be corresponding to an IP address. Generally you will not be home to more than 256 Internet device, so / 24 basic enough. Sometimes we can also see CIDR / 16, these two are the most common and most easily understood. No need to convert decimal to binary 32, can be evident 192.168.0 network number, followed by a host number. The first address 192.168.0.1 inside of the entire network, is often exported address you this private network. For example, your home PC connected to Wi-Fi, Wi-Fi router address is 192.168.0.1, and 192.168.0.255 is the broadcast address. Once sent to this address, 192.168.0 across all machines inside the network can receive. But all is not always the case. Therefore, other cases will often difficult to understand, but also prone to error. For example: 192.168.3.9/22, ask about this if the first network address, broadcast address and subnet mask, if you come on to answer 192.168.3.1 it would be wrong, is not an integer multiple of 8 to 22 harder to resolve, in front of 192.168 share of 16 unchanged, except for 3 this (0000 0011), only 6bit + 2bit into two parts, so now the situation becomes: 16 + 6 bits are before network number, the remaining two bits are +8 host number, so the first address is 192.168. <000000> <00> .1 192.168.0.1 i.e., the subnet mask is 255.255. <111111> <00>. 0 i.e. 255.255.252.0, broadcast address is 192.168. <000000> <11> .255 i.e. 192.168.3.255. It is not quite wound?

Behind the IP address has a scope, for eno16777736 this card, this is a global, explain this card is external, can receive packets from various places. For lo, this is a host, the network card can only be described for the unit communicate with each other. lo stands for loopback, loopback adapter is also ,, they tend to be assigned to this address 127.0.0.1. This address is used to communicate the machine, the process directly returns after the kernel, it does not appear in any network.

The row address is the ip link / ether 00: 0c: 29: e7: d7: 08, This is called MAC address is a physical address of the card, hexadecimal, six bytes.

Because the MAC address is known globally unique, no two cards have the same MAC address, and NIC self produced, took this address. A lot of people will want to see here, so, the entire Internet communications, all with the MAC address is good, as long as know each other's MAC address, you can pass information in the past. This of course does not work, a network packet is sent from one place to another place, in addition to know each other's specific location, but also a positioning function, ip equivalent is to provide a positioning function, while the MAC address is similar to the ID card number. Indeed, the ID number is globally unique, but the problem is I am in Beijing, in Shanghai you, even if I know you ID number can find you?

Therefore, the MAC address of the communication range is relatively small, confined inside a subnet. For example, access from 192.168.0.2/24 192.168.0.3/24 is the MAC address. Once across subnets, from 192.168.0.2/24 to 192.168.1.2/24,MAC address to die, you need the IP address into play.

MAC address resolve over, we will look at <BROADCAST,MULTICAST,UP,LOWER_UP>is doing? This is called net_device flags, status of network devices identity. UP indicates the card in the activated state; BROADCAST represents a broadcast address that the network card can send a broadcast packet; represents the MULTICAST card can send a multicast packet; LOWER_UP represents L1 is activated, i.e. it stuck cable. MTU1500 refers to the MTU is 1500, which is the default value of Ethernet.

qdisc pfifo_fast What does it mean? qdisc stands for queueing discipline, Chinese name queuing discipline. If required by the kernel interface to send a network packet, it needs to follow for this qdisc allows users to configure the interface (queuing discipline) is added to the packet queue. The simplest is pfifo qdisc, it does not do any incoming data packet processing packets using FIFO manner through the queue. pfifo_fast slightly more complex, its queue comprises three bands (band). In each band inside, using the FIFO rule.

=====================================================

ip --- configure multiple IP addresses (aliases) to the network adapter and delete

increase

Format: ip addr add CIDR dev NIC NIC name label name: num

Examples: ip addr add 3.3.3.3/24 dev eth1 label eth1: 2

4202450-0413921b9ce9d589.png
image
4202450-4a887aaaa60ab189.png
image

delete

Format: ip addr del CIDR dev card name

Specifies to delete example: ip addr del 3.3.3.3/24 dev eth1

4202450-fe54b35fff0e0e83.png
image

Delete all: ip addr flush eth1

4202450-5edecc777c69b175.png
image

Guess you like

Origin blog.csdn.net/weixin_33802505/article/details/90862943