MAC/IP/ subnet mask are very important in the network, and these three concepts will be involved wherever there is a network.

A, MAC

Each nic has a 48-bit MAC address (Media Access Control).

  • Unique in the world, embedded in the ROM of a network card, specified by the IEEE802 standard

    • First 3 bytes: OUI (Organizationally Unique Identifier), the unique identifier of the organization byIEEEThe registration authority is assigned to the vendor
    • The last three bytes: network interface identifier, assigned by the vendor
  • OUI query

    • standards-oui.ieee.org/oui.txt
    • mac.51240.com/

1.1. Format of the MAC Address

  • Windows
    • 32-06-52-3C-4F-2E
  • Linux, Android, Mac, iOS
    • 32:06:52:3C:4F:2E
  • Packet Tracer
    • 3206.523 C. 4 f2e
  • When all 48 bits are 1, it indicates the broadcast address (for all devices on the same network segment).
    • FF-FF-FF-FF-FF-FF

1.2. MAC Address Operation

Viewing the MAC Address (terminal) :

  • Windows:ipconfig
  • Linux/Mac:ifconfig

Sometimes, you can access the Internet by changing the MAC address (some companies set the MAC address whitelist on their Intranet routers, which is the case in our company. Even mobile phones cannot connect to the wireless network).

1.3. Obtaining the MAC Address

If you do not know the MAC address of the host, you can obtain the MAC address by sending ARP broadcasts

  • After obtaining the IP address and MAC address mapping information, ARP cache is commonly known as ARP cache
  • MAC addresses obtained through ARP broadcast belong to dynamic cache. The storage duration is short (2 minutes by default). After the storage period expires, the storage system will be automatically deleted.

If the MAC address cannot be found, ARP broadcasts are sent again. Therefore, you do not need to worry about the Internet access failure after the network adapter is replaced.

Related commands:

  • Arp -a [host address]: Queries ARP cache
  • Arp -d [host address]: Deletes ARP cache
  • Arp -s [host address] [MAC address]: Add a cache message (this is a static cache, storage time is relatively long, different systems storage time is different)

Second, the IP

Internet Protocol (IP) : Each host on the Internet has an IP address

Originally IPv4, 32bit (4 bytes), on November 25, 2019, the world ran out of IP addresses. Later came the IPv6 version, 128bit (16 bytes).

2.1. Composition of IP addresses

An IP address consists of two parts: Network ID (network ID) and host ID (host ID) Computers on the same network segment have the same network ID

You can calculate the network ID by using the subnet mask: IP address & subnet mask

Bitwise & (&) calculation technique: 1 is the original, 0 is 0.

Case 1:

IP address: 192.168.1.10 Subnet mask: 255.255.255.0 Computing network segment: 1100 0000.1010 1000.0000 0001.0000 1010 -> 192.168.1.10(base 10) & 1111 1111.1111 1111.1111 1111.0000 0000 -> 255.255.255.0 (decimal) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- = 0000.1010 1000.0000 0001.0000 1100 0000 -> 192.168.1.0(base 10) 192.168.1 indicates the network ID and the following part indicates the host ID.Copy the code

Case 2:

IP address: 192.168.1.10 Subnet mask: 255.255.0.0 Computing network segment: 1100 0000.1010 1000.0000 0001.0000 1010 -> 192.168.1.10(base 10) & 1111 1111.1111 1111.0000 0000.0000 0000 -> 255.255.0.0 (decimal) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- = 0000.1010 1000.0000 0000.0000 1100 0000 -> 192.168.0.0(base 10) 192.168 indicates the network ID, and the last two bits indicate the host ID.Copy the code

Note: Remove all 0s and 255 from the host ID because 0 represents the network segment (example: 192.168.0.0) and 255 represents the broadcast address (example: 192.168.255.255).

Before communicating with other computers, the computer checks whether the target host and itself are on the same network segment

  • Same network segment: Does not need to be forwarded by a router
  • Different network segments: The router forwards the packets

2.2. IP Address Classification

2.2.1. Class A Address: The default subnet mask is255.0.0.0

Network ID:

  • 0Can’t use,127Reserved network segment. Among them127.0.0.1Is the loopback address (Loopback), representing the local address.
  • So, the range of values in Part 1 that can be assigned to hosts is:1~126

The host ID:

  • The value ranges of parts 2, 3, and 4 are:0 ~ 255
  • The maximum number of hosts that each Class A network can hold is:256 * 256 * 256-2 = 2 ^ 24-2 = 16777214

2.2.2. Class B Address: The default subnet mask is255.255.0.0

Network ID:

  • That can be assigned to the host
    • The range of values in Part 1 is:128 ~ 191
    • The range of values in Part 2 is:0 ~ 255

