Network address planning: what are hosts, routes, and gateways

picture

Internet equipment

Big Liu's computer A and Xiaomei's computer B can be connected through a network cable to form a network. When A sends data, B can receive it. On the contrary, A can receive all the data sent by B.

picture

switch

Before long, Pharaoh's computer C, Ali's computer D, and Minmin's computer E also joined the network. It is impossible to connect only using network cables, and the problem that cannot be solved can be solved in a layered way.

picture

So there is a layer 2 network device switch , which provides network interconnection functions.

picture

The MAC address of each computer network card  is different. When the computer sends data, the data header carries the MAC address of the network card, and the MAC address is used to identify different computers. The switch can identify the MAC address of the data header to distinguish different computers.

picture

In addition to being able to identify different computers, the switch also needs to find the switch port to which the computer is connected , in order to smoothly send data from the corresponding port. The switch adds the learned device MAC address and switch port number to  the MAC address table through the self-learning mechanism , and forwards data according to the MAC address table .

picture

router

With South Korea's Bangbang Computer F, America's Sam's Computer G, India's Sansan's Computer H, and so on, the scale of the network is getting bigger and bigger. Switches need to record more and more MAC address tables, and more and more switches are needed. However, the capacity and performance of the switch is limited, the MAC address table cannot record the MAC addresses and corresponding port numbers of computers all over the world, and the MAC address table is too large to quickly find the corresponding MAC address entries.

picture

The upper limit of the switch and the problem that the switch cannot handle can be solved in a layered way.

Schematic diagram of network layer processing

So there is a three-tier network device router , which can connect the world's networks.

picture


 router

The network connection in the LAN can use a switch , for example, a network within a company or a network within a campus is connected through a switch. LANs in different areas are interconnected using routers , so how to distinguish different network areas? And how to forward data across network regions?

The MAC address is burned into the network card, also called the hardware address, which can identify a certain device, but cannot be used to identify a certain network area. In order to distinguish different network areas, IP addresses come into play. An IP address is composed of a network number and a host number. The network number can identify a network area. Hosts with the same network number are located in the same network area, that is, in the same network segment. Different network areas use different network numbers. The host number identifies different hosts in the same network segment, and duplicate host numbers are not allowed in the same network segment. By setting the network number and host number in the entire network, it is guaranteed that the IP address of each host will not appear repeatedly, that is, the IP address is unique.

 IP address

A router has multiple ports, which are respectively connected to different network areas, and the IP addresses and network numbers of different network areas are different . It identifies the network number of the destination IP address , and then forwards data according to the routing table .

picture

 Forwarding principle

Network address planning

IP address

The IP address is composed of 32-bit binary numbers, and is expressed in decimal numbers for the convenience of viewing and recording.

IP address representation method

Conversion of common binary numbers to decimal numbers

picture

 Conversion Table

The classified addresses assigned to hosts are  Class A , Class B , and Class C. Classified addresses use fixed network digits, Class A has  8-  digit network numbers, Class B has  16  -digit network numbers, and Class C has  24  -digit network numbers. The network number can be identified by judging the classified address type (one of class A, B, and C) , and the network number can also be identified through the subnet mask .

picture

Category address

Category address

The first bit of a class A address starts with 0, and there are 7 variable network bits, that is, 128 class A addresses. Among them, 0 and 127 belong to special addresses , and there are 128 - 2 = available Class A addresses  126 .

There are 24 variable host bits, that is, 16777216 host addresses. Among them, the host bits are all 0 and the host bits are all 1, which are the network segment address and the broadcast address respectively , which cannot be allocated to the host, and each class A address can have 16777216 - 2 = host addresses  16777214 .

The range of class A addresses is  1.0.0.0 ~ 126.255.255.255 .

The subnet mask of a class A address is  255.0.0.0 , and can also be written  /8 .

picture

The first two digits of a class B address start with 10, and there are 14 variable network bits, that is, 16384 class B addresses. Among them, 128.0 and 191.255 are special addresses , and there are 16384 - 2 = available Class B addresses  16382 .

There are 16 variable host bits, that is, 65536 host addresses. Among them, network segment addresses and broadcast addresses cannot be assigned to hosts, and each class B address can have 65536 - 2 = host addresses  65534 .

The range of class B addresses is  128.0.0.0 ~ 191.255.255.255 .

The subnet mask of a class B address is  255.255.0.0 , and can also be written  /16 .

Class B address

The first three digits of a Class C address start with 110, and there are 21 variable network digits, that is, 2097152 Class C addresses. Among them, 192.0.0 and 223.255.255 are special addresses , and there are 2097152 - 2 = available Class C addresses  2097150 .

There are 8 variable host bits, that is, 256 host addresses. Among them, network segment addresses and broadcast addresses cannot be assigned to hosts, and each class C address can have 256 - 2 = host addresses  254 .

