Sunday, May 20, 2012

Red Hat / CentOS Add IPv6 Network Alias (multiple IPv6 IP to Same NIC)

Q. How do I add multiple IPv6 address to eth0 under Red Hat / Fedora / RHEL / CentOS Linux for virtual hosting?

A. There are two ways to add network aliaes under Red hat / CentOS Linux system. You need to edit any one of the following file in order to add IPv6 network alias.
  1. /etc/rc.local - Use ifconfig command and shell loop.
  2. /etc/sysconfig/network-scripts/ifcfg-eth0 - Set special variable called IPV6ADDR_SECONDARIES for eth0 virtual hosting (network alias).
First, setup IPv6 main server IP address and default router. Once basic IPv6 connectivity established you can setup aliases for NIC.

/etc/rc.local configuration

To add 2607:f0d0:1002:11::10 to 2607:f0d0:1002:11::50 (total 40) virtual aliases, open /etc/rc.local file, enter:
# vi /etc/rc.local
Append following code:
#IP Alias
for ip in {10..40}; do /sbin/ifconfig eth0 inet6 add 2607:f0d0:1002:11::${ip}/64; done
You can type the same command at a shell prompt to immediately activate network aliases. Or create a shell script and call it from /etc/rc.local itself:
#!/bin/bash
INETP="2607:f0d0:1002:11::"
PRE="64"
START=2
END=200
INT_IF="eth0"
IFCONFIG=/sbin/ifconfig
echo -n "Adding IPv6 Alias..."
for i in {$START..$END}
do
$IFCONFIG $INT_IF inet6 add ${INETP}${i}/${PRE}
done
echo "Done!"

sysv style configuration

Open network interface configuration file, enter:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Append a list of secondary IPv6 addresses following code (set 5 aliases):
IPV6ADDR_SECONDARIES="2607:f0d0:1002:11::10/64 \
2607:f0d0:1002:11::11/64 \
2607:f0d0:1002:11::12/64 \
2607:f0d0:1002:11::13/64 \
2607:f0d0:1002:11::14/64"
Save and close the file. Restart networking:
# /etc/init.d/network restart
Test your connectivity using ping6 and other tools:
$ /sbin/ifconfig
$ /sbin/ifconfig eth0 | less
$ ping6 2607:f0d0:1002:11::15

No comments:

Post a Comment