24. Subnetting
For IP 192.168.0.1 the following is submitted.
The default subnet is what is automatically assigned. Notice that the default subnet has 255 in the same octets as networks for a Class C. For a Class B the default subnet is 255.255.0.0, for a Class A the default would be 255.0.0.0. Using subnets allows you to tell the computer how to handle IPs, so you can't divide the number of networks into smaller, more manageable chunks.
To get a subnet do the following:
Decide what bit subnet you are dealing with by looking at the subnet mask. To decide this
lets look at an example:
Address - 192.168.0.60 Subnet Mask- 255.255.255.248
This is a Class C address, but notice that the subnet mask is not the default of 255.255.255.0, it is 255.255.255.248. The 4th octet is a 5 bit number: (look below)
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
There are 5 ones in the number 248, so another name for this subnet mask is 192.168.0.60/29. When you add the other octets which have 8 ones each, to the 5 bit number you get 29 (11111111.11111111.11111111.11111000, is what 255.255.255.248 would look like in binary, to get the bit notation of this address just add all the one's (1) together to see how many you get, which in this case there are 29 one's.) This type of notation is not widely used, but it is used to determine the broadcast address (broadcast address is discussed later.)
Now lets discuss subnet masks a little more in-depth. You need to put the subnet mask into binary. Use the last number that is not zero into binary, so for our example of 192.168.0.60 with a subnet mask of 255.255.255.248 we will use the 248 to transfer into binary (if our example was 10.2.1.0 with a subnet mask of 255.248.0.0 we would still use the 248). After we put the subnet mask number into binary, we need to put the number in the IP address occupying the same octet that we used for the subnet mask, which in our example is 60. (if our example was 10.2.1.0 with a subnet of 255.248.0.0 then the IP address number to transfer into binary would be 2). So lets put our numbers into binary in the table below:
Comparing the Subnet Mask Values and Finding the Actual Subnet Value |
||||||||
Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
60 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
248 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
Below we will put a 1 where there are two ones vertically, if there is a zero and a one or two zeros then we will put a zero |
||||||||
Subnet | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
So you then add the binary value from the result, which in our case is 32+16+8=56. This will be your actual subnet. The following will be the subnet for this address:
IP Address | Subnet Mask | Subnet |
192.168.0.60 | 255.255.255.248 | 192.168.0.56 |
To figure out the broadcast (a broadcast is the address that you want every host to see), you look at the last bit that is active. So for our sample IP address of 192.168.0.60 with a subnet of 255.255.255.248, the last active octet is 248, which makes this a 5 bit subnet mask. The last active bit in a 5 bit subnet mask of 248 is 8. How did we determine that? Lets see:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | =248 |
As you can see the last active bit is the bit in position 8 (you read these from left to right). Next you add that number (8 in our example) to the subnet (in our case the 4th octet which was the number 56 (look above, the subnet is 192.168.0.56). So add 56 (from the subnet number) to 8 (the last active bit in the subnet mask) which gives you 64. From this you go down 1 for the broadcast address which gives you 192.168.0.63 as the broadcast address. (Another way is to add the unused bits, from a 5 bit address the unused ones are the last 3 (look at the above table, you will see that the 4,2 and 1 have zeros) then you add this to the subnet. So in our example 4+2+1=6, add this 6 to the 56 from our subnet, which gives you 63, so your broadcast is 192.168.0.63
So lets look at another example, to further illustrate this. Heres a hypothetical situation:
Address | Subnet Mask | Class | Subnet | Broadcast |
192.168.193.6/21 | 255.255.248.0 | C | 192.168.192.0 | 192.168.199.255 |
(remember that this is a Class C address so the Network portion of the address is 192.168.193 and the host part is 6 by default)
Again we are dealing with a 5 bit subnet mask, and the last number in the network portion (use the subnet mask to determine the last number, in our case the class C default and the subnet mask have the same number of network octets). Look at the below table to see how we get our numbers:
Binary |
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | Total |
248 (from last octet number of subnet mask) | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 248 |
193 (from last network number of IP address) | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 193 |
Active bits for determining subnet | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 192 |
Look at the last active number of the subnet mask and add it to the subnet, then subtract 1 to determine the broadcast | X | 8 + 192 - 1 | |||||||
199 |
/etc/inet/netmasks shows netmasks, which shows you authorized networks, an example of this output looks like this:
192.168.200.0 | 255.255.255.240 |
192.168.0.1 | 255.255.255.0 |
Note: The 192.168.200.0 portion is the authorized network, and the 255.255.255.240 is the subnet.
To set up your own IP address:
Go to Chapter 23
Go to Index
Go to Chapter 25