Routing table interpretation - networking

Given the following table, where the network is using 8-bit host addresses, I am asked to compute the associated range of destination host addresses for every interface. Then I am also asked about the number of addresses in every range.
Table:
prefix match Interface
00 0
010 1
011 2
10 2
11 3
I determined that I am given the prefixes of the 8-bit binary IP's and the concluded that:
00000000 to 00111111 (0-63 in decimal) uses interface 0
addresses in the range = 2 to the power of (8 - the number of bits in the prefix, so 2) = 64
01000000 to 01011111 (64-95 in decimal) uses interface 1
addresses in range = 2^(8-3) = 32
01100000 to 10111111 (96-191 in decimal) uses interface 2
addresses in range = 2^5 = 32
11000000 and higer (192+ in decimal) uses interface 3
addresses in range = 2^5 = 32
Is my reasoning correct?

The number of addresses in each range is 2(8 - prefixlen). So if the prefix has 2 bits, the number of addresses is 26 = 64.

Related

How are the number of blocks for different classes in classful addressing determined in IPv4?

The following are the initial bits (out of 32) for the different classes of addresses in IPv4:
and the following are the number of blocks and block sizes respectively for each class:
For class A, I can see that the number of blocks is 2^7=128, and block size is 2^24=16777216. But I am unable to understand the following:
How the number of blocks in class B (16384), and in class C (2097152) are calculated.
How the size of blocks for classes D and E are calculated.
How can class D and class E have the same number of blocks and block size even though their initial four bits are not the same?
Please help me understand it as the calculation I used for class A is not working out for these.
Keep in mind: you have 32 bits overall.
Class A uses one bit of those 32; so 31 are left. And guess what ... 2^7 and 2^24 results in ... 31 bits left for block data.
Classes D and E ... both using four bits; so 28 bits are left.
2^28 is ... surprise 268.435.456
Now just go and check how many bits are left for the other classes!
The thing is: those first bits are mutually exclusive.
When the 32 bits start with 0, you know: class A; and so on.
netid = number of blocks
hostid = block size
IP address has total of 4 bytes and is divided into 5 classes depending on the initial bit(s).
In class A, one byte define the netid and 3 bytes defines the hostid.
In class B, two bytes define the netid and 2 bytes defines the hostid.
In class C, three bytes define the netid and 1 byte defines the hostid.
Hence;
for A
number of blocks = 2^7 as 1 bit is reserved for class identification. (0)
block size = 2^24
for B
number of blocks = 2^14 as 2 bits are reserved for class identification. (10)
block size = 2^16
for C
number of blocks = 2^21 as 3 bits are reserved for class identification. (110)
block size = 2^8
The system of netid and blockid is not applicable to class D and class E.
since it is of class B - first two byte are fixed.
and first bits of each block is not used (16-2).
so number of blocks are 2^14 =16384 and block size is no host id i.e=2^16=65535
similarly for class c
no. of blocks 2^(24-3)=2097152 and block size 2^8=256
Class A contains first byte of net id (255.0.0.0) and has a range 0-127 equals 128(127-0 +1).So total no blocks= 128.
Similarly
Class B contains 2 bytes of net it(255.255.0.0) and has a range 128-191 equals 64(191-128 +1).So total no of blocks= 64 * 255 (of 2nd byte) = 16,384.
And
Class C contains 3 bytes of net id(255.255.255.0) and range 192-223 equals 32(223-192 +1).So total no of blocks = 32 * 255 (of 2nd byte) * 255 (of 3rd byte)= 2,097,152
Class D is assigned block=1 (since it uses multicast addresses instead of uni-cast).
Class E is assigned block=1 (because no partitioning into block and hosts as reserved for future use).
In IPv4 addressing, the IP address is 32 bits long.
The first n bits, which are all 1s are known as network bits
The remaining 32-n bits which are all 0s are known as host bits.
Further for each class, there is a fixed prefix which is found in each address belonging to that class,
Class A: 0
Class B: 10
Class C: 110
Class D: 1110
Class E: 1111
Host Bits for each class are
Class A: 8
Class B: 16
Class C: 24
Class D: 32
Class E: 32
For calculating the number of blocks and block sizes, the following formula can be used,
Number of Blocks = 2^(number of Hostbits- length of prefix)
Block Size = 2^(32- number of Hostbits)
Class D & E are exceptions to this, you could just remember their values

