11 · Introducing the TCP_IP Internet Layer, IPv4 Addressing, and Subnets認識 TCP/IP 網際網路層、IPv4 定址與子網路

Subnet Masks子網路遮罩

A subnet mask is a 32-bit number that describes which portion of an IPv4 address refers to the network ID and which part refers to the host ID.

子網路遮罩是一個 32 位元的數字,用來描述 IPv4 位址中哪一部分屬於網路 ID,哪一部分屬於主機 ID。

The subnet mask is configured on a device along with the IPv4 address.

子網路遮罩與 IPv4 位址一同設定在裝置上。

If a subnet mask has a binary 1 in a bit position, the corresponding bit in the address is part of the network ID. If a subnet mask has a binary 0 in a bit position, the corresponding bit in the address is part of the host ID.

如果子網路遮罩某個位元位置為二進位 1,位址中對應的位元就屬於網路 ID;如果子網路遮罩某個位元位置為二進位 0,位址中對應的位元就屬於主機 ID。

The figure represents an IPv4 address separated into a network and a host part. In the example, the network part ends on the octet boundary, which coincides with what you learned about IPv4 address class boundaries. The address in the figure belongs to class B, where the first two octets (16 bits) indicate the network part, and the remaining two octets represent the host part. Therefore, you create the subnet mask by setting the first 16 bits of the subnet mask to binary 1 and the last 16 bits of the subnet mask to zero.

此圖顯示一個 IPv4 位址被分成網路與主機兩部分。在此範例中,網路部分結束於八位元組邊界,這與你先前學到的 IPv4 位址類別邊界一致。圖中的位址屬於 B 類,前兩個八位元組(16 位元)表示網路部分,其餘兩個八位元組表示主機部分。因此,你將子網路遮罩的前 16 位元設為二進位 1,後 16 位元設為 0,藉此建立子網路遮罩。

Notice the prefix /16; it is another way of expressing the subnet mask and it matches the number of network bits that are set to binary 1 in the subnet mask.

請注意前綴 /16,這是表示子網路遮罩的另一種方式,其數值對應子網路遮罩中設為二進位 1 的網路位元數。

Networks are not always assigned the same prefix. Depending on the number of hosts on the network, the prefix that is assigned may be different. Having a different prefix number changes the host range and broadcast address for each network.

網路不一定都被指派相同的前綴。依網路上的主機數量而定,所指派的前綴可能不同。不同的前綴數會改變每個網路的主機範圍與廣播位址。

Calculating the Network Address

計算網路位址

An IPv4 address that has binary zeros in all the host bit positions is reserved for the network address. The main purpose of the subnet mask is to identify the network address of a host, which is crucial for routing purposes. Based on the network address, the host can identify whether a packet's destination address is within the same network or not.

所有主機位元皆為二進位 0 的 IPv4 位址保留作為網路位址使用。子網路遮罩的主要用途是識別主機的網路位址,這對繞送而言至關重要。根據網路位址,主機可以判斷封包的目的位址是否位於同一網路內。

Given an IPv4 address and a subnet mask, you can calculate the network address by using the AND function between the binary representation of the IPv4 address and the binary representation of the subnet mask.

已知一個 IPv4 位址與子網路遮罩,你可以透過將 IPv4 位址的二進位表示法與子網路遮罩的二進位表示法進行 AND 運算,來計算網路位址。

The calculation is performed bit-by-bit following these rules:

此計算依照以下規則逐位元進行:

  • 0 AND 0 = 00 AND 0 = 0
  • 1 AND 0 = 01 AND 0 = 0
  • 0 AND 1 = 00 AND 1 = 0
  • 1 AND 1 = 11 AND 1 = 1

The result of the AND operation is the network address of the network on which the device resides; this is also called the network prefix. You can see that in the network address, the network part is the same as it is in the original IPv4 address, while the host bits are all set to zero.

AND 運算的結果就是該裝置所在網路的網路位址,也稱為網路前綴。你可以看到在網路位址中,網路部分與原始 IPv4 位址相同,而主機位元則全部設為 0。

Usually, you will use the decimal form of the network address, so you need to remember the binary to decimal conversion. Look at the figure to remember the conversion process.

通常你會使用網路位址的十進位形式,因此需要記住二進位轉十進位的換算方法。請參閱圖示以記住轉換過程。

You have a host 192.168.50.2/24. What is its network address?你有一台主機 192.168.50.2/24,它的網路位址是什麼?
Given the host 10.110.100.24/16 IP address. What is the range of IP addresses of the network that this host belongs to?已知主機 10.110.100.24/16 的 IP 位址,此主機所屬網路的 IP 位址範圍為何?