The host ID:

  • The value ranges of parts 3 and 4 are:0 ~ 255
  • The maximum number of hosts that a Class B network can hold is:256 * 256-2 = 2 ^ 16-2 = 65534

2.2.3. Class C Address: The default subnet mask is255.255.255.0

Network ID:

  • That can be assigned to the host
    • The range of values in Part 1 is:192 ~ 223
    • The value ranges of parts 2 and 3 are:0 ~ 255

The host ID:

  • The range of values in Part 4 is:0 ~ 255
  • The maximum number of hosts that each Class C network can hold is:256 minus 2 is 2 to the eighth minus 2 is 254

2.2.4. Class D address1110Beginning, multicast address

Class D addresses do not have a subnet mask and are used for multicast (multicast) addresses.

Part 1 The value ranges from 224 to 239.

2.2.5. Address of Class E1111The beginning is reserved for future use

Class E addresses are reserved for future use.

Part 1 The value ranges from 240 to 255.

Only class A/B/C addresses can be assigned to hosts.

  • Host ids are all 0s, indicating the network segment where the host resides
  • Host ids are all 1, indicating all hosts in the network segment where the host resides (broadcast)
  • You can use ping to send data to all hosts on a certain network segment

3. Subnet mask

3.1. The CIDR

CIDR: Classless inter-domain Routing (CIDR) : Classless interdomain Routing.

CIDR representation of a subnet mask:

  • 192.168.1.100/24, means that the subnet mask has 24 ones, i.e255.255.255.0
  • 123.210.100.200/16Represents that the subnet mask has 16 ones, i.e255.255.0.0

Computational tools: www.sojson.com/convert/sub…

3.2. Subnets

Why subnets?

If 200 hosts need to reside on the same network segment, you can allocate a Class C network segment, for example, 192.168.1.0/24.

  • A total of 254 available IP addresses:192.168.1.1 ~ 192.168.1.254
  • 54 more free IP addresses (this is not a waste of resources)

If 500 hosts need to be on the same network segment, assign a class B network segment, such as 191.100.0.0/16.

  • 65,534 available IP addresses:191.100.0.1 ~ 191.100.255.254
  • 65034 more idle IP addresses (this is a huge waste of resources)

How to avoid wasting IP address resources? Divide subnets properly.

Subnet division: Use the host bit as the subnet bit to divide multiple subnets.

  • Can be divided into:
    • Equal-length subnet division:Divide a network segment into multiple subnets, and each subnet has the same number of available IP addresses.
      • Such asAlong / 16Four subnet segments are divided, and each segment has 6553 AVAILABLE IP addresses.
    • Variable-length subnets:The number of available IP addresses for each subnet can be different.
      • Such as191.100.0.0/16Allocate 512 IP addresses to the first segment, 2048 IP addresses to the second segment, and the rest to the last network segment.

Subnet delimit separator: www.ab126.com/web/3552.ht…

The steps for dividing subnets are as follows:

  • Determine the length of the subnet mask
  • Determine the IP address available to the first and last host in the subnet

3.2.1. Division of isometric subnets

Equally divided into 2 subnets:

A subnet:

  • Network segment:192.168.0.0
  • Subnet mask:255.255.255.128/25
  • Radio:192.168.0.127
  • Host range:192.168.0.1 ~ 192.168.0.126

B subnet:

  • Network segment:192.168.0.128
  • Subnet mask:255.255.255.128/25
  • Radio:192.168.0.255
  • Host range:192.168.0.129 ~ 192.168.0.254

Equally divided into 4 subnets:

A subnet:

  • Network segment:192.168.0.0
  • Subnet mask:255.255.255.192/26
  • Radio:192.168.0.63
  • Host range:192.168.0.1 ~ 192.168.0.62

B subnet:

  • Network segment:192.168.0.64
  • Subnet mask:255.255.255.192/26
  • Radio:192.168.0.127
  • Host range:192.168.0.65 ~ 192.168.0.126

C subnet:

  • Network segment:192.168.0.128
  • Subnet mask:255.255.255.192/26
  • Radio:192.168.0.191
  • Host range:192.168.0.129 ~ 192.168.0.190

D subnet:

  • Network segment:192.168.0.192
  • Subnet mask:255.255.255.192/26
  • Radio:192.168.0.255
  • Host range:192.168.0.193 ~ 192.168.0.254

Class B Subnets:

Class A Subnets:

Rule: Subnets should be divided into equal groups2^nIs smaller, the subnet mask is moved to the rightnposition

Consider: Can the following two devices communicate normally?

Answer: No, because they are in different network segments. The network segment for computer 0 is 192.168.0.0, and the network segment for computer 1 is 192.168.0.128. For the two devices to communicate, you need to add a router.

3.2.2. Variable-length Subnets

If a subnet address block is (1/2)^n of the original network segment, then

  • Add n 1s to the subnet mask of the original network segment
  • Subnets are not equally long, and their subnet masks are different