How does 192,168,1,2,7,138 convert to port 1930 on IP address 192.168.1.2

How do i deduce the port and ip from a number that FTP throws?
For example 192,168,1,2,7,138 converts to 1930 on IP address 192.168.1.2?
What is the logic behind?
The first four numbers indicate client IP, the second two numbers indicate the client port number. It's a hex to dec conversion.
16^2 * 7 + 138 = 1930
The first number stands for 3-rd and 4-th bit of a hex number (port number), the second is for 1-st and 2-nd bit of a hex number.
So we have
7 = 07 in hex
and
138 = 8A in hex
Altogether we have
078A in hex which is 1930
or you can just skip that and convert only the first number to dec which is for 3-d and 4-th bit because of that "shift". The second number is already converted.

Using Hexadecimal to represent a 7 bit code

My computer uses ASCII, American Standard Code for Information Exchange.
It is my understanding that this uses a 7 bit code to represent all the letters, symbols, and numbers needed for the english language.
It is my understanding that these 7 bits can be represented with hexadecimal codes.
I thought that hexadecimal needed 8 bits. 4 bits per number.
Can some one explain to me how the hexadecimal system can be used to represent the codes in the 7 bit ASCII system.
Thanks in advance.
Hexadecimal numbers don't need eight bits, each hex digit can represent four bits but there's no upper limit, since you can just use more digits:
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
For representing seven-bit values, you can just use the lower half of the eight-bit hex numbers, 0x00 through 0x7f.
That gives you the binary numbers 0000000 through 1111111.
With 7 bits you can represent every number from 0 to 2^7 = 127 (decimal) = 7f (hexadecimal).
Hexadecimal doesn't need 7 bits, it is just another way to write numbers.
You can combine any combination of up to 4 bits into one hexadecimal character.
1 bit: 0 to 1
2 bits: 0 to 3
3 bits: 0 to 7
4 bits: 0 to F
For 7 bits you need 2 hex digit, one coding 3 bits and the other 4 bits so you get a code of 00 to 7F.
Or you use 8 bits, but the most significant bit is always 0.

Determining if two IP adresses are on same subnet - is it leading or trailing 0s get dropped from IP address?

I understand if two IP addresses are AND'd with a subnet mask if the result is the same then they are on the same network. If the result is different then they are on different networks. My question is, when given an IP address omitting some 0s where do the extra 0s get placed?
For example if the subnet mask is 255 . 128 . 0 . 0 , and you have IP 126 . 1 . 0 . 10 and IP 126 . 127 . 0 . 1 if you just blindly AND the IPs with the subnet mask you get different results even though they are on the same network.
Does 126.1.0.10 become 126.100.000.100 or 126.001.000.100?
EDIT after reading replies:
255128000000 AND 126001000010 = 1085496376*32* but 255128000000 AND 126127000001 = 1085276323*84*
Am I missing something?
IPv4 addreses are written as four ordinary decimal numbers (each fitting into a byte) separated by dots.
The ordinary decimal number 1 is "one", which can also be written 001. However 100 is a different number, namely "a hundred".
The AND operation is always a bitwise AND, so to understand it you must first see how the dotted-decimal address and netmask corresponds to a raw binary 32-bit address:
126 . 127 . 0 . 1
01111110 01111111 00000000 00000001
255 . 128 . 0 . 0
AND 11111111 10000000 00000000 00000000
-----------------------------------------------
01111110 00000000 00000000 00000000
126 . 0 . 0 . 0
So 126.127.0.1 with netmask 255.128.0.0 is in subnet 126.0.0.0/9
In software one usually stores IPv4 addresses in a single 32-bit variable -- so 126.127.0.1 is 01111110011111110000000000000001 binary (which also encodes 2122252289 decimal, except that nobody ever cares what the decimal value of a 32-bit IP address is), and it is converted to dotted-decimal only when it needs to be shown to human users. This representation is what glglgl decribes as multiplying by 256 several times.
If you also have the netmask in a 32-bit variable (11111111100000000000000000000000 binary or 4286578688 decimal), you can AND them in a single machine instruction to get the network address 01111110000000000000000000000000.
You are completely missing something: You don't just concat your digits together, because AND works on binary level.
So either you process the IPv4 addresses byte-wise, or you transform them into a decimal number, but not with factor 1000, but with factor 256.
This is to say, instead of doing
((126 * 1000 + 1) * 1000 + 0) * 1000 + 10 = 126001000010
you should do
((126 * 256 + 1) * 256 + 0) * 256 + 10 = 2113994762
. If you apply this to the other numbers, you should succeed.
Alternatively, you could AND together the 4 numbers separately, so
255 & 126 = 126 (in both cases), 128 & (1 resp. 127) = 0, 0 & (anything) = 0, 0 & (anything) = 0.
So you get 126.0.0.0 for both, making them belong to the same subnet.
Despite the fact that it's a rather odd question, I'll try answering your specific query:
The number '1' in that second octet is really a number 1, and therefore it's '001', not '100'.
That said, your example should have worked, so I suspect there's something wrong with your implementation. You should not need to worry about padding or anything. These are numbers, and bitwise-AND should "just work".
You might want to provide more detail about what is going wrong.