The range of class C addresses is  192.0.0.0 ~ 223.255.255.255 .

The class C address subnet mask is  255.255.255.0 , and can also be written  /24 .

picture

 class address

The network segment address is the address where the host number is all 0, which means a certain network segment, for example: the network segment address 192.168.10.0/24 means all addresses with the network number 192.168.10.

The broadcast address is an address whose host number is all 1s, an address that sends data packets to all hosts in the same network segment, for example: the broadcast address of the network segment address 192.168.10.0/24 is 192.168.10.255.

broadcast address

Classified addresses reserve several private network addresses that can be used freely .

Class A private addresses are 10.0.0.0

The class B private network address range is 172.16.0.0 ~ 172.31.0.0

The class C private network address range is 192.168.0.0 ~ 192.168.255.0

picture

private address range

give a chestnut

Class A private network address 10.10.10.10

It can be deduced that the network segment address of 10.10.10.10 is 10.0.0.0/8, the subnet mask is 255.0.0.0, the broadcast address is 10.255.255.255, the first available address is 10.0.0.1, and the last available address is 10.255 .255.254, the available address range is 10.0.0.1 ~ 10.255.255.254.

Class B private network address 172.20.20.20

It can be deduced that the network segment address of 172.20.20.20 is 172.20.0.0/16, the subnet mask is 255.255.0.0, the broadcast address is 172.20.255.255, the first available address is 172.20.0.1, and the last available address is 172.20 .255.254, the available address range is 172.20.0.1 ~ 172.20.255.254.

Class C private network address 192.168.30.30

It can be deduced that the network segment address of 192.168.30.30 is 192.168.30.0/24, the subnet mask is 255.255.255.0, the broadcast address is 192.168.30.255, the first available address is 192.168.30.1, and the last available address is 192.168 .30.254, the available address range is 192.168.30.1 ~ 192.168.30.254.

picture

subnet mask

The subnet mask must be used together with the IP address. The subnet mask is also composed of 32-bit binary numbers. The network bit is 1, and the host bit is 0. Perform an AND (AND) operation on the subnet mask and the IP address to obtain the network segment address of the IP address. In other words, as many bits of the network number as there are in the IP address, the number of bits in the subnet mask is 1, and the rest are 0.

subnet mask

The subnet mask can be represented as a decimal number or as a slash notation .

picture

 Two representation methods of subnet mask

Calculate the network segment address according to the IP address and subnet mask, first convert the IP address and subnet mask into a binary number, then perform an AND operation on the IP address and the subnet mask binary number one by one, and then convert the result into In decimal, it is the network segment address .

picture

Calculate network segment address

AND (AND) operation

The binary number of the IP address and subnet mask, calculated bit by bit. The operation result is 1 only when both the IP address and the mask are 1. In other cases, the calculation result is 0.

picture

 AND operation

classless address

Classification addresses use a fixed number of network bits, and the assignable host IP addresses are also fixed. But when actually using the network, the number of IP addresses required varies.

For example: a company has 500 computers and needs to assign 500 IP addresses. If a Class C address is allocated, the number of available IP addresses for a Class C address is 254, which is not enough for use. If a class B address is allocated, the number of available IP addresses for a class B address is 65534, which will cause a lot of waste of IP addresses.

Another example: if a family has 2 computers that need to go online, it would be a waste to allocate a class C address, but there is no address with a range smaller than class C.

To solve the problem of address waste,  CIDR (Classless Inter-Domain Routing) and  VLSM (Variable Length Subnet Mask) technologies can be used.

VLSM  can divide A, B and C addresses into networks of various types and sizes, and the number of available host addresses can be flexibly changed in size. The process of dividing classified addresses is also called subnetting .

picture

CIDR  can group multiple classified addresses together to generate a larger network segment to reduce the number of routing entries in the router and reduce the burden on the router. The process of merging classified addresses is also called supernet merging .

picture

The network segment address after subnetting or supernet merging is no longer a fixed number of network digits. This kind of network segment address with variable network digits is also called a classless address . Classless addresses can only identify the network number through the subnet mask .

picture

subnetting

Subnetting starts from the leftmost part of the host bit of the IP address, divides the host bit into the network bit, and obtains multiple subnet addresses. The part where the host bit becomes the network bit is called the subnet number. The number of divided subnets is equal to 2 to the Nth power, and N is equal to the number of digits of the subnet number.

subnet number

That is, every time a host bit is changed into a network bit, one network segment address becomes two subnet addresses, and the number of subnet addresses is only half of the original network segment address.

picture

give a chestnut

A school has 150 computers and three computer rooms, each with 50 computers. Use the private address 192.168.0.0/24 to assign a network segment address to each computer room.