Assume that 192.168.0.0/24 is divided into A subnet of varying length. Network segment C: the subnet mask is 255.255.255.128/25 NETWORK segment B: the subnet mask is 255.255.255.192/26 A: the subnet mask is 255.255.255.224/27 D: Subnet mask 255.255.255.252/30 E Network segment: The subnet mask is 255.255.255.252/30

Consider: Can the following two devices communicate normally?

Answer: No, because they are in different network segments. The network segment for computer 0 is 192.168.0.0, and the network segment for computer 1 is 192.168.10.0. For the two devices to communicate, you need to add a router.

Analysis: computer 1 0 and computer communication, only 1 IP address of the computer, no computer 1 subnet mask, in the end is holding each other’s IP address and subnet mask bitwise and calculate the network segment, so computer network segment is 192.168.10.0, 1 0 and computer is not in the same network segment, is unable to communicate. If computers 1 and 0 for communication, two sets of equipment of IP and subnet mask of computer 1 after the bitwise and calculation network segment is 192.168.0.0, can send message to the computer 0, 0 but because the computer calculation and computer 1 is not in the same network segment, computer can’t reply message to the computer 1 0, so can’t normal communication.

Note: The IP address classification depends on which category the first part of the IP address belongs to. The subnet mask has nothing to do with the IP address classification. Subnets can only be an exponent of 2.

3.3. Super net

Hypernet: As opposed to a subnet, it combines multiple contiguous network segments into a larger network segment.

3.3.1. Merge two network segments

Divide the network for use by hosts. In the figure above, the network segment 192.168.0.0 and 192.168.1.0 is 192.168.0.0, and the number of hosts is twice as high as before because the host bit is increased by 1 bit.

Requirement: There were 200 computers using 192.168.0.0/24 network segment, now we want to add 200 devices to the same network segment.

  • 200 units in192.168.0.0/24Network segment, 200 units in192.168.1.0/24Network segment
  • merge192.168.0.0/24,192.168.1.0/24For a network segment:192.168.0.0/23(Subnet mask moves 1 bit to the left)

Think: can the IP address 192.168.0.255/23 be assigned to a computer?

Answer: Yes. Because the host part is actually 9 bits, the high level of the host bit is 0, not all 1, so this IP address is not a broadcast address, and can be assigned to the computer. If the high level of the host part is changed to 1, the actual IP address is 192.168.1.255/23 (broadcast address), which cannot be assigned to the computer.

3.3.2. Merge the four network segments

Move the subnet mask two bits to the left to merge four network segments.

Merge 192.168.0.0/24, 192.168.1.0/24, 192.168.2.0/24, and 192.168.3.0/24 into network segment 192.168.0.0/22.

Consider: can the following 2 network segments be merged by moving 1 bit to the left through the subnet mask?

Answer: No. To merge 192.168.2.0 and 192.168.1.0 into the same network segment, you must move 192.168.2.0 two places to the left.

3.3.3. Rules of merging network segments

Let’s say n is 2 to the k.

  • Moving the subnet mask k bits to the left will merge n network segments
  • If the network number of the first network segment is divisible by N, then the n consecutive network segments starting from it can be merged by shifting the subnet mask k bits to the left

Such as:

  • The network number of the first network segment ends in binary 0, so the two consecutive network segments starting from it can be merged by moving the subnet mask one bit to the left
  • The network number of the first network segment ends in binary 00, so the four consecutive network segments starting from it can be combined by moving the subnet mask two bits to the left
00 0 192.168.0.0/24 192.168.0000 | | 0 0.0 1 00 192.168.1.0/24 192.168.0000 | 0 1.0 2 192.168.2.0/24 192.168.0000 00 | | 1 | 0.0 3 00 192.168.3.0/24 192.168.0000 | 1 | 1.0 above is easy to see that 1 and 2 left one can't be merged into the same network segment. Move 1 bit to the left, 0 and 1 can merge, 2 and 3 can merge. Move 2 bits to the left, 0 to 3 can be combined.Copy the code

Once a hypernet is used, there is no need to classify addresses. Of course, specific or according to the needs of customization.

3.4. Determine whether a network segment is a subnet or a hypernetwork

  1. First of all,
  • Look at the type of network segment (IP address class)
  • By default, A class A subnet mask has 8 bits (255.0.0.0), the bits of the class B subnet mask are 16 (255.255.0.0), the bits of the class C subnet mask are 24 (255.255.255.0)
  1. then
  • If the subnet mask has more bits than the default subnet mask, it is a subnet
  • If the subnet mask bits of the network segment are less than the default subnet mask bits, it is a hypernet

Example: 25.100.0.0/16 is A class A subnet. 200.100.0.0/16 is a class C hypernet.


For more articles in this series, please pay attention to wechat official account [1024 Planet].