3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【2024年12月版】Ubuntu24.04, 22.04 で IPv6 を無効にする方法 【GRUB版】

Last updated at Posted at 2023-07-11

はじめに

Ubuntu24.04, Ubuntu22.04 で IPv6 無効にしたい。。。
そうだ、GRUBからカーネルパラメータで無効化しよう

環境

Ubuntu 24.04

詳細 ```terminal $ uname -a Linux host02 6.8.0-51-generic #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec 5 13:09:44 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux $ cat /proc/version Linux version 6.8.0-51-generic (buildd@lcy02-amd64-091) (x86_64-linux-gnu-gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, GNU ld (GNU Binutils for Ubuntu) 2.42) #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec 5 13:09:44 UTC 2024 $ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=24.04 DISTRIB_CODENAME=noble DISTRIB_DESCRIPTION="Ubuntu 24.04.1 LTS" $ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=24.04 DISTRIB_CODENAME=noble DISTRIB_DESCRIPTION="Ubuntu 24.04.1 LTS" $ cat /etc/os-release PRETTY_NAME="Ubuntu 24.04.1 LTS" NAME="Ubuntu" VERSION_ID="24.04" VERSION="24.04.1 LTS (Noble Numbat)" VERSION_CODENAME=noble ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=noble LOGO=ubuntu-logo ```

Ubuntu 22.04

詳細 ```terminal $ uname -a Linux host01 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux $ cat /proc/version Linux version 5.15.0-76-generic (buildd@lcy02-amd64-028) (gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 $ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS" $ cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.2 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.2 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy ```

IPv6 が有効な状態

$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever

手順

  • GRUB の設定ファイルを更新
  • GRUB の更新
  • リブート

GRUB の設定ファイルを更新

GRUB_CMDLINE_LINUX_DEFAULT の行に ipv6.disable=1 を付加する

以下のようになる

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"
or
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"

$ sudo cp /etc/default/grub /etc/default/grub.backup 
$ sudo vim /etc/default/grub
$ diff /etc/default/grub /etc/default/grub.backup 
10c10
< GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"
---
> GRUB_CMDLINE_LINUX_DEFAULT=""

これは、GRUBからカーネルパラメータで ipv6.disable=1 を渡すように設定している

GRUB の更新

update-grubコマンドで、設定ファイル /etc/default/grub から、GRUB の設定 /boot/grub/grub.cfg を更新する

(Windows11とデュアルブートになっているので、/dev/nvme0n1p1@/EFI/Microsoft/Boot/bootmgfw.efi が表示されている)

/boot/grub/grub.cfg は直接編集せずに、 /etc/default/grub を編集して、update-grub/boot/grub/gurb.cfg に反映させるのがお作法
(/boot/efi/EFI/ubuntu/grub.cfg がubuntuのgrubだが、内部で /boot/grub/grub.cfg を参照している)

$ sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-76-generic
Found initrd image: /boot/initrd.img-5.15.0-76-generic
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Found Windows Boot Manager on /dev/nvme0n1p1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings ...
done

リブート

$ sudo reboot

GRUB の設定を表示

ipv6.disable=1 が追加されている

image.png

IPv6 が無効な状態

$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever

さいごに

かんたんでしたね

3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?