linux Server Opens IPv6

Keywords: Linux network CentOS

On the premise of the implementation of IPv6 in the National Network Telecom Office, IPv6 address configuration is required for the server.

The configuration process outlines Ha:


#cat ipv6.sh
#! /bin/bash
Ipv6=$1
Ipv4=$(dig +short $(hostname)) #Used to get the corresponding network card and change it as needed
Time=$(date  +%Y%m%d%H%M%S)
[[ $Ipv6 ]] || echo "ipv6 get fail!,Usage: sh  ipv6.sh X:X:X::ipv6 address"
[[ $Ipv4 ]] || echo "ipv4 get fail!"
echo "The change module includes: grub To configure sysctl To configure IP To configure"
Grub(){
    #grub modification
    cp /etc/default/grub /etc/default/grub.$Time
    cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.$Time
    sed -i 's#ipv6.disable=1#ipv6.disable=0#'  /etc/default/grub  || grep 'ipv6.disable' /etc/default/grub
    grub2-mkconfig -o /boot/grub2/grub.cfg &>/dev/null
    grep 'ipv6.disable=0' /boot/grub2/grub.cfg &>/dev/null && \
    echo "###grub ok ###" || echo -e "\033[31m"grub fail !!!!!!!!!!!"\033[0m" 
    }    
Systcl(){
    #Configure sysctl.conf
    cp /etc/sysctl.conf /etc/sysctl.conf.$Time
    sed -i '/net.ipv6.conf.all.disable_ipv6/d' /etc/sysctl.conf
    sed -i '/net.ipv6.conf.default.disable_ipv6/d' /etc/sysctl.conf
    sysctl -p &>/dev/null
    
    grep ipv6 /etc/sysctl.conf &>/dev/null &&\
    echo -e "\033[31m sysctl fail !!!!!!!!!!! \033[0m"  || echo "###sysctl ok ###"
    }
Ip(){
    #IP Configuration:
    cp /etc/sysconfig/network /etc/sysconfig/network.$Time
    grep "NETWORKING=yes" /etc/sysconfig/network &>/dev/null || echo "NETWORKING=yes" >> /etc/sysconfig/network
    grep "NETWORKING_IPV6=yes" /etc/sysconfig/network &>/dev/null || echo "NETWORKING_IPV6=yes" >> /etc/sysconfig/network
    FileName=$(grep $Ipv4 /etc/sysconfig/network-scripts/* | awk -F':' '{print $1}')
    [[ $FileName ]] || cp $FileName $FileName.$Time
    [[ $FileName ]] || echo -e "\033[31m get network file fail !!!!!!!!!!! \033[0m" 
    
    grep "IPV6INIT=yes"  $FileName &>/dev/null || echo "IPV6INIT=yes" >> $FileName
    grep "IPV6_AUTOCONF=no"  $FileName &>/dev/null || echo "IPV6_AUTOCONF=no" >> $FileName
    grep "IPV6ADDR="  $FileName &>/dev/null || [[ $FileName ]] && [[ $Ipv6 ]] && \
    echo "IPV6ADDR=$Ipv6" >> $FileName
    
    grep 'IPV6' $FileName &>/dev/null && \
    echo "###IPconfig ok ###" || echo -e "\033[31m IPconfig fail !!!!!!!!!!! \033[0m" 
    }

Reboot(){
    //restart
    sync && sync
    echo "10s after reoot"
    sleep 10
    reboot
    }
Check(){
    echo 
    echo 
    echo 
    echo "=====================IPv6 Changes include:==================="
    echo "=============File : /boot/grub2/grub.cfg"
    grep 'ipv6.disable=0' /boot/grub2/grub.cfg
    echo 
    echo "=============File : /etc/sysctl.conf "
    grep "ipv6" /etc/sysctl.conf 
    echo 
    echo "=============File : /etc/sysconfig/network"
    grep "NETWORKING_IPV6=yes" /etc/sysconfig/network
    echo 
    echo "=============File : $FileName"
    grep 'IPV6' $FileName
    echo 
    }
Grub
Systcl
Ip
Check
#Reboot


//See:

One: grub modification:

Method 1:

#/boot/grub2/grub.cfg

linux16 Line Add: ipv6.disable=0 (0: turn on IPV6, 1: turn off IPV6)

 

Method 2:

1. Edit / etc / default / grub and change the value of the kernel parameter ipv6.disable from 1 in the GRUB_CMDLINE_LINUX line to 0, for example:

# cat /etc/default/grub

GRUB_CMDLINE_LINUX="ipv6.disable=0 crashkernel=auto rhgb quiet"


Note: ipv6.disable = 0 is the default value, so you can remove this parameter ipv6.disable from the GRUB_CMDLINE_LINUX parameter list as needed.(

2. Use the commands shown below to regenerate the GRUB configuration file and overwrite the existing configuration file.(

#grub2-mkconfig -o /boot/grub2/grub.cfg

 

2: Configure sysctl.conf

1. In order for ipv6 to run online, make sure that the following lines in/etc/sysctl.conf are commented out or deleted.(

#cat /etc/sysctl.conf | grep ipv6
#net.ipv6.conf.all.disable_ipv6 = 1 ###Comment/delete this line or change its value from 1 to 0
#net.ipv6.conf.default.disable_ipv6 = 1 ###Comment/delete this line or change its value from 1 to 0


2. Reread the configuration file/etc/sysctl.conf using the command'sysctl-p'.(

#sysctl -p


 

 

3: Restart the server and load gurb configuration:

Verify that the configuration is valid;

ip add

#Check to see if there is an ipv6 configuration;

 


centos 6

1. Check if the server loads the ipv6 module

  lsmod | grep ipv6


If there is no echo, then it is not loaded.

Load ipv6 module

modprobe ipv6


Run Again

lsmod | grep ipv6

, if echo appears, ipv6 is loaded normally

 

2. Modify profile to enable ipv6

cat /etc/modprobe.d/ipv6.conf
//Modify options ipv6 disable=0


 

 

 

3. Turn on kernel parameters to support ipv6

After performing the above steps, run the following command to turn on ipv6 for the kernel

  sysctl -w net.ipv6.conf.all.disable_ipv6=0


 

Run Again

sysctl -a | grep ipv6 | grep disable


If all parameters are 0, ipv6 is fully supported.

 

4. Configure ipv6 address on the network card

After all the above configurations are complete, the network card can support ipv6 addresses. Enable one to try.

 

 

IV. IP Configuration:

Add the following two things #/etc/sysconfig/network #where the gateway can also be configured;

NETWORKING=yes
NETWORKING_IPV6=yes


sed -i '/^NETWORKING_IPV6=/d' /etc/sysconfig/network
echo "NETWORKING_IPV6=yes" >> /etc/sysconfig/network


#ifcfg-eth0
IPV6INIT=yes
IPV6_AUTOCONF=no
IPV6ADDR=xxx::xxx
IPV6_DEFAULTGW=fe80::1%eth0(eth0 For actual network card name)



Follow-up questions on configuring IPv6 are welcome to read another blog post: Priority problem with network dual stacks

Because there may be some risks to be aware of after configuration.

Posted by newmember on Mon, 06 Jan 2020 20:44:17 -0800