Working with IPV6 addresses in Linux
Well, working with IPV6 addresses is little bit tricky unlike IPV4 addresses. IPV6 addresses are 128 bit-length with 8 octets each of 16 bits. In this post, i'll explain my working experience with IPV6 addresses.
While working with IPV6, i found that sipcalc command is very useful on deciding which ipv6 address to use and what is the network corresponding to the ipv6 address.
Hence, lets install sipcalc in Linux using bellow steps:
Step1: Download the sipcalc rpm
wget ftp://ftp.univie.ac.at/systems/linux/fedora/epel/6/x86_64/sipcalc-1.1.6-4.el6.x86_64.rpm
Step2: Install the rpm
rpm -ivh sipcalc-1.1.6-4.el6.x86_64.rpm
Lets suppose i need at most 2 IPV6 addresses in a subnet. I have 128-2 => 126 network bits & 2 host bits. That means 2^2 hosts per subnet of length /126.
Example: 2001:db8:1:1:0:0:0:0/126 is a subnet having 4 possible ipv6 addresses as:
2001:db8:1:1:0:0:0:0 => network address
2001:db8:1:1:0:0:0:1 & 2001:db8:1:1:0:0:0:2 => Usable host addresses
2001:db8:1:1:0:0:0:3 => Broadcast address.
Using sipcalc, its easy to know on which subnet a IPV6 address belong to. Lets pick a IPv6 address 2001:db8:1:1:0:0:0:1/126
[Indu@gns ~]$ sipcalc -6 2001:db8:1:1:0:0:0:1/126
-[ipv6 : 2001:db8:1:1:0:0:0:1/126] - 0
[IPV6 INFO]
Expanded Address - 2001:0db8:0001:0001:0000:0000:0000:0001
Compressed address - 2001:db8:1:1::1
Subnet prefix (masked) - 2001:db8:1:1:0:0:0:0/126
Address ID (masked) - 0:0:0:0:0:0:0:1/126
Prefix address - ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc
Prefix length - 126
Address type - Aggregatable Global Unicast Addresses
Network range - 2001:0db8:0001:0001:0000:0000:0000:0000 -
2001:0db8:0001:0001:0000:0000:0000:0003
From above we can see that ipv6 address 2001:db8:1:1:0:0:0:1/126 belong to the network 2001:db8:1:1:0:0:0:0/126 which has 4 possible v6 addresses as shown in Network range section above.
Once the IPV6 addresses to use are finalised, you can add your system to v6 network using following steps:
Step1: Assign IPV6 address on interface lets say eth0:
To remove the added ipv6 route, just run:
route -A inet6 del 2001:db9:1:1:1:1:1:0/125 gw 2001:db8:1:1::1
Finally, lets verify our configuration:
Step1: Verify the IPV6 address is assigned correctly as
[root@BR-140 ~]# ifconfig eth0 | grep -i inet6 | grep -i scope:Global
inet6 addr: 2001:db8:1:1::3/64 Scope:Global
Step2: Verify IPV6 route as
[root@BR-140 ~]# route -n -A inet6 | awk '$2~/[0-9a-zA-Z]+:[0-9a-zA-Z]+/'
2001:db9:1:1:1:1:1:0/125 2001:db8:1:1::1 UG 1 0 0 eth0
ff02::1:ff00:2/128 ff02::1:ff00:2 UC 0 3 0 eth1
Thats all, now you are connected to IPV6 network.
While working with IPV6, i found that sipcalc command is very useful on deciding which ipv6 address to use and what is the network corresponding to the ipv6 address.
Hence, lets install sipcalc in Linux using bellow steps:
Step1: Download the sipcalc rpm
wget ftp://ftp.univie.ac.at/systems/linux/fedora/epel/6/x86_64/sipcalc-1.1.6-4.el6.x86_64.rpm
Step2: Install the rpm
rpm -ivh sipcalc-1.1.6-4.el6.x86_64.rpm
Lets suppose i need at most 2 IPV6 addresses in a subnet. I have 128-2 => 126 network bits & 2 host bits. That means 2^2 hosts per subnet of length /126.
Example: 2001:db8:1:1:0:0:0:0/126 is a subnet having 4 possible ipv6 addresses as:
2001:db8:1:1:0:0:0:0 => network address
2001:db8:1:1:0:0:0:1 & 2001:db8:1:1:0:0:0:2 => Usable host addresses
2001:db8:1:1:0:0:0:3 => Broadcast address.
Using sipcalc, its easy to know on which subnet a IPV6 address belong to. Lets pick a IPv6 address 2001:db8:1:1:0:0:0:1/126
[Indu@gns ~]$ sipcalc -6 2001:db8:1:1:0:0:0:1/126
-[ipv6 : 2001:db8:1:1:0:0:0:1/126] - 0
[IPV6 INFO]
Expanded Address - 2001:0db8:0001:0001:0000:0000:0000:0001
Compressed address - 2001:db8:1:1::1
Subnet prefix (masked) - 2001:db8:1:1:0:0:0:0/126
Address ID (masked) - 0:0:0:0:0:0:0:1/126
Prefix address - ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc
Prefix length - 126
Address type - Aggregatable Global Unicast Addresses
Network range - 2001:0db8:0001:0001:0000:0000:0000:0000 -
2001:0db8:0001:0001:0000:0000:0000:0003
From above we can see that ipv6 address 2001:db8:1:1:0:0:0:1/126 belong to the network 2001:db8:1:1:0:0:0:0/126 which has 4 possible v6 addresses as shown in Network range section above.
Once the IPV6 addresses to use are finalised, you can add your system to v6 network using following steps:
Step1: Assign IPV6 address on interface lets say eth0:
ifconfig eth0 inet6 add 2001:db8:1:1:0:0:0:1/126 up
To remove the ipv6 address, just run:
ifconfig eth0 inet6 del 2001:db8:1:1:0:0:0:1/126
Step2: Add an IPV6 static route to reach to the destination V6 network:
route -A inet6 add [destination IPV6 network ] gw [next-hop IP]
Example: route -A inet6 add 2001:db9:1:1:1:1:1:0/125 gw 2001:db8:1:1::1
route -A inet6 del 2001:db9:1:1:1:1:1:0/125 gw 2001:db8:1:1::1
Finally, lets verify our configuration:
Step1: Verify the IPV6 address is assigned correctly as
[root@BR-140 ~]# ifconfig eth0 | grep -i inet6 | grep -i scope:Global
inet6 addr: 2001:db8:1:1::3/64 Scope:Global
Step2: Verify IPV6 route as
[root@BR-140 ~]# route -n -A inet6 | awk '$2~/[0-9a-zA-Z]+:[0-9a-zA-Z]+/'
2001:db9:1:1:1:1:1:0/125 2001:db8:1:1::1 UG 1 0 0 eth0
ff02::1:ff00:2/128 ff02::1:ff00:2 UC 0 3 0 eth1
Thats all, now you are connected to IPV6 network.
Comments