Centos7 添加 IPV6 地址

正文索引 [隐藏]

Centos7 添加 IPV6 地址

前言

大家应该买过含IPV6地址的服务器,或者多个IPV4地址的服务器,但是有的商家不会自动绑定,需要我们手动绑定.

例如Buyvm和OVH

正文

临时添加

ip -6 addr add 2605:6400:0020:130d::2/64 dev eth0

使用ifcongfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet xxx.xxx.xxx.xxx  netmask 255.255.255.0  broadcast 205.185.121.255
        inet6 2605:6400:20:130d::2  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::216:45ff:fe97:af56  prefixlen 64  scopeid 0x20<link>
        inet6 2605:6400:20:130d::  prefixlen 128  scopeid 0x0<global>
        ether 00:16:45:97:af:56  txqueuelen 1000  (Ethernet)
        RX packets 126686795  bytes 31465397496 (29.3 GiB)
        RX errors 0  dropped 7  overruns 0  frame 0
        TX packets 90533440  bytes 747906361963 (696.5 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

可以发现已经绑定上了

永久添加

首先使用ifconfig查看网卡信息

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
        ether 02:42:8d:3b:c1:b2  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet xxx.xxx.xxx.xxx  netmask 255.255.255.0  broadcast 205.185.121.255
        inet6 fe80::216:45ff:fe97:af56  prefixlen 64  scopeid 0x20<link>
        ether 00:16:45:97:af:56  txqueuelen 1000  (Ethernet)
        RX packets 126662654  bytes 31463073997 (29.3 GiB)
        RX errors 0  dropped 7  overruns 0  frame 0
        TX packets 90509939  bytes 747690271954 (696.3 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 66726308  bytes 30552961591 (28.4 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 66726308  bytes 30552961591 (28.4 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

从中可以看到eth0为主网卡,目前绑定的IPV6为fe80::即内网地址

之后切换到/etc/sysconfig/network-scripts文件夹

修改对应得配置文件,在最后添加:

IPV6INIT=yes
DNS1=1.1.1.1
DNS2=2a06:98c1:54::bc6
DNS3=2001:4860:4860::8888
IPV6ADDR=2605:6400:0020:130d:0000:0000:0000:0000

之后systemctl restart network重启网络