作用场景
-
VPS 重装系统后发现商家给你配的 ipv6 地址没有出现在ifconfig或者hosts中,且软件无法绑定ipv6地址。
-
有多个 ipv6地址
教程
首先我们需要安装
net-tools
,一般的 linux 都自带。先用
ifconfig
看一下你有没有绑定/绑定了多少个ipv6地址:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
root@localhost:~# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.4.1.2 netmask 255.255.252.0 broadcast 10.4.1.255 inet6 2409:1f54:14f0:7:1:0:0:1919 prefixlen 64 scopeid 0x0<global> inet6 fe80::be24:11ff:fe4f:e415 prefixlen 64 scopeid 0x20<link> ether bc:bc:bc:bc:bc:bc txqueuelen 1000 (Ethernet) RX packets 2428320 bytes 5240960878 (1.1 GiB) RX errors 0 dropped 173306 overruns 0 frame 0 TX packets 3885095 bytes 3754172432 (3.4 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 11324 bytes 19139659 (18.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 11324 bytes 19139659 (18.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
先来看看帮助页面:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
root@localhost:~# ip address help Usage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ] [ CONFFLAG-LIST ] ip address del IFADDR dev IFNAME [mngtmpaddr] ip address {save|flush} [ dev IFNAME ] [ scope SCOPE-ID ] [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up] ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ] [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up] [ vrf NAME ] ] ip address {showdump|restore} IFADDR := PREFIX | ADDR peer PREFIX [ broadcast ADDR ] [ anycast ADDR ] [ label IFNAME ] [ scope SCOPE-ID ] [ metric METRIC ] SCOPE-ID := [ host | link | global | NUMBER ] FLAG-LIST := [ FLAG-LIST ] FLAG FLAG := [ permanent | dynamic | secondary | primary | [-]tentative | [-]deprecated | [-]dadfailed | temporary | CONFFLAG-LIST ] CONFFLAG-LIST := [ CONFFLAG-LIST ] CONFFLAG CONFFLAG := [ home | nodad | mngtmpaddr | noprefixroute | autojoin ] LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ] LFT := forever | SECONDS TYPE := { vlan | veth | vcan | vxcan | dummy | ifb | macvlan | macvtap | bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | lowpan | gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan | vti | nlmon | can | bond_slave | ipvlan | geneve | bridge_slave | hsr | macsec | netdevsim }
然后执行:
1 2 3 4 5 6 7
ip -6 addr add ipv6地址/64(子网掩码长度,如果ifconfig里有相同类型的ipv6,那就按ifconfig里的填) dev 网卡(一般是eth0) # 例子 ip -6 addr add 2409:d114:5f41:9:1:9:8:1011/64 dev eth0 # 查看路由表有没有你添加的ipv6地址 route -6 # 如果没有,就添加一下 ip -6 route add default via ipv6地址 dev 网卡