Thursday, June 30, 2011

IPv4/IPv6 subnetmask calculation

Well, you all know about calculation network masks and wildcard masks in the IPv4 world. But how to do it in IPv6? IPv6 has a binary numbering system, but IPv6 is hexadecimal based and now we have 340282366920938463463374607431768211456 IP addresses. So that’s the number you will find on the internet. My calculator says just 3,402408308e+38. I multiplied FFFF*FFFF*FFFF*FFFF*FFFF*FFFF*FFFF*FFFF in hexadecimal format and converted it afterwords into decimal.
With IPv4 there are a maximum of 255*255*255*255 with is 4228250625. Well you see the difference? I read it’s about 1000 addressess for each square centimeter of the earth IPv6 has.
IPv4 has 32 bits into his entire IP address. This means, there are 32 places where there can be a 1 or 0 in place.
So a binary numbers for 192.168.10.1 looks like:
11000000 => 192 => 2^7+2^6
10101000 => 168 => 2^7+2^5+2^3
00001010 => 10 => 2^3+2^1
00000001 => 1 => 2^0
And you have 192.168.29.2:
11000000 => 192 => 2^7+2^6
10101000 => 168 => 2^7+2^5+2^3
00011101 => 29 => 2^4+2^3+2^2+2^0
00000001 => 2 => 2^1
To calculate the host and network part you will “and” one ip with the subnet mask. If the mask is 255.255.192.0:
11111111 => 255
11111111 => 255
11000000 => 192
00000000 => 0
Anding the ip address with the mask:
11000000 = 192
11111111 = 255
—————
11000000 = 192
10101000 = 168
11111111 = 255
—————-
10101000 = 168
00011101 = 29
11000000 = 192
—————-
00000000 = 0
00000001 = 2
00000000 = 0
—————–
00000000 = 0
So here you will have 192.168.0.0 for the network address. As for the mask 255.255.192.0
there will be the last 14 bits for hosts on the network.
11111111.11111111.11000000.00000000
The network ranges are from 192.168.0.0 – 192.168.192.0
So you have 2 bits for the network and 14 for hosts.
11111111.11111111.00000000.00000000 = 192.168.0.0
11111111.11111111.01000000.00000000 = 192.168.64.0
11111111.11111111.10000000.00000000 = 192.168.128.0
11111111.11111111.11000000.00000000 = 192.168.192.0
Where the network address is for example:
11111111.11111111.01000000.00000000 = 192.168.64.0
The broadcast address is:
11111111.11111111.0111111.11111111 = 192.168.127.255
The first and the last usable host in the network is:
11111111.11111111.01000000.00000001 = 192.168.64.1
11111111.11111111.01111111.1111110 = 192.168.127.254
So now you have the IPv6 addressing and how to compute a netmask matching your needs. I did not found anything on the internet about it, and so i write i down myself. Well that’s not absolute true. Look at the links provided…
The network mask /64 will be:
FFFF:FFFF:FFFF:FFFF:0000:0000:0000:0000 => /64
FFFF:FFFF:FFFF:FFFF:F000:0000:0000:0000 => /68
FFFF:FFFF:FFFF:FFFF:FF00:0000:0000:0000 => /72
FFFF:FFFF:FFFF:FFFF:FFFF:0000:0000:0000 => /80
FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:0000:0000 => /96
FFFF:FFFF:FFFF:FFFF:F000:0000:0000:0000 => /68
FFFF:FFFF:FFFF:FFFF:C000:0000:0000:0000 => /69
FFFF:FFFF:FFFF:FFFF:8000:0000:0000:0000 => /70
FFFF:FFFF:FFFF:FFFF:4000:0000:0000:0000 => /65
The main thing which is important to understand is, that the quadrupples are divided into two 8 bit parts. That means, if you have the FF00 this is devided into FF which is 11111111 and 00 which is 00000000. So each /64 is half of all networks. And the next smaller unsubnetted network begins with /80 and so on, every 16 bits.
Each network “bit” represents a 4 bit value. So plus a value of 1 means you will habe 2^4=16 more networks.
So the smalles subnetmask for example these IPv6 networks:
0001:2001:00EF:0222:0003:0001:EEEA:00AA
0001:2001:00EF:0222:0003:0001:EEEA:001A
——————————————————–
FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFF:FFC0 => /121
0001:2001:00EF:0222:0003:0001:EEEA:00AA
0001:2001:00EF:0222:0003:0001:EEEA:001A
——————————————————–
FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFF:FFC0 => /121
0001:2001:00EF:0012::/64
0001:2001:00EF:0022::/64
——————————————————–
FFFF:FFFF:FFFF:FF40 => /82
Example 1:
To calculate an access-list mask for two IPv4 addresses that matches both addresses you AND these addresses:
For example:
192.168.1.10.1 and 10.11.2.3
11000000 => 192
00001010 => 10
————
00000000 => 0
10101000 => 168
00000001 => 11
————
00000000 => 0
00001010 => 10
00001011 => 11
————
00001010 => 10
00000001 => 1
00000011 => 3
————
00000001 => 1
The result is an access-list mask of 0.0.10.1 that would match both ip addresses.
The wildcard mask is a logical XOR conjunction. Means 0 XOR 1 = 1, 1 XOR 0 = 1, 0 XOR 0 = 0, 1 XOR 1 = 0. So only if there are differnt values, the result is 1.
That’s:
11000000 => 192
00001010 => 10
————
1111111 => 255
10101000 => 168
00000001 => 11
————
1111111 => 255
00001010 => 10
00001011 => 11
————
11110101 => 244
00000001 => 1
00000011 => 3
————
00000010=> 2
192.168.1.10.1 and 10.11.2.3
Networkmask: 0.0.10.1
Wildcardmask: 255.255.244.2
Example 2:
Another more common example:
192.168.43.132
192.168.45.4
access-list mask:
11000000 => 192
11000000 => 192
——————-
11000000 => 192
10101000 => 168
10101000 => 168
——————-
10101000 => 168
00101011 => 43
00101101 => 45
——————-
00101001 => 41
10000100 => 132
00000100 => 4
—————–
00000100 = > 4
The resulting access-list is:
192.168.41.4
The wildcard mask is:
11000000 => 192
11000000 => 192
——————-
00000000 => 0
10101000 => 168
10101000 => 168
——————-
00000000 = > 0
00101011 => 43
00101101 => 45
——————-
00000110 => 6
10000100 => 132
00000100 => 4
—————–
10000000 => 128
Wildcardmask 0.0.6.128
192.168.43.132
192.168.45.4
Mask: 192.168.41.4 , Wildcardmask: 0.0.6.128
Example 3
192.168.32.5
192.168.48.99
11000000 => 192
11000000 => 192
——————-
11000000 => 192
10101000 => 168
10101000 => 168
——————
10101000 => 168
00100000 => 32
00110000 => 48
—————–
00100000 => 32
00000101 => 5
01100011 => 99
—————-
00000001 => 1
Mask 192.168.32.1
Wildcardmask:
11000000 => 192
11000000 => 192
——————-
0000000 => 0
10101000 => 168
10101000 => 168
——————
00000000 => 168
00100000 => 32
00110000 => 48
—————–
00010000 => 16
00000101 => 5
01100011 => 99
—————-
01100110 => 102
0.0.16.102
Source:
http://www.internetworkexpert.com/resources/01700370.htm
http://wiki.linuxquestions.org/wiki/IPv6_deployment:addressing
http://blog.sazza.de/?p=209

No comments:

Post a Comment