Network Config - Custom Subnet Broadcast Address

Issues related to configuring your network
Post Reply
bangieff
Posts: 1
Joined: 2020/11/20 03:31:03

Network Config - Custom Subnet Broadcast Address

Post by bangieff » 2020/11/20 03:44:09

Hello,
I'm trying to configure a custom subnet as follows:

Network address: 192.168.0.8
Netmask: 255.255.255.240
Broadcast: 192.168.0.23

(I have another subnet 192.168.0.0 - 192.168.0.7 that I want to keep separate)

My network script for the network interface looks like that:
DEVICE=enp1s0
ONBOOT=yes
IPADDR=192.168.0.9
NETMASK=255.255.255.240
BROADCAST=192.168.0.23

However when I check the result, the broadcast address seems to be ignored (I expected to see 0.23, but it actually is 0.15):

enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 02:00:aa:0a:01:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.9/28 brd 192.168.0.15 scope global noprefixroute enp7s0
valid_lft forever preferred_lft forever

Could anyone tell me what am I missing?

Thanks!

User avatar
jlehtone
Posts: 3180
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Network Config - Custom Subnet Broadcast Address

Post by jlehtone » 2020/11/20 09:13:07

You have 192.168.0.9/28. That means:

Code: Select all

$ ipcalc -n -b -m 192.168.0.9/28
NETMASK=255.255.255.240
BROADCAST=192.168.0.15
NETWORK=192.168.0.0
The PREFIX 28 means that 28 bits of the address denote the network and last 4 bits identify the host.
4 bits => 2^4 values = 16 values.
Of those 16 values the first is the subnet's address and the last is the broadcast address.

The possible values for 28-bit network (i.e. when the last 4 bits are all 0) are:

Code: Select all

192.168.0.0
192.168.0.16
192.168.0.32
192.168.0.48

Code: Select all

$ ipcalc -n -b -m 192.168.0.9/29
NETMASK=255.255.255.248
BROADCAST=192.168.0.15
NETWORK=192.168.0.8
The possible values for 29-bit network (i.e. when the last 3 bits are all 0) are:

Code: Select all

192.168.0.0
192.168.0.8
192.168.0.16
192.168.0.24
192.168.0.32
192.168.0.40
The 192.168.0.0 - 192.168.0.7 must have PREFIX 29.

It is not possible to have 192.168.0.8 - 192.168.0.23 as a subnet.
You would have to have 192.168.0.8/29 and 192.168.0.16/29 to cover that range.

If you need 14 addresses (for machines), then you could choose 192.168.0.16/28 (the 192.168.0.16 - 192.168.0.31)
For example, set your address 192.168.0.17/28.


[EDIT]
If you want broadcast to be 192.168.0.23, then only possible subnets are
192.168.0.16/29 and 192.168.0.20/30. (The /31 has only two addresses and then bcast is 255.255.255.255.)

Note that it is best to set ADDRESS and PREFIX in the config.
The NETWORK, BROADCAST, and NETMASK are calculated from those.
If you don't set PREFIX, then NETMASK is used in calculations, but PREFIX is way less error-prone.

Post Reply

Return to “CentOS 8 - Networking Support”