LoginSignup
1
2

More than 3 years have passed since last update.

CentOS Linux 8 でネットワークインターフェースの IPv6 を無効にする

Posted at

概要

  • NetworkManager のコマンドラインツール nmcli でネットワークインターフェースの IPv6 を無効にする

今回の環境

  • CentOS Linux 8
# cat /etc/centos-release
CentOS Linux release 8.1.1911 (Core) 

設定前の状態を確認する

現在は IPv6 が有効な状態。
ifconfig コマンドで inet6 エントリーが表示されている場合は、デバイスで IPv6 が有効になっている。

# nmcli connection show
NAME  UUID                                  TYPE      DEVICE
eth0  XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX  ethernet  eth0
# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet XXX.XXX.XXX.XXX  netmask XXX.XXX.XXX.XXX  broadcast XXX.XXX.XXX.XXX
        inet6 XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX  prefixlen 64  scopeid 0x0<global>
        inet6 XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX  prefixlen 64  scopeid 0x20<link>
        ether XX:XX:XX:XX:XX:XX  txqueuelen 1000  (Ethernet)
        RX packets 1856709  bytes 121862479 (116.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 53733  bytes 8848173 (8.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

IPv6 を無効にする

nmcli connection modify コマンドでネットワークインターフェース eth0 の IPv6 を無効にする。
ipv6.method に disabled を指定。
ipv6.addresses と ipv6.gateway に無効な値を指定。

# nmcli connection modify eth0 ipv6.method "disabled" ipv6.addresses "" ipv6.gateway ""

nmcli connection show コマンドで設定値を確認する。

# nmcli connection show eth0 | grep ipv6
ipv6.method:                            disabled
ipv6.dns:                               --
ipv6.dns-search:                        --
ipv6.dns-options:                       --
ipv6.dns-priority:                      0
ipv6.addresses:                         --
ipv6.gateway:                           --
ipv6.routes:                            --
ipv6.route-metric:                      -1
ipv6.route-table:                       0 (unspec)
ipv6.routing-rules:                     --
ipv6.ignore-auto-routes:                no
ipv6.ignore-auto-dns:                   no
ipv6.never-default:                     no
ipv6.may-fail:                          yes
ipv6.ip6-privacy:                       0 (disabled)
ipv6.addr-gen-mode:                     stable-privacy
ipv6.dhcp-duid:                         --
ipv6.dhcp-send-hostname:                yes
ipv6.dhcp-hostname:                     --
ipv6.token:                             --

nmcli connection up コマンドでネットワーク接続を再起動して設定を反映する。

# nmcli connection up eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)

ipv6.addresses と ipv6.gateway を指定しない場合はエラーが発生

Red Hat Enterprise Linux 8 の公式ドキュメントには ipv6.method だけの指定方法が書かれていたが、今回の環境では ipv6.addresses と ipv6.gateway の値を設定しない場合は以下のようなエラーが発生していた。

# nmcli connection modify eth0 ipv6.method "disabled"
Error: Failed to modify connection 'eth0': ipv6.addresses: this property is not allowed for 'method=disabled'

# nmcli connection modify eth0 ipv6.method "disabled" ipv6.addresses ""
Error: Failed to modify connection 'eth0': ipv6.gateway: gateway cannot be set if there are no addresses configured

設定後の状態を確認する

ifconfig コマンドで inet6 エントリーが表示されない場合は、このネットワークインターフェースで IPv6 が無効になっている。

# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet XXX.XXX.XXX.XXX  netmask XXX.XXX.XXX.XXX  broadcast XXX.XXX.XXX.XXX
        ether XX:XX:XX:XX:XX:XX  txqueuelen 1000  (Ethernet)
        RX packets 1885535  bytes 123804373 (118.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 56110  bytes 9257206 (8.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

disable_ipv6 ファイルに 1 が書き込まれている場合は、このネットワークインターフェースで IPv6 が無効になっている。

# cat /proc/sys/net/ipv6/conf/eth0/disable_ipv6
1

参考資料

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2