Network planning steps:

  1. There are 50 computers in each computer room, and the host bits of the subnet address are calculated to be 6 bits.

    picture

    Computer bit
  2. Calculate the network bits of the subnet address , ie 32 - host bits = 26 bits.

  3. Use the private network address 192.168.0.0/24 to allocate three subnet addresses whose host bits are all 26 bits. The subnet number has 2 bits, so it can be divided into 4 subnet addresses with the same size.

    picture

    According to the order of the subnet numbers from small to large, assign 3 subnet addresses to the computer room. That is, three subnet addresses of 192.168.0.0/26, 192.168.0.64/26, and 192.168.0.128/26 are assigned.

  4. Subnet segment information
  5. According to the number of required  IP addresses , divide the subnets in descending order. First calculate that the subnet host bits required by the marketing department with 100 people are 7 bits.

    Computer bit
  6. Calculate the network bits for the subnet address required by the marketing department , ie 32 - host bits = 25 bits.

  7. Use the private network address 192.168.100.0/24 to assign a subnet address whose first host bit is 25 bits, that is, 192.168.100.0/25.

  8. another chestnut

    A company has 157 people, 100 people in the marketing department, 50 people in the technical department, 4 people in the administrative department, and 3 people in the financial department. Each person has an office computer. Use the private address 192.168.100.0/24 to divide the network address for each department separately.

    Network planning steps:

    picture

    Under the premise of ensuring that it is not duplicated with the first subnet address , use the subnet address with the smallest unassigned subnet value to calculate the second subnet address to be allocated. That is, use 192.168.100.128/25 to assign the second subnet address to the technical department (50 people). Repeat steps 1 to 3 to calculate that the host bit of the second subnet is 6 bits, the network bit is 26 bits, and the address of the second subnet is 192.168.100.128/26.


     

    picture

  9. Under the premise of ensuring that the addresses of the previous two subnets are not duplicated, use the subnet address with the smallest unassigned subnet value to calculate the third subnet address to be allocated. That is, use 192.168.100.192/26 to assign the third subnet address to the Administration Department (4 persons). Repeat steps 1 ~ 3 to calculate that the host bit of the third subnet is 3 bits, the network bit is 29 bits, and the address of the third subnet is 192.168.100.192/29.

  10. By analogy, calculate the fourth subnet address for the finance department (3 people). It is obtained that the host bit of the fourth subnet is 3 bits, the network bit is 29 bits, and the address of the fourth subnet is 192.168.100.200/29.

    picture

    supernet merger

  11.  Contrary to subnetting, combining small networks into one large network is called supernetting.

picture

192.168.3.64/26 and 192.168.3.128/26 cannot be combined.

Determine whether network segments can be merged

When the subnet mask moves one bit to the left, the network numbers are different and cannot be merged;

picture

 The network number is different

When the subnet mask moves to the left by two bits, the network number is the same, but four network segments are merged, not 192.168.3.64/26 and 192.168.3.128/26 are merged.

picture

picture

More network segments are merged

Conclusion : If the subnet mask is shifted one bit to the left, and the network numbers are the same, two network segments can be merged; if the subnet mask is shifted two bits to the left, and the network numbers are the same, four network segments can be merged; if the subnet mask is shifted three bits to the left, eight network segments can be merged. part. And so on.

picture

 Segment merge

static route

When the router receives a data packet, it will identify the network number of the destination IP address to query the routing entries in the routing table, and judge which interface should forward the data packet based on the longest matching routing entry . Only when there is a matching routing entry in the routing table, the data will be sent, and if there is no matching routing entry, it will be discarded directly.

picture

routing entry

routing table

The routing table is composed of routing entries, and routing entries include destination address, next hop, and outgoing interface.

picture

routing table

The destination address (Destination / Mask) indicates the destination network segment address or destination IP address. The destination address can be the network segment address directly connected to the router interface, or the network segment address or IP address on other routers.

NextHop / Interface (NextHop / Interface) indicates the interface IP address of the next-hop device when forwarding the data packet of the destination address, or the interface from which the data packet is forwarded.

The protocol type (Proto / Protocol abbreviation) indicates how to obtain routing entries. There are three ways in total.

  • Direct route: The route entry directly connected to the router, as long as the interface is configured with an IP address and the interface status is normal, the corresponding direct route will be automatically generated.

    direct route
  • Static routing: Routing entries manually added through commands are static routing.

  • picture

    Dynamic routing: Routing entries dynamically learned from neighboring routers through routing protocols.

    picture


     

  • dynamic routing
  • picture

    Priority (abbreviation for Pre / Preference) indicates that there are multiple routing entries to the same destination address. According to the type of routing entry, the routing entry with the highest priority is selected and added to the routing table.

    Default Route Priority Table

    The smaller the route priority value , the higher the priority of this type of route .

    picture

    Forward by priority

    Path cost ( Cost ) means that multiple routing entries to the same destination address are learned through the same routing type, and the routing entry with the smallest path cost is selected and added to the routing table.

Guess you like

Origin blog.csdn.net/qq_35789269/article/details/132240021
Recommended