I am using Beaglebone Black and I want to assign it a static IP address. I have gone through this tutorial and I know how to assign static IP. But question is, what is meant by these parameters;
iface enp0s25 inet static
address 192.168.0.11
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
address: an IP address at which we will receive IP packets. But what is functionality of netmask, network and broadcast ?
I want to connect my PC to BBB, in which range I can assign an IP to my PC ?
The netmask determines the portion of the "network" IP that defines the subnet.
Skip down past this whole part about IP addresses as HEX and binary if you already understand those things. Otherwise, start here:
Let's only consider IPv4 addresses to simplify the explanation. IP addresses are really decimal numbers. For example, when I ping (or dig) google.com, I see that the IP address resolves to 172.217.8.78 for me.
If I ping that address:
I get this response, just as expected:
Did you notice the "2899904590" at the beginning of the response? Keep that number in mind as we continue...
Convert each of the octets of the Google IP address to HEX. The equivalent of the decimal value, 172, is the HEX value, AC. Next, 217 is D9, 8 is 08, and 78 is 4E. The IP address as expressed in HEX is then ACD90878. If I convert this entire HEX number to decimal, I get 2899904590. That's the same number my ping command returned. Now if I do this:
I get the same response:
Quick Aside: you can also just ping the HEX value:
All version 4 IP addresses (IPv4) are just 4 HEX octets. Each HEX digit, 0 through F, is made up of 4 binary bits. An "octet" is 2 HEX digits, 00 through FF, made up of 8 (hence "octet") binary bits.
Now lets look at the netmask in your config file. The first 3 octets are all 255, which is HEX FF, which is binary 11111111. The last octet is 0, which is HEX 00, which is 00000000 binary. The mask defines which bits of the network IP address, 192.168.0.0, constitute the subnet. When the value of any mask bit is 1, then the corresponding network bit is part of the subnet definition. Since the bits of the first three octets of the netmask are all 1's, then the corresponding first 3 octets, 192.168.0, of the network IP are what defines the subnet. So the last octet of the network IP, 0, is not part of the subnet definition and is ignored. It can be set to any number between 0 and 255 but we conventionally set it to 0.
Addresses on this subnet must all begin with 192.168.0 since that is the part of the network IP that is masked. So IPs that are part of this subnet can range from 192.168.0.1 to 192.168.0.254 (0 and 255 are always reserved in the last octet)
A logical AND function is defined like this: binary 1 AND binary 1 = binary 1. Binary 1 AND binary 0 = binary 0. Binary 0 AND binary 1 = binary 0. Binary 0 AND binary 0 = binary 0 (so anything AND'ed with 0 is 0).
broadcast is the range of IPs that a broadcast message may be sent to. A broadcast message is a message sent to ALL IPs on a subnet, rather than to a specific IP. In this case, the available IPs must be on the subnet (192.168.0), and may be any binary number that is "AND'ed" with the last octet of the broadcase IP (255). Since 255 is 11111111 in binary, AND'ing each of those binary bits with each binary bit of any IP quadrant with a value from 00000000 to 11111111 (0 to 255) gives you back the value of the original IP quadrant. So the broadcast range is from 192.168.0.1 to 192.168.0.254.
Putting it all together: If an IP address AND'ed with the netmask = the network value AND'ed with the netmask, then the IP address is on the subnet. In this case:
and
so 192.168.0.99 is on the subnet - I can sent an IP packet to that address directly.
Conversely:
and
The 2 values are different which means that 192.168.88.99 is not on my subnet - I have to sent to that IP via the gateway.