Tổng quan
Mạng con (subnet hay subnetwork) là một khái niệm rất phổ biến. Ttrong môi trường mạng, đó là khái niệm phân đoạn hệ thống mạng thành những bộ phận nhỏ có những địa chỉ riêng của nó. Để tạo ra các subnet, một số bit nằm trong phần host của địa chỉ IP sẽ được mượn để tạo ra các subnet. Bài học sẽ mô tả về chức năng của subnet và cách tính toán các subnet.
Nhiệm vụ
Cung cấp khả năng tính toán địa chỉ subnet thông qua các nhiệm vụ sau:
Mô tả mục tiêu và chức năng của subnet
Mô tả tiến trình tính toán những địa chỉ subnet và host khả dụng
Mô tả làm cách cách thiết bị đầu cuối sử dụng subnet mask để định vị trí thiết bị đích
Mô tả cách router sử dụng subnet mask để định tuyến cho dữ liệu đến đích
Mô tả cơ cấu vận hành của subnet mask
Áp dụng nguyên tắc vận hành này vào các lớp địa chỉ A, B, C
Quản trị mạng thông thường sẽ chia nhỏ hệ thống mạng, đặc biệt là trong môi trường mạng lớn, thành nhiều subnet khác nhau nhằm tạo ra khả năng phân địa chỉ một các linh động. Chủ dề này mô tả mục tiêu, chức năng của subnet và cách định ra kế hoạch về địa chỉ.
Một công ty chiếm hũu 3 tầng lầu của một toàn nhà sẽ có hệ thống mạng được chia theo các tầng, trên mỗi tầng lại được chia nhỏ thành từng văn phòng nhỏ. Suy nghĩ một toà nhà này như một hệ thống mạng với 3 tầng là 3 subnet và mỗi văn phòng như một host trong hệ thống mạng này.
Subnet sẽ phân đoạn các host trong hệ thống mạng. Nếu không có khái niệm subnet, hệ thống mạng chỉ là một mô hình phẳng. Một mô hình phẳng như vậy sẽ làm bảng định tuyến của chúng ta ngắn hơn và chỉ dựa trên địa chỉ MAC lớp 2 để phân phối dữ liệu. MAC là dạng địa chỉ không phân cấp và khi hệ thống mạng càng lớn, băng thông của hệ thống mạng sẽ ít dần và trở nên kém hiệu quả.
Những bất lợi của một mạng phẳng:
Tất cả các thiết bị sẽ chia sẻ cùng một băng thông
Tất cả các thiết bị chia sẻ cùng một vùng broadcast
Rất khó để áp đặt các chính sách bảo mật bởi vì hầu như không tồn tại một sự ngăn cách nào giữa các thiết bị
Trong hệ thống mạng Ethernet gắn kết với nhau bởi HUB, mỗi host trong môi trường mạng này sẽ thấy tất cả các gói dữ liệu khác trên mạng. Trong môi trường gắn qua hệ thống chuyển mạch (switched-connected network) các host sẽ thấy gói dữ liệu broadcast. Trong trường hợp dữ liệu đưa ra lớn, khả năng va chạm là hoàn toàn có thề khi các thiết bị gởi dữ liệu ra đồng thời. Thiết bị phát hiện được va đụng sẽ phải ngưng truyền và sẽ cố gắng truyền lại trong một khoản thời gian ngẫu nhiên sau đó. Về phía người dùng, họ chỉ có thể cảm nhận được tiến trình này qua sự chậm đi của hệ thống mạng. Router có thể được sử dụng trong trường hơp này để chia cách mạng thành những những subnet khác nhau.
Những lợi điểm của việc subnet hệ thống mạng được thể hiện như dưới:
Hệ thống mạng càng nhỏ càng dễ quản lý và dễ dàng gắn kết với các nhu cầu chức năng cũng như phạm vi địa lý
Tổng lưu lượng hệ thống mạng sẽ được giảm xuống do đó sẽ làm tăng khả năng hoạt động của hệ thống
Bạn có thể dễ dàng áp dụng các chính sách bảo mật mạng tại những điểm liên kết nối giữa các subnet thay vì phải dặt trên toàn bộ hệ thống mạng
Trong môi trường tồn tại nhiều hệ thống mạng, mỗi subnet có thể được gắn vào Internet qua một router như hình trên. Trong ví dụ này, hệ thống mạng được chia nhỏ thành nhiều subnet. Chi tiết bên trong môi trường mạng và làm cách nào hệ thống mang được chia thành nhiều subnet sẽ trở nên không quan trọng đối với cách nhìn từ hệ thống mạng khác.
Giá trị subnet mask xác định phần quan trọng trong địa chỉ IP, tầm quan trọng ở đây chính là ranh giới giữa phần network và phần host. Giá trị này sẽ ảnh hưởng đến quá trình định tuyến trong hệ thống mạng.
Địa chỉ 2 cấp và 3 cấp
Khi phương pháp xác định địa chỉ và các lớp địa chỉ IPv4 được phát triển, địa chỉ 2 lớp (bao gồm network và host) thoạt đầu tỏ ra khá hiệu quả. Mỗi lớp địa chỉ (A, B và C) có giá trị subnet mask mặc định đi liền, và do subnet mask được định nghĩa trước, do vậy không cần phải bắt buộc cấu hình giá trị này.
Khi số lượng các thiết bị gắn kết vào mạng ngày càng tăng, vấn đề không hiệu quả trong việc sử dụng địa chỉ mạng ngày càng trở nên rõ ràng hơn. Để giải quyết vấn đề này, cấp địa chỉ thứ 3, bao gồm subnet, đã được phát triển.
Một địa chỉ subnet bao gồm phần mạng đầy đủ của lớp mạng nguyên gốc cộng thêm phần subnet. Đây cũng được xem như là phần mở rộng tiền tố mạng. Vùng subnet và vùng host được tạo ra từ phần host cũ của lớp mạng ban đầu. Để tạo ra các địa chỉ subnet, chúng ta mượn những bit từ vùng host nguyên gốc và phân định chúng thành những bit thuộc vùng subnet.
Tuy nhiên, subnet sẽ không vận hành được nếu không có cách xác định phần địa chỉ nào giờ đây sẽ thuộc về phần mạng và phần nào là phần host. Do vậy, subnet mask cần phải được cấu hình rõ ràng.
Quá trình tạo subnet
Địa chỉ subnet được tạo ra bằng cách lấy đi những bit của phần host thuộc về các lớp A, B hay C. Thông thường quản trị mạng sẽ phân định các địa chỉ subnet một cách cục bộ. Và cũng như địa chỉ IP, mỗi subnet phải là duy nhất.
Khi tạo ra các subnet, một số địa chỉ IP sẽ bị mất đi, do vậy phải lường trước được tỷ lệ địa chỉ bị mất đi khi tạo ra các subnet. Phương pháp được sử dụng để tính toán số lượng của các subnet là lũy thừa của 2. Khi lấy đi một số bit từ vùng host, cần phẩi chú ý về số lượng subnet mới được tạo ra. Khi mượn 2 bit ta có thể tạo ra 4 subnet (2^2 = 4). Mỗi khi có một bit được mượn từ vùng host, số lượng subnet sẽ được tăng lên bằng với lũy thừa 2 số lượng bit mượn được đồng thời số lượng host cũng giảm đi theo công thức lũy thừa 2 như vậy. Một số ví dụ được đưa ra như sau:
Sử dụng 3 bit cho vùng subnet sẽ tạo ra 8 subnet (2^3 = 8)
Sử dụng 4 bit cho vùng subnet sẽ tạo ra 8 subnet (2^4 = 16)
Sử dụng 5 bit cho vùng subnet sẽ tạo ra 8 subnet (2^5 = 32)
Sử dụng 6 bit cho vùng subnet sẽ tạo ra 8 subnet (2^6 = 64)
Nói tóm lại, công thức sau đây được sử dụng để tính toán số lượng subnet
Số lượng subnet = 2^s (s là số lượng số bit làm subnet)
Tính số lượng host cho địa chỉ lớp C
Mỗi khi 1 bit được mượn từ vùng host, vùng host lại bị giảm đi 1 bit có thể được sử dụng cho các host và số lượng địa chỉ host dùng để gán cho các host bị giảm đi theo công thức lũy thừa 2.
Như ví dụ trên, xét một địa chỉ lớp C trong đó tất cả 8 bit trong octet cuối được sử dụng cho phần xác định host. Do vậy, có khoản 256 địa chỉ có thể. Trên thực tế, giá trị thực sự để có thể phân định cho các host là 254 (256 -2 địa chỉ để dành).
Hãy tường tượng rắng địa chỉ lớp C được chia thành các subnet, nếu 2 bit được mượn từ 8 bit mặc định ban đầu, kích cỡ vùng host sẽ giảm xuống còn 6 bit. Sự kết hợp của tất cả các giá trị bit 0 và bit 1 xảy ra ở 6 bit còn lại sẽ tạo ra các địa chỉ để gán cho host trong mỗi subnet đó. Số lượng này, ban đầu là 256 giờ giảm xuống còn 64. Giá trị thực tế lúc này lại chỉ giảm còn 62 (64 -2 địa chỉ để dành)
Trong cùng một mạng lớp C, nếu 3 bit được mượn, kích cỡ vùng host sẽ giảm còn 5 bit và số lượng địa chỉ tổng cộng cho các host là 32 (2^5). Trong đó chỉ có 30 địa chỉ sử dụng được (32-2). Số lượng địa chỉ host có thể sử dụng được để gán cho subnet thì liên quan đến số lượng subnet được tạo ra. Ví dụ trong địa chỉ mạng lớp C số lượng subnet được tạo ra là 8 thì mỗi subnet bao gồm khoản 30 địa chỉ host
Computing Hosts for a Class B Subnetwork
Now consider a Class B network address, in which 16 bits are used for the network ID and 16
bits are used for the host ID. Therefore, there are 65,536 (216) possible addresses available to
assign to hosts (65,534 usable addresses, after subtracting the two addresses, the broadcast and
the subnet addresses, that cannot be used).
Now, imagine that this Class B network is divided into subnets. If 2 bits are borrowed from the
default 16-bit host field, the size of the host field decreases to 14 bits. All possible
combinations of 0s and 1s that could occur in the remaining 14 bits produce a total number of
possible hosts that could be assigned in each subnet. Thus, the number of hosts assigned to each
subnet is now 16,382.
In the same Class B network, if 3 bits are borrowed, the size of the host field decreases to 13
bits and the total number of assignable hosts for each subnet decreases to 8,192 (213). The
number of usable host numbers decreases to 8,190 (8,192 – 2). In a Class B network, for
example, the usable subnets created are 6 (8 – 2), each having 8,190 (8,192 – 2) usable host
addresses.
Computing Hosts for a Class A Subnetwork
Finally, consider a Class A network address, in which 8 bits are used for the network ID and 24
bits are used for the host ID. Therefore, there are 16,777,216 (224) possible addresses available
to assign to hosts (16,777,214 usable addresses, after subtracting the two addresses, the
broadcast and the subnet addresses, that cannot be used).
Now, imagine that this Class A network is divided into subnets. If 6 bits are borrowed from the
default 24-bit host field, the size of the host field decreases to 18 bits. All possible
combinations of 0s and 1s that could occur in the remaining 18 bits produce a total number of
possible hosts that could be assigned in each subnet. This number is now 262,142, while it was
formerly 16,777,216. The number of usable hosts decreases to 262,140 (262,142 – 2).
How End Systems Use Subnet Masks
The end system uses the subnet mask to compare the network portion of the local network
address with the destination network address of the packet to be sent. This topic describes the
process that end systems follow in using subnet masks.
Before an end system can send a packet to its destination, it must first determine if the
destination address is on the local network. If it is, the end system will use the Address
Resolution Protocol (ARP) process to bind the IP address to the MAC address. If it is not, the
packet must be forwarded to the default gateway router for transmission to the destination
network.
How Routers Use Subnet Masks
The subnet mask identifies the network-significant part of an IP address. Routers need this
information to determine how to get a packet to the desired destination. This topic describes
how routers use subnet masks.
All routers have routing tables. Depending on the location of the router in the network
hierarchy, the table may be small and simple or large and complex.
The router populates the routing table with the network-significant part of all known networks,
to compare the destination network addresses of packets that need to be forwarded. If the
network is not directly attached to the router, the router stores the address of the next-hop router
to which the packet should be forwarded. For routers to function without the need to store all
destination networks in their tables, they use a default route to which packets not matching any
entry in the route table are forwarded.
Procedure for Routing with Subnet Masks
Step Action Notes
1. Host A determines that the destination
network requires the use of its default
gateway router (Router A).
Router A has a route to the destination network
10.3.1.0 and forwards the packet to Router B
through the indicated interface.
2. Because the 10.3.1.0/24 network is
directly connected to Router B interface
fa0/2, Router B will use ARP to determine
the MAC address of Host B.
When configuring routers, each interface is connected to a different network or subnet segment.
An available host address from each different network or subnet must be assigned to the
interface of the router that connects to that network or subnet (see figure). In this example, the
router has two Ethernet interfaces. The interface that is connected to the 172.16.2.0 subnetwork
is assigned the IP address of 172.16.2.1, and the other interface that is connected to the
172.16.3.0 subnetwork is assigned the IP address of 172.16.3.1. All of the attached hosts need
to have their addresses within the range of the subnet. Any host configured with an address
outside of this would not be reachable.
Mechanics of Subnet Mask Operation
You have learned why subnet masks exist and how end systems and routers use subnet masks.
This topic describes how subnet masks are created and how they work.
Although subnet masks use the same format as IP addresses, they are not IP addresses
themselves. Each subnet mask is 32 bits long, divided into four octets, and is usually
represented in the dotted decimal notation like IP addresses. In their binary representation,
subnet masks have all 1s in the network and subnetwork portions and all 0s in the host portion.
Octet Values of a Subnet Mask
There are only eight valid subnet mask values per octet. The subnet field always immediately
follows the network number. That is, the borrowed bits must be the first n bits, starting with the
most significant bit (MSB) of the default host field, where n is the desired size of the new
subnet field (see figure). The subnet mask is the tool used by the router to determine which bits
are routing (network and subnet) bits and which bits are host bits.
If all 8 bits in any octet are binary 1s, the octet has a decimal equivalent of 255. This is why
there is a “255” in a decimal representation of a default subnet. In Class A, the default subnet
address is 255.0.0.0 or 11111111.00000000.00000000.00000000. If the three highest order bits
from the next highest order host octet are borrowed, they add up to 224. This translates to
255.224.0.0, or 11111111.11100000.00000000.00000000.
With IP addressing, the subnet mask identifies the addressing information that is necessary to
send packets toward their final destinations. The subnet mask identifies which bits within the IP
address are the network and subnet bits.
The figure shows the default subnet masks for Class A, Class B, and Class C addresses. The
subnet mask itself is indicated with 1s in the binary notation for the mask, with all other bits
indicated as 0s.
Applying Subnet Mask Operation
Most network administrators work with existing networks, complete with subnets and subnet
masks in place. Network administrators need to be able to determine, from an existing IP
address, which part of the address is the network and which part is the subnet. Applying the
subnet mask operation provides this information. This topic describes how to apply the subnet
mask operation.
The procedure described in the figure explains how to select the number of subnets you need
for a particular network and then apply a mask to implement subnets.
Procedure for Implementing Subnets
Step Action Example
1. Determine the IP address for your network
as assigned by the registry authority.
Assume you are assigned a Class B address of
172.16.0.0.
2. Based on your organization and
administrative requirements and structure,
determine the number of subnets required
for the network. Be sure to plan for future
growth.
Assume that you are managing a worldwide
network in 25 countries. Each country has an
average of four locations. Therefore, you will
need 100 subnets.
3. Based on the address class and the
number of subnets you selected,
determine the number of bits you need to
borrow from the host ID.
To create 100 subnets, you need to borrow 7
bits (27 – 2 = 126).
Step Action Example
4. Determine the binary and decimal values
of the subnet mask you select.
For a Class B address with 16 bits in the
network ID, when you borrow 7 bits, the mask
is /23.
Binary value of the mask:
11111111.11111111.11111110.00000000
Decimal value of the mask: 255.255.254.0
5. Apply the subnet mask for the network IP address to determine the subnet and host
addresses. You will also determine the network and broadcast addresses for each subnet.
6. Assign subnet addresses to specific subnets on your network.
Determining the Network Addressing Scheme
When working in a classful networking environment that uses fixed-length subnet masks, you
can determine the entire network addressing scheme based on a single IP address and its
corresponding subnet mask.
The figure shows the first three of eight steps used to determine the subnet of a given IP
address. In this example, the IP address and subnet mask are as follows:
Network address: 192.168.221.37
Subnet mask: 255.255.255.248
The figure shows the last five of eight steps used to determine the subnet of a given IP address.
After converting the addresses from binary to decimal, the addresses for the subnets are as
follows:
First subnet address: 192.168.221.32
First host address: 192.168.221.33
Last host address: 192.168.221.38
Broadcast address: 192.168.221.39
Next subnet address: 192.168.221.40
Notice that the range of the address block, including the subnet address and directed-broadcast
address in this example, is from 192.168.221.32 through 192.168.221.39, which includes eight
addresses. The address block is the same size as the number of host bits (2h = 23 = 8).
Class C Example
Given the address of 192.168.5.139 and knowing that the subnet mask is 255.255.255.224, the
subnet number is 11111111.11111111.11111111.11100000, or /27.
Steps to Determine Class C Subnet Addresses
Step Description Example
1. Write down the octet that is being split in binary. 10001011
2. Write the mask or classful prefix length in binary. 11100000
3. Draw a line to delineate the significant bits in the
assigned IP address.
Cross out the mask so you can view the
significant bits in the IP address.
100 | 01011
111 | 00000
4. Copy the significant bits four times.
5. In the first line, define the network address by
placing 0s in the remaining host bits.
6. In the last line, define the directed-broadcast
address by placing 1s in the host bits.
7. In the middle lines, define the first and last host ID
for this subnet.
100 00000 (first subnet address)
100 00001 (first host address)
100 11110 (last host address)
100 11111 (broadcast address)
8. Increment the subnet bits by 1 to determine the
next subnet address.
Repeat Steps 4 through 8 for all subnets.
101 00000 (next subnet address)
Subnet Addresses Table
Subnet
No.
Subnet ID Host Range Broadcast Address
All 0s 192.168.5.0 192.168.5.1 to 192.168.5.30 192.168.5.31
1 192.168.5.32 192.168.5.33 to 192.168.5.62 192.168.5.63
2 192.168.5.64 192.168.5.65 to 192.168.5.94 192.168.5.95
3 192.168.5.96 192.168.5.97 to 192.168.5.126 192.168.5.127
4 192.168.5.128 192.168.5.129 to 192.168.5.158 192.168.5.159
5 192.168.5.160 192.168.5.161 to 192.168.5.190 192.168.5.191
6 192.168.5.192 192.168.5.193 to 192.168.5.222 192.168.5.223
All 1s 192.168.5.224 192.168.5.225 to 192.168.5.254 192.168.5.255
Class B Example
Given the address of 172.16.139.46 and knowing that the subnet mask is 255.255.240.0, or /20,
you can determine the subnet and host addresses for this network.
Steps to Determine Class B Subnet Addresses
Step Description Example
1. Write down the octet that is being split in binary. 10001011
2. Write the mask or classful prefix length in binary. 11110000
3. Draw a line to delineate the significant bits in the
assigned IP address.
Cross out the mask so you can view the
significant bits in the IP address.
1000 | 1011
1111 | 0000
4. Copy the significant bits four times.
5. In the first line, define the network address by
placing 0s in the remaining host bits.
6. In the last line, define the directed-broadcast
address by placing 1s in the host bits.
7. In the middle lines, define the first and last host ID
for this subnet.
1000 0000 (first subnet address)
1000 0001 (first host address)
1000 1110 (last host address)
1000 1111 (broadcast address)
8. Increment the subnet bits by 1 to determine the
next subnet address.
Repeat Steps 4 through 8 for all subnets.
1001 0000 (next subnet address)
Subnet Addresses Table
Subnet
No.
Subnet ID Host Range Broadcast
All 0s 172.16.0.0 172.16.0.1 to 172.16.15.254 172.16.15.255
1 172.16.16.0 172.16.16.1 to 172.16.31.254 172.16.31.255
2 172.16.32.0 172.16.32.1 to 172.16.47.254 172.16.47.255
……….
13 172.16.208.0 172.16.208.1 to 172.16.223.254 172.16.223.255
14 172.16.224.0 172.16.224.1 to 172.16.239.254 172.16.239.255
All 1s 172.16.240.0 172.16.240.1 to 172.16.255.254 172.16.255.255
Class A Example
Given the address of 10.172.16.211 and knowing that the subnet mask is /18, you can
determine the subnet and host addresses for this network.
Steps to Determine Class A Subnet Addresses
Step Description Example
1. Write down the octet that is being split in binary. 00010000
2. Write the mask or classful prefix length in binary. 11000000
3. Draw a line to delineate the significant bits in the
assigned IP address.
Cross out the mask so you can view the
significant bits in the IP address.
00 | 010000
11 | 000000
4. Copy the significant bits four times.
5. In the first line, define the network address by
placing 0s in the remaining host bits.
6. In the last line, define the directed-broadcast
address by placing 1s in the host bits.
7. In the middle lines, define the first and last host ID
for this subnet.
00 000000 (first subnet address)
00 000001 (first host address)
00 111110 (last host address)
00 111111 (broadcast address)
8. Increment the subnet bits by 1 to determine the
next subnet address.
Repeat Steps 4 through 8 for all subnets.
01 000000 (next subnet address)
Subnet Addresses Table
Subnet
No.
Subnet ID Host Range Broadcast
All 0s 10.0.0.0 10.0.0.1 to 10.0.63.254 10.0.63.255
1 10.0.64.0 10.0.64.1 to 10.0.127.254 10.0.127.255
2 10.0.128.0 10.0.128.1 to 10.0.191.254 10.0.191.255
……….
1021 10.255.64.0 10.255.64.1 to 10.255.127.254 10.255.127.255
1022 10.255.128.0 10.255.128.1 to 10.255.191.254 10.255.191.255
All 1s 10.255.192.0 10.255.192.1 to 10.255.255.254 10.255.255.255