Please help me understand IP4 address and subnet mask and subnetting

You'd use a different subnet mask to increase the amount of addresses available in the subnet.

But I think, as suggested in the first reply you got, you should go do some web searches to find some reading you can do about IPv4 addressing and subnetting. It's not really OpenWRT specific at this point.

3 Likes

The first address in any subnet is the network address. It cannot be assigned to a host. In a /24 network (subnet mask 255.255.255.0), the first address is .0, which is the network itself.
If you are referring to a whole network, it would look like 192.168.1.0/24 (whereas an individual host might be 192.168.1.5/24).

The last address is the broadcast address - all hosts listen to this broadcast traffic (kind of like the PA system in a commercial/educational environment). It also cannot be assigned to a host. In the /24 network space, that broadcast address would be .255.

If you use a different subnet size, the network address and broadcast address will be different, but always at the bottom and top of the ranges, respectively.

3 Likes

For a given network, the first IP is reserverdedthe network ID and the last IP is reserved for the broadcast address. So for the network of 192.168.1.0 and subnet mask of 255.255.255.0, the valid IPs are actually 192.168.1.1 to 192.168.1.254. You can specify your DHCP pool within that range, and it's a good practice to leave some IPs outside that pool for static IPs, so the DHCP server doesn't tu to assign them to clients.

For static IPs not static leases, to be precise.

1 Like

You change the subnet mask. 255.255.254.0 with network 192.168.0.0 will give you valid IPs from 192.168.0.1 to 192.168.1.254.

1 Like

Well I would say, that range is for static IP or static Leases. It's cleaner not to overlap the DHCP pool with the static leases from my point of view

No, it's perfectly fine[1] to have a static lease in the DHCP pool. I do it that way acutally.

It's the static IPs that should never overlap with the DHCP range.


[1] In some implementations, including OpenWrt's

1 Like

IPv4 is not complicated and with enough effort you can work it out on your own with some basic google searches. IPv6 however is a little more complicated and I would suggest you learn IPv4 first. But to get you started you should at least know there are 3 main sets of IPv4 addresses you should be aware of....

  1. Public addresses -> anything not reserved or localhost which basically means the internet
  2. Reserved addresses -> 192.x.x.x , 172.x.x.x, 10.x.x.x etc...
  3. your localhost address -> 127.0.0.1

When configuring OpenWRT (or any other device connected to your network for that matter) you will be working with the reserved and localhost addresses mostly. The only time I can think of when you will be working with public addresses is when you are setting the DNS server addresses.

The netmask is simple: it sets which part of the IP address is your network ID so the packets can route if there is a gateway available.

As faser1 mentioned, the lease range is for Dynamically assigned IP Addresses. What happens is, if you need a device (say a server) to keep it's IP Address constantly, you'll assign it a static IP outside of the lease range. If you remove the static IP address from your list, then when the lease expires on the device, it will get a dynamic one from the range.

The DHCP server handles all of this. The only difference is, if it's a static IP, it always goes to the device with the MAC Address that matches the list. If it's a dynamic IP, then it's first come first serve for each IP address in the range.

1 Like

Let's look at a "Class C" address, as it's the easiest to work with and the principles apply to every other class. By default, a Class C (192.168.0.0 for example) is a /24 address. That means that of the 32 bits, 24 are turned on (meaning they are part of the network portion of the IP Address). The bits are grouped in 8's. So, 255.255.255.0 would be 11111111.11111111.11111111.00000000 (the 1 means it's part of the network portion).

So, by default, you have 256 possible addresses in the /24. The catch is the .0 and .255 are reserved, so you can't use them. So, you have 254 hosts available. For every bit that you turn on to the right of the last 1, you cut the number of hosts in half. For every bit you turn off to the left of the last 1, you double the number of hosts. I'll show you an example.
192.168.0.0 = 255.255.255.0 = 11111111.11111111.11111111.00000000 = 254 hosts (0 and 255 are reserved)
192.168.0.0 = 255.255.255.128 = 11111111.11111111.11111111.10000000 = 126 hosts (0 and 127 are reserved)
192.168.0.0 = 255.255.255.192 = 11111111.11111111.11111111.11000000 = 62 hosts (0 and 63 are reserved).

Going the other way:
192.168.0.0 = 255.255.252.0 = 11111111.11111111.11111110.00000000 = 510 hosts (0.0 and 1.255 are reserved).
192.168.0.0 = 255.255.248.0 = 11111111.11111111.11111100.00000000 = 1,022 hosts (0.0 and 3.255 are reserved).

Typically you won't go to the left (the last two examples). If you're going to do that, then use a Class B and subnet it like you would the Class C. All you care about is the octet that is being chopped up (in Class C, it's the last octet in a Class B, it's the next one over).

Looking at an octet, it looks something like this (I'm spacing it out so you know what numbers go where--or I would if the spacing matched up in the editor)

128 64 32 16 8 4 2 1 = 256
1 1 1 1 1 1 1 1 = 256

Hopefully this helps a little.
Patrick.

1 Like

Subnet makes for these are 255.255.254.0 and 255.255.252.0, respectively.