Number of hosts in a subnet

Does anyone know how many host bits are needed to guarantee that a subnet could have 9 usable hosts?
I was thinking about around 4, but I'm not sure. Can some shed some light on this?
Two subnet addresses (all-ones and all-zeros) can't be used to indicate a host, so with N bits you get up to (2**N - 2) usable hosts. So, for 9 hosts, 4 bits is correct: it would do up to 14, but 3 bits would do only 6 hosts.
Here are networks that meet the requirement 192.168.1.0 /28
Mask:255.255.255.240 Host/Net - 14
Network Broadcast
192.168.1.0 192.168.1.15
192.168.1.16 192.168.1.31
192.168.1.32 192.168.1.47
192.168.1.48 192.168.1.63
192.168.1.64 192.168.1.79
192.168.1.80 192.168.1.95
192.168.1.96 192.168.1.111
192.168.1.112 192.168.1.127
192.168.1.128 192.168.1.143
192.168.1.144 192.168.1.159
192.168.1.160 192.168.1.175
192.168.1.176 192.168.1.191
192.168.1.192 192.168.1.207
192.168.1.208 192.168.1.223
192.168.1.224 192.168.1.239
192.168.1.240 192.168.1.255
We can calculate number of host bit by 2 methods:
We require 9 usable hosts
So converting 9 into binary we have 00001001.
Now,
128 64 32 16 8 4 2 1
0 0 0 0 1 0 0 1
count from right to left now, till the last on bit
so into 00001001 we have last on bit at 1
get the borrow bit till last on bit, that is 4
now for if we are calculating for class c , than the default subnet mask is
255.255.255.00000000
Now for calculation we off the bits where as for network we on the bit
so for host off 4 bits from right to left and on the rest left bits.
here 4 is the borrow bit that was calculated earlier
255.255.255.11110000
now taking only the last bit of subnet mask,
128 64 32 16 8 4 2 1
1 1 1 1 0 0 0 0
the increment value is 16
Note: increment value is calculated as last on bit from left to right.
so we will have a network of 128+64+32+16= 240
for class 'C' we have 192.168.1.0/28 or 192.168.1.0 255.255.255.240
number of host: 192.168.1.0
192.168.1.16
this is the first network, here we have 192.168.1.0 as network IP and 192.168.1.15 as broadcast IP
so from 192.168.1.1 to 192.168.1.14 are the usable IP or host that claculates to 14 usable host.
2nd method
we have the formula of claculating the host as 2^(n)-2
here n are off bits
from the 1st method we have number of off bit is 4
so 2^4 - 2= 16-2 = 14
hence we will get a slot of 14 usable host from which we can use 9
NOTE: The network class taken above is just an example which does not have any effect on increment bit calculation.Similarly we can calculate for class A and B

Resources