记为 Ubuntu 增加 IPv6 地址
转:https://cyp0633.icu/archives/1244
检查配置
使用命令 ifconfig
查看网卡中 IPV6 地址的配置,如果看到如下结果说明当前 IPV6 配置是无效的。
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.5 netmask 255.255.254.0 broadcast 10.0.0.1
inet6 fe80::5054:ff:fe69:5bca prefixlen 64 scopeid 0x20<link>
ether 52:54:00:69:5b:ca txqueuelen 1000 (Ethernet)
RX packets 87844 bytes 5902599 (5.9 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 820 bytes 130766 (130.7 KB)
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 186 bytes 14118 (14.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 186 bytes 14118 (14.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
配置 ipv6
ubuntu 从18.04开始使用 Netplan 配置网络
Netplan 的默认配置文件处于 /etc/netplan 中,里面应该有一个 YAML 文件,即其配置文件。
vim 编辑这个文件看到:
network:
version: 2
renderer: networkd
ethernets: # ens3 为网络接口名称[ifconfig可以看到]
ens3:
addresses:
- xxx.xxx.xxx.xxx/24 # IPV4地址/24
- xxxx:xxxx:xxxx::xxxx/64 # IPV6地址/64
gateway4: xxx.xxx.xxx.xxx # IPV4网关 不知道网关的话问服务商
gateway6: xxxx:xxxx:xxxxx:xxxx::1 # IPV6网关 不知道网关的话问服务商
nameservers:
addresses:
- "1.1.1.1" # [DNS服务器]
- "1.0.0.1" # [备用DNS服务器]
执行以下代码使配置生效
netplan try
netplan apply
检查网络连接
使用 networkctl status ens3
命令查看 ens3 端口情况。除了查看 Address 信息有没有错误之外,最重要的是 State。如果是绿色的 routable (configured),那么一切正常。
然后ping一下google.com的ipv6看看通不通吧:
ping6 www.google.com
ubuntu 临时关闭ipv6
先ifconfig
查看 interface-name (网卡名字)
我的是 ens3 所以你的网卡名字记得替换
# 关闭
sudo sh -c 'echo 1 > /proc/sys/net/ipv6/conf/ens3/disable_ipv6'
# 开启
sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/ens3/disable_ipv6'
# 查看关闭状态
# 显示0说明ipv6开启,1说明关闭
cat /proc/sys/net/ipv6/conf/ens3/disable_ipv6
# 关闭ipv6的方法是临时的,下次开机就会发生变化