LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   question about IP address and subnet mask (https://www.linuxquestions.org/questions/linux-networking-3/question-about-ip-address-and-subnet-mask-541106/)

2007fld 03-27-2007 04:00 PM

question about IP address and subnet mask
 
I have a question about IP address and subnet mask.

My understanding is each IP address has netid part and hostid part. The netid part is used for routing efficiently.

For example: an IP address 192.25.4.5 with a netmask 255.255.255.0, (ie /24 ) has a subnet number of 192.25.4.0, and there can be 2^8-2 = 254 hosts in this system.

But, for the same IP address, if I want to divide the 254 hosts into 8 subnets, what should I do? Change the subnet mask? How do I know they are in different subnets?

Furthermore, I read in a book said:
“When you divide a class C address 192.25.4.0 into eight subnets, you get a subnet mask of 255.255.255.224 (27 1s). The eight resultant network are 192.25.4.0, 192.25.4.32, 192.25.4.64, 192.25.4.96, 192.25.4.128, 192.25.4.160, 192.25.4.192, and 192.25.4.224”

I understand 224 is 27 1s. But I don’t know where 224 comes from. Also, I thought hosts in a subnet has a range of IP address. For exmaple, 192.25.4.1-192.25.4.31 are in the first subnet. But how can the routers between the subnets know?

I’m really confused with these concepts. Please advise.
Thanks!

chakkerz 03-27-2007 04:17 PM

8 subnets, so sections of 32 each 2*2*2*2*2 or 2^5 -> 32-5 = 27

OR alternatively 256(total addresses)-32(desired addresses) = 224
That said if you want 15 addresses you can't go 256-15 = 241 -> 255.255.255.241

Or if you have a CIDR table handy

CIDR Dec Netmask Hex Netmask No of IP addresses
/27 255.255.255.224 0xFFFFFFE0 32

so your networks are:
192.25.4.0/27 which is the exact same as 192.25.4.0/255.255.255.224 *
192.25.4.32/27
192.25.4.64/27
192.25.4.96/27
...128/27
...160/27
...192/27
...224/27

* well not exactly the same - hosts.allow understands the long form, but not the short form. On that note, don't specify individual IPs in your hosts.allow (or deny) as 195.25.4.3/255.255.255.255 cause that will be ignored/not matched.

Each of those CIDR notations are a range, not a single address. Or they are a network address block, which is a range. The routers between the subnet can know by a number of means: Vlans are one popular mean though i'm not sure what deeper explanation you might need there.

in a Vlan setup your system tags each packet so the router knows that the source is part of a vlan, and based on this can route it. Unless you have a complex setup though, vlans might not be the way to go. If you use a firewall you can restrict access of your network blocks to each other in the router and not bring vlan's into it. Vlans offer enhanced security (as potential targets are not part of the Vlan so they won't respond to the packets as said target knows to ignore them), but this can be subverted by the router due to making a port tagged or untagged. but again, this gets complex and unless you need to know there is little point in telling you, and i'm sure wikipedia will do a better job.

2007fld 03-27-2007 05:03 PM

so for 254 hosts divided into 8 subnets, it is 32 hosts on each subnet, that is 5 bits for hostid. Is this how you get the first 32?

chakkerz 03-28-2007 07:36 AM

well CIDR is based on 2 to the power of 32 = 4294967296
this is the same as 256*256*256*256 ... each section of the netmask can be 0 - 255 (or 0x00 to 0xFF) in other words 256 values, so total potential number of IP addresses is that long number with 4 at the start.

CIDR does not care about the number of hosts, in fact it completely ignores that aspect of it. It can be used to denote a range of IPs which are all hosts (say in a firewall) or a subsection of a network. In the case of the network subset, it may or may not include all sorts of non host usable IPs such as Base IP, Gateway, Broadcast, HSRP interfaces, Router Management IP etc.

so really you have not 254 hosts but 256 IPs. 256 / 32 = 8. Or 8 equal sized network segments out of 256 potential IP addresses gives 32.

CIDR uses a starting point of /32 meaning one IP address only, each step towards 0 means double the IPs, so /31 is 2; /30 is 4; /29 is 8; /28 is 16; and /27 is 32.

An easier way to derive this, rather than counting backwards, is to take the 32 (number of IPs) and work out 2 to the power of what = 32. (2^x=32) so the value in question (x) is 5. To then work out what you CIDR mask for this would be is 32 (base CIDR value of one IP) and reduce that by x -> 27 so /27 (CIDR) gives 32 IP addresses.

So in other words, if you are doing your network split instead of 254 host usable IP address; you end up with 240 host usable IP addresses only.

oh, and one other things, say we have 192.168.5.16/27 - that would mean 192.168.5.16-192.168.5.48; but depending on the place you use it, it may mean something else; for instance most routers will interpret that as meaning you want the /27 block of the 192.168.5.0/24 address range, which will contain .16 and interpret that as 192.168.5.0/27 instead;

If you used this in a firewall on the other hand, it might be legal and mean 16-48 instead (i'm really not sure, i've not come across that, but firewalls generally interpret it as a range, and don't give the bounds special meaning as a router would). To be safe that this is interpreted as the range, you'd probably have a group of 192.168.5.16/28 and 192.168.5.32/28 which would not confuse a firewall, but would mean something completely different to a router.

I realize that this is all a bit confusing and probably more info than you wanted, but just know it's based on Y = 2 to the power of X; and then 32 - X is the notation that gives you Y addresses. As long as you know X or Y you'll be fine.

tredegar 03-28-2007 11:00 AM

.. This stuff always ends up making my head hurt!

2007fld: There's a good tutorial here:

http://www.yolinux.com/TUTORIALS/Lin...etworking.html


All times are GMT -5. The time now is 06:09 PM.