Subnet mask and gateway

Subnet Mask
 

I. Introduction

The network connects the host, and the Internet is to connect a variety of different networks, so the Internet is a network of networks.

Understand the Internet has more than one network instead of only one network for understanding the subnet mask of great help.

In other words, the Internet is a network composed of many small, each network has many hosts, so that they form a hierarchical structure. IP address designed to take into account the characteristics of the level assigned address, IP addresses are each divided into two portions network number and host number, for operation in the addressing of the IP address.

We have also said, IP address is the network number and host number to mark the hosts on the network.

We put the same number of network hosts called the local network, not the same host network number is called the remote network host.

Local network host may communicate with the remote network host to communicate with each other must be passed forward data directly with each other through a local gateway (Gateway).

 

Second, the concept of the subnet mask

Subnet Mask (subnet mask) called network mask, the mask address, subnet mask, which is a bit used to indicate which IP address is identified by a subnet host resides, and the identification of which bits is the host of bit mask. Subnet mask can not exist alone, it must be combined with the IP address.

Its main role has two, one for shielding part of the IP address to distinguish the network ID and host ID, and shows that the IP address is on the LAN, or on a remote network. Second, for a large IP network is divided into small subnetworks.

Under Windows operating system, win + R to run cmd to open a command line, then enter ipconfig command to view the subnet mask and gateway of our own network host is located.

Here Insert Picture Description

 

Third, the subnet mask is composed

With the same IP address, subnet mask address by the length of a 32-bit binary number is. 32-bit IP address and subnet mask bits that correspond to 32, if the IP address by a network address, the subnet mask is 1, and 0 otherwise.

For example: 11111111.11111111.11111111.00000000

No. 24 is a length of the network (first three bytes), a length of 8 host ID (the last byte)

 

Fourth, the subnet mask representation

1. dotted decimal notation:

Decimal Binary conversion, each spaced by 8 dot

For example, the binary subnet mask 11111111.11111111.11111111.00000000 converted to decimal, that is 255.255.255.0

2. CIDR slash notation:

IP address / n

Examples 1: 192.168.1.100/24, which represents the subnet mask 255.255.255.0, and a binary representation of 11111111.11111111.11111111.00000000

Examples 2: 172.16.198.12/20, which is expressed as the subnet mask 255.255.240.0, expressed as a binary 11111111.11111111.11110000.00000000

Such a method commonly used carriers ISP assigns IP addresses to clients.

Cause n is a number of 1 to 32, represents the length of the subnet mask of the network number, the subnet number of hosts is determined by the number n = 2 ^ (32-n) -2 (minus the 2: Host bits are all the network address of the present network, indicates the host address of the broadcast network 1 is full, which is two special addresses, can not be used by the user) is zero.

 

Fifth, use the subnet mask of significance

While in the foregoing we have already mentioned two roles subnet mask, but I believe there will be a lot of people like me in the beginning contact with this concept, the role of the subnet mask in a very ignorant of b status. Now let's talk about why there must be such a thing subnet mask.

According to the previous description, we already know, the subnet mask can separate the network and host addresses in the IP address, so why separate it? Because the two hosts to communicate, we must first determine whether the segment in the same network, i.e. the network address are the same. If so, then the packet can be sent directly to the target host, otherwise you will need a gateway router forwards the packet to the destination.

That's Why I started to say, the network will be linked to the host, and the Internet will link different networks, the Internet is a kind of network of networks. Communication process between two hosts need to distinguish them are in the same network.

It can be appreciated that a simple:
 
A to host B with the host communication operation, A and B are each IP address and subnet mask of the host A, we observed the results obtained:
 
1, if the same result, then this two hosts are in the same network segment, so that a can find B's MAC address by broadcasting ARP, B a MAC address can also be found to implement normal communication.
 
2, if a different result, ARP broadcast will end at the local gateway, this time A will send packets B of the first distributed to local gateway, then to query the routing table based on the IP address of the host B, and then continue to pass data packets forwarding, delivery to the final destination B.

Not completely get to know? All right, then look at the following chart
Here Insert Picture Description
if there are so four hosts, according to our previous discussion, not difficult to see

Host A and Host B are in the same network, the network address is 192.168.1.0, 192.168.1.1 gateway address

C and D host while the host is in the same network, the network address is 192.168.2.0, the gateway address is 192.168.2.1

Therefore, A and B, C and D, can communicate directly with each other (each belong to the same network segment, without going through the router), but A and C, A and D, B and C, B and D are not the same therebetween segment, so they are to communicate via the local gateway, and the IP address of the router in accordance with each other, in the routing table look exactly matched to each other direct route of the IP address, then forwards gateway interface to interconnect the other side.

 

Sixth, the subnet mask classification

1. default subnet mask

I.e. undivided subnet network number corresponding bits are set to 1, the host numbers are set to zero.

IP address without making subnetting: No. + network host number

A Class Default Network Subnet Mask: 255.0.0.0, expressed as a CIDR / 8

Class B subnet mask Network Default: 255.255.0.0, expressed as a CIDR / 16

Class C network default subnet mask: 255.255.255.0, expressed as a CIDR / 24

2. Custom Subnet Mask

将一个网络划分子网后,把原本的主机号位置的一部分给了子网号,余下的才是给了子网的主机号。其形式如下:

做子网划分后的IP地址:网络号+子网号+子网主机号

如:192.168.1.100/25,其子网掩码表示:255.255.255.128

意思就是将192.168.1.0这个网段的主机位的最高1位划分为了子网。

 

六、子网掩码与 IP 地址的关系

上面我们也说到了,通过观察两个 IP 地址与子网掩码做与运算的结果是否相同,可以得出两个 IP地址是否在一个网络中的结论。所以子网掩码可以用来判断任意两台主机的IP地址是否属于同一网络,就是拿双方主机的IP地址和自己主机的子网掩码做与运算,如结果为同一网络,就可以直接通信。

 
网关
 

在上面介绍子网掩码时,曾多起提及网关,那么网关到底是什么呢?

网关实质上是一个网络通向其他网络的 IP 地址。

比如有网络 A 和网络 B,

网络 A 的 IP 地址范围为 192.168.1.1~192.168.1.254,子网掩码为 255.255.255.0
网络 B 的 IP 地址范围为 192.168.2.1~192.168.2.254,子网掩码为 255.255.255.0

在没有路由器的情况下,两个网络之间是不能进行 TCP/IP 通信的,即使是两个网络连接在同一台交换机(或集线器)上,TCP/IP 协议也会根据子网掩码 (255.255.255.0) 判定两个网络中的主机是否处在不同的网络里。而要实现这两个网络之间的通信,则必须通过网关。

如果网络 A 中的主机发现数据包的目的主机不在本地网络中,就把数据包转发给它自己的网关,再由网关转发给网络 B 的网关,网络 B 的网关再转发给网络 B 的某个主机。

So, just set the gateway IP address, TCP / IP protocol to communicate with each other between different networks. Then the IP address is the IP address which machine it? IP address of the gateway is the IP address of the device has a routing function, the most typical is the router, the device has a routing function IP address of the router interface is the address of the gateway, it can be any address in the network segment, but usually use the first available address on the network segment or the last available address , which is to try to avoid conflict and host address in the local network segment.

Guess you like

Origin blog.csdn.net/u013568373/article/details/92063406