Do I need the broadcast and network values in etc/network/interfaces?

7,595

All you need to calculate the network and broadcast addresses are an address somewhere in the network and the netmask, you don't need to know the gateway.

First, Take your network mask and convert to binary:

255.255.255.248 = 11111111 11111111 11111111 11111000

Next, Take the network address you know and do the same:

192.168.216.222 = 11000000 10101000 11011000 11011110

Now you can calculate the network and broadcast, for the network you carry out a logical AND between the known address and the netmask:

    255.255.255.248 = 11111111 11111111 11111111 11111000
    192.168.216.222 = 11000000 10101000 11011000 11011110
AND 192.168.216.216 = 11000000 10101000 11011000 11011000 = Network

For the broadcast, invert net netmask and carry out a logical OR between the known address and the inverted netmask:

    255.255.255.248 = 11111111 11111111 11111111 11111000
NOT 000.000.000.007 = 00000000 00000000 00000000 00000111
    192.168.216.222 = 11000000 10101000 11011000 11011110
OR  192.168.216.223 = 11000000 10101000 11011000 11011111

So, given an address of 192.168.216.222 and a netmask of 255.255.255.248, you can calculate the network as 192.168.216.216 and the broadcast as 192.168.216.223.

In your case, you say your ISP has given you 2 static IP's, this will in reality be 4 IP's, with a netmask of 255.255.255.252 it's just that two of those 4 IP's are taken up by your network and broadcast addresses.

Share:
7,595

Related videos on Youtube

mudasirahanger
Author by

mudasirahanger

I'm a software developer who relishes authoring Java and Python, hacking on Android and toying with AppEngine. I have a penchant for development and a passion for the business side of software. In between all the work, I contribute to a number of open-source projects, learn to master the art of cooking Asian cuisine and try to stay sane while learning to fly my Align Trex-600 Nitro Heli.

Updated on September 18, 2022

Comments

  • mudasirahanger
    mudasirahanger over 1 year

    My ISP has given me two static IPs, and I was just configuring the etc/network/interfaces file and saw that I need netmask, gateway, address, broadcast and network values.

    I only have the first three, so can I calculate the broadcast and network values from the other three?

    My network is currently working without them, but I'm wondering if it'll affect me in any way by leaving them off?

    • barlop
      barlop almost 13 years
      I suppose so. If your gateway is 192.168.1.0 and your mask is 255.255.0.0 then your network address would be 192.168.0.0 and your broadcast would be 192.168.255.255 Whereas if as is more likely, your gateway is 192.168.1.0 and your broadcast is 255.255.255.0 then your network address would be 192.168.1.0 and your broadcast address would be 192.168.1.255 Though i'm not into ubuntu so this may not be relevant.. but that's what I know from what I know of subnetting. You should be able to see the pattern and apply the principle to your network, and see if it works.
    • barlop
      barlop almost 13 years
      in the netmask, the 255s mark the network portion, the 0s mark the host portion. broadcast is host portion set to all 1s, so 255s(for any octet that is all 1s). if a netmask is not of the pattern 255(s) followed by 0(s), then it may be a little more complicated.
    • Keith
      Keith almost 13 years
      what is the IP and mask?
  • Matt Austin
    Matt Austin over 11 years
    The question asked if these are needed, not how to calculate them.
  • Mike Insch
    Mike Insch over 11 years
    Actually, the question did ask how to calculate them: "I only have the first three, so can I calculate the broadcast and network values from the other three?" ... Pretty clear, no?