A. 概要
IPv6を導入したくても導入できないネットワーク環境があります。このような環境でうっかりIPv6を有効にしてしまうと、yumアップデートがフリーズ等するなどの問題が発生します。本稿では、CentOS7.9、RHEL8.8、Ubuntu22環境での、IPv6無効化/再有効化の方法を解説します。
B. 解決したい課題
CentOS7.9、RHEL8.8、Ubuntu22環境で、IPv6無効化/再有効化したい。
C. 解決方法
CentOS7.9、RHEL8.8、Ubuntu22の順に、それぞれ、IPv6の、──①設定状態の確認、②無効化設定、③無効化後の確認、④再有効化設定、⑤再有効化後の確認──を解説します。
C.1 CentOS7.9で、IPv6を無効化/再有効化する
- enp0s3がインターネットに抜けていけるインターフェースです。
現在のIPv6設定を確認します
# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.43 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 240d:1a:b86:e800:443a:d3fa:1644:e55b prefixlen 64 scopeid 0x0<global>
inet6 fe80::777f:d335:e009:c9e0 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:aa:80:99 txqueuelen 1000 (Ethernet)
RX packets 6425 bytes 8944887 (8.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 555 bytes 52301 (51.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 enp0s3
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3
(関係部分のみ抜粋)
- inetにも、inet6にもアドレスが設定されています。
現在のIPv6設定の動作を確認します
# ping -c 3 -4 google.com
PING google.com (142.250.196.142) 56(84) bytes of data.
64 bytes from nrt12s36-in-f14.1e100.net (142.250.196.142): icmp_seq=1 ttl=116 time=5.16 ms
64 bytes from nrt12s36-in-f14.1e100.net (142.250.196.142): icmp_seq=2 ttl=116 time=4.38 ms
64 bytes from nrt12s36-in-f14.1e100.net (142.250.196.142): icmp_seq=3 ttl=116 time=4.04 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 4.044/4.528/5.162/0.474 ms
# ping -c 3 -6 google.com
PING google.com(nrt12s28-in-x0e.1e100.net (2404:6800:4004:810::200e)) 56 data bytes
64 bytes from nrt12s28-in-x0e.1e100.net (2404:6800:4004:810::200e): icmp_seq=1 ttl=116 time=5.35 ms
64 bytes from nrt12s28-in-x0e.1e100.net (2404:6800:4004:810::200e): icmp_seq=2 ttl=116 time=4.46 ms
64 bytes from nrt12s28-in-x0e.1e100.net (2404:6800:4004:810::200e): icmp_seq=3 ttl=116 time=4.39 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 4.396/4.737/5.352/0.439 ms
- IPv4、IPv6ともにpingが届きます。
IPv6を無効化します
# nmcli c mod enp1s0f0 ipv6.method ignore
# systemctl restart NetworkManager
無効化後のIPv6設定を確認します
# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.43 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:feaa:8099 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:aa:80:99 txqueuelen 1000 (Ethernet)
RX packets 6763 bytes 8973062 (8.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 741 bytes 74573 (72.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- inet6の設定は残っています(ちょっと紛らわしいです)
無効化後のIPv6動作を確認します
# ping -c 3 -4 google.com
PING google.com (142.250.196.110) 56(84) bytes of data.
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=1 ttl=116 time=3.90 ms
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=2 ttl=116 time=4.57 ms
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=3 ttl=116 time=4.42 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 3.906/4.302/4.574/0.291 ms
# ping -c 3 -6 google.com
connect: ネットワークに届きません
- IPv6のpingが疎通しなくなりました。
IPv6を再有効化します
# nmcli c mod enp1s0f0 ipv6.method auto
# systemctl restart NetworkManager
- IPv6のアドレスの取得/設定方法を指定する必要があります。上例は「自動設定」です。
再有効化後のIPv6設定を確認します
# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.43 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 240d:1a:b86:e800:443a:d3fa:1644:e55b prefixlen 64 scopeid 0x0<global>
inet6 fe80::a00:27ff:feaa:8099 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:aa:80:99 txqueuelen 1000 (Ethernet)
RX packets 7212 bytes 9008616 (8.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1023 bytes 103714 (101.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
inet6
の変化がないので、ifconfigでは有効/無効が分かりません。
再有効化後のIPv6動作を確認します
# ping -c 3 -4 google.com
PING google.com (142.250.196.110) 56(84) bytes of data.
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=1 ttl=116 time=3.92 ms
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=2 ttl=116 time=4.23 ms
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=3 ttl=116 time=4.16 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 3.920/4.104/4.234/0.153 ms
# ping -c 3 -6 google.com
PING google.com(nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e)) 56 data bytes
64 bytes from nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e): icmp_seq=1 ttl=58 time=5.82 ms
64 bytes from nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e): icmp_seq=2 ttl=58 time=4.59 ms
64 bytes from nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e): icmp_seq=3 ttl=58 time=4.44 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 4.443/4.951/5.822/0.623 ms
- IPv4、IPv6ともにpingが届くようになりました。
C.2 RHEL8.8で、IPv6を無効化/再有効化する
- enp1s0f0がインターネットに抜けていけるインターフェースです
現在のIPv6設定を確認します
# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.8 (Ootpa)
# ifconfig enp1s0f0
enp1s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.123 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a236:9fff:fe8e:41b4 prefixlen 64 scopeid 0x20<link>
inet6 240d:1a:b86:e800:a236:9fff:fe8e:41b4 prefixlen 64 scopeid 0x0<global>
ether a0:36:9f:8e:41:b4 txqueuelen 1000 (Ethernet)
RX packets 1488726 bytes 1568795131 (1.4 GiB)
RX errors 0 dropped 20 overruns 0 frame 0
TX packets 566324 bytes 191670708 (182.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xdf100000-df1fffff
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 101 0 0 enp1s0f0
192.168.1.0 0.0.0.0 255.255.255.0 U 101 0 0 enp1s0f0
(関係部分のみ抜粋)
- inetにも、inet6にもアドレスが設定されています。
現在のIPv6設定の動作を確認します
# ping -c 3 -4 google.com
PING google.com (142.250.196.142) 56(84) bytes of data.
64 bytes from nrt12s36-in-f14.1e100.net (142.250.196.142): icmp_seq=1 ttl=117 time=3.19 ms
64 bytes from nrt12s36-in-f14.1e100.net (142.250.196.142): icmp_seq=2 ttl=117 time=3.46 ms
64 bytes from nrt12s36-in-f14.1e100.net (142.250.196.142): icmp_seq=3 ttl=117 time=3.23 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 3.194/3.293/3.455/0.132 ms
# ping -c 3 -6 google.com
PING google.com(nrt12s36-in-x0e.1e100.net (2404:6800:4004:822::200e)) 56 data bytes
64 bytes from nrt12s36-in-x0e.1e100.net (2404:6800:4004:822::200e): icmp_seq=1 ttl=58 time=4.32 ms
64 bytes from nrt12s36-in-x0e.1e100.net (2404:6800:4004:822::200e): icmp_seq=2 ttl=58 time=3.58 ms
64 bytes from nrt12s36-in-x0e.1e100.net (2404:6800:4004:822::200e): icmp_seq=3 ttl=58 time=3.65 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 3.578/3.847/4.320/0.342 ms
- IPv4、IPv6ともにpingが届きます。
IPv6を無効化します
# nmcli c mod enp1s0f0 ipv6.method disable
# systemctl restart NetworkManager
-
ipv6.method disable
がサポートされてない古いRHEL8.Xバージョンでは、ipv6.method ignore
を指定します。
無効化後のIPv6設定を確認します
# ifconfig enp1s0f0
enp1s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.123 netmask 255.255.255.0 broadcast 192.168.1.255
ether a0:36:9f:8e:41:b4 txqueuelen 1000 (Ethernet)
RX packets 1496291 bytes 1570491500 (1.4 GiB)
RX errors 0 dropped 21 overruns 0 frame 0
TX packets 572846 bytes 192855030 (183.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xdf100000-df1fffff
- inet6の設定が削除されました。
無効化後のIPv6動作を確認します
# ping -c 3 -4 google.com
PING google.com (142.250.196.110) 56(84) bytes of data.
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=1 ttl=117 time=3.30 ms
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=2 ttl=117 time=3.20 ms
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=3 ttl=117 time=3.11 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 3.114/3.206/3.302/0.100 ms
# ping -c 3 -6 google.com
connect: Network is unreachable
- IPv6のpingが疎通しなくなりました。
IPv6を再有効化します
# nmcli c mod enp1s0f0 ipv6.method auto
# systemctl restart NetworkManager
- IPv6のアドレスの取得/設定方法を指定する必要があります。上例は「自動設定」です。
再有効化後のIPv6設定を確認します
# ifconfig enp1s0f0
enp1s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.123 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a236:9fff:fe8e:41b4 prefixlen 64 scopeid 0x20<link>
inet6 240d:1a:b86:e800:a236:9fff:fe8e:41b4 prefixlen 64 scopeid 0x0<global>
ether a0:36:9f:8e:41:b4 txqueuelen 1000 (Ethernet)
RX packets 1499728 bytes 1571232879 (1.4 GiB)
RX errors 0 dropped 21 overruns 0 frame 0
TX packets 575824 bytes 193334401 (184.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xdf100000-df1fffff
- inet6のアドレス情報が再設定されました。
再有効化後のIPv6動作を確認します
# ping -c 3 -4 google.com
PING google.com (142.250.198.14) 56(84) bytes of data.
64 bytes from nrt12s58-in-f14.1e100.net (142.250.198.14): icmp_seq=1 ttl=117 time=3.15 ms
64 bytes from nrt12s58-in-f14.1e100.net (142.250.198.14): icmp_seq=2 ttl=117 time=3.26 ms
64 bytes from nrt12s58-in-f14.1e100.net (142.250.198.14): icmp_seq=3 ttl=117 time=3.11 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 3.106/3.170/3.256/0.078 ms
# ping -c 3 -6 google.com
PING google.com(nrt12s36-in-x0e.1e100.net (2404:6800:4004:822::200e)) 56 data bytes
64 bytes from nrt12s36-in-x0e.1e100.net (2404:6800:4004:822::200e): icmp_seq=1 ttl=58 time=4.50 ms
64 bytes from nrt12s36-in-x0e.1e100.net (2404:6800:4004:822::200e): icmp_seq=2 ttl=58 time=3.70 ms
64 bytes from nrt12s36-in-x0e.1e100.net (2404:6800:4004:822::200e): icmp_seq=3 ttl=58 time=3.59 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 3.589/3.929/4.500/0.406 ms
- IPv4、IPv6ともにpingが届くようになりました。
C.3 Ubuntu22で、IPv6を無効化/再有効化する
- enps03がインターネットに抜けていけるインターフェースです
NetworkManager環境を構築します
- UbuntuはデフォルトではNetworkManager環境が設定されてないので、設定します。
# apt install network-manager
# systemctl status NetworkManager
● NetworkManager.service - Network Manager
Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-09-08 06:07:06 UTC; 19s ago
Docs: man:NetworkManager(8)
Main PID: 1780 (NetworkManager)
Tasks: 3 (limit: 40062)
Memory: 3.1M
CPU: 44ms
CGroup: /system.slice/NetworkManager.service
└─1780 /usr/sbin/NetworkManager --no-daemon
(以下省略)
- /etc/netplan/00-installer-config.yamlを編集します。
-
version: 2
とrenderer: NetworkManager
の行を追加します。
# This is the network config written by 'subiquity'
network:
version: 2
renderer: NetworkManager
- 編集後リブートして、nmcliコマンドが正常動作することを確認します。
# nmcli c show
NAME UUID TYPE DEVICE
netplan-enp0s3 1eef7e45-3b9d-3043-bee3-fc5925c90273 ethernet enp0s3
現在のIPv6設定を確認します
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS"
# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.42 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe6d:1c43 prefixlen 64 scopeid 0x20<link>
inet6 240d:1a:b86:e800:a00:27ff:fe6d:1c43 prefixlen 64 scopeid 0x0<global>
ether 08:00:27:6d:1c:43 txqueuelen 1000 (Ethernet)
RX packets 510 bytes 317588 (317.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 287 bytes 33136 (33.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 enp0s3
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s3
(関係部分のみ抜粋)
- inetにも、inet6にもアドレスが設定されています。
現在のIPv6設定の動作を確認します
# apt-get install iputils-ping net-tools
# ping -c 3 -4 google.com
PING (142.250.196.110) 56(84) bytes of data.
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=1 ttl=117 time=4.69 ms
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=2 ttl=117 time=4.22 ms
64 bytes from nrt12s35-in-f14.1e100.net (142.250.196.110): icmp_seq=3 ttl=117 time=4.10 ms
--- ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 4.101/4.336/4.691/0.255 ms
# ping -c 3 -6 google.com
PING google.com(nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e)) 56 data bytes
64 bytes from nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e): icmp_seq=1 ttl=117 time=3.85 ms
64 bytes from nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e): icmp_seq=2 ttl=117 time=4.26 ms
64 bytes from nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e): icmp_seq=3 ttl=117 time=4.14 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 3.847/4.082/4.255/0.172 ms
- pingがインストールされてない場合は、
iputils-ping
net-tools
をインストールしておきます。 - IPv4、IPv6ともにpingが届きます。
IPv6を無効化します
# nmcli c mod netplan-enp0s3 ipv6.method disable
# systemctl restart NetworkManager
無効化後のIPv6設定を確認します
# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.42 netmask 255.255.255.0 broadcast 192.168.1.255
ether 08:00:27:6d:1c:43 txqueuelen 1000 (Ethernet)
RX packets 308 bytes 29193 (29.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 168 bytes 20875 (20.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- inet6の設定が削除されました。
無効化後のIPv6動作を確認します
# ping -c 3 -4 google.com
PING google.com (142.250.198.14) 56(84) bytes of data.
64 bytes from nrt12s58-in-f14.1e100.net (142.250.198.14): icmp_seq=1 ttl=117 time=3.85 ms
64 bytes from nrt12s58-in-f14.1e100.net (142.250.198.14): icmp_seq=2 ttl=117 time=4.13 ms
64 bytes from nrt12s58-in-f14.1e100.net (142.250.198.14): icmp_seq=3 ttl=117 time=3.98 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 3.854/3.988/4.132/0.113 ms
# ping -c 3 -6 google.com
ping: connect: Network is unreachable
- IPv6のpingが疎通しなくなりました。
IPv6を再有効化します
# nmcli c mod netplan-enp0s3 ipv6.method auto
# systemctl restart NetworkManager
- IPv6のアドレスの取得/設定方法を指定する必要があります。上例は「自動設定」です。
再有効化後のIPv6設定を確認します
# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.42 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe6d:1c43 prefixlen 64 scopeid 0x20<link>
inet6 240d:1a:b86:e800:9e67:bc57:fffe:ccc3 prefixlen 64 scopeid 0x0<global>
inet6 240d:1a:b86:e800:a00:27ff:fe6d:1c43 prefixlen 64 scopeid 0x0<global>
ether 08:00:27:6d:1c:43 txqueuelen 1000 (Ethernet)
RX packets 458 bytes 41510 (41.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 263 bytes 32191 (32.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- inet6のアドレス情報が再設定されました。
再有効化後のIPv6動作を確認します
# ping -c 3 -4 google.com
PING (142.250.196.142) 56(84) bytes of data.
64 bytes from nrt12s36-in-f14.1e100.net (142.250.196.142): icmp_seq=1 ttl=117 time=3.62 ms
64 bytes from nrt12s36-in-f14.1e100.net (142.250.196.142): icmp_seq=2 ttl=117 time=4.37 ms
64 bytes from nrt12s36-in-f14.1e100.net (142.250.196.142): icmp_seq=3 ttl=117 time=4.06 ms
--- ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2006ms
rtt min/avg/max/mdev = 3.624/4.015/4.366/0.304 ms
# ping -c 3 -6 google.com
PING google.com(nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e)) 56 data bytes
64 bytes from nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e): icmp_seq=1 ttl=117 time=5.23 ms
64 bytes from nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e): icmp_seq=2 ttl=117 time=4.07 ms
64 bytes from nrt12s35-in-x0e.1e100.net (2404:6800:4004:821::200e): icmp_seq=3 ttl=117 time=4.35 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 4.074/4.551/5.225/0.490 ms
- IPv4、IPv6ともにpingが届くようになりました。
以上