Categories
SysOps

How to disable IPv6 on Raspberry Pi 4

Disable IPv6 on Raspberry Pi 4.

The first solution uses runtime kernel parameters, second and third one disables ipv6 module using two equivalent methods.

Take advantage of system parameters

Inspect current IPv4/IPv6 addresses.

$ ip -br a
lo               UNKNOWN        127.0.0.1/8 ::1/128 
eth0             UP             172.16.1.101/16 fe80::14b8:2700:4354:ec24/64 
wlan0            DOWN

Alter system parameters to disable IPv6.

$ echo net.ipv6.conf.all.disable_ipv6=1 | sudo tee /etc/sysctl.d/disable-ipv6.conf
net.ipv6.conf.all.disable_ipv6=1

Apply changes.

$ sudo sysctl --system
* Applying /usr/lib/sysctl.d/50-pid-max.conf ...
kernel.pid_max = 4194304
* Applying /etc/sysctl.d/98-rpi.conf ...
kernel.printk = 3 4 1 3
vm.min_free_kbytes = 16384
net.ipv4.ping_group_range = 0 2147483647
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/disable-ipv6.conf ...
net.ipv6.conf.all.disable_ipv6 = 1
* Applying /usr/lib/sysctl.d/protect-links.conf ...
fs.protected_fifos = 1
fs.protected_hardlinks = 1
fs.protected_regular = 2
fs.protected_symlinks = 1
* Applying /etc/sysctl.conf ...

Inspect IP addresses.

$ ip -br a
lo               UNKNOWN        127.0.0.1/8 ::1/128 
eth0             UP             172.16.1.101/16 
wlan0            DOWN   

Take advantage of kernel boot parameters

Inspect current IPv4/IPv6 addresses.

$ ip -br a
lo               UNKNOWN        127.0.0.1/8 ::1/128 
eth0             UP             172.16.1.102/16 fe80::18c2:49dd:2041:4e4b/64 

wlan0            DOWN

Inspect kernel boot parameters.

$ cat /boot/cmdline.txt; echo
console=serial0,115200 console=tty1 root=PARTUUID=4c6fc505-02 rootfstype=ext4 fsck.repair=yes rootwait

Alter these parameters to disable IPv6 module.

$ sudo sed -i -e 's/$/ ipv6.disable=1/' /boot/cmdline.txt
$ cat /boot/cmdline.txt; echo
console=serial0,115200 console=tty1 root=PARTUUID=4c6fc505-02 rootfstype=ext4 fsck.repair=yes rootwait ipv6.disable=1

Reboot operating system.

$ sudo reboot

Inspect kernel parameters.

$ cat /proc/cmdline 
coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 video=HDMI-A-1:2560x1080M@60 smsc95xx.macaddr=E4:5F:01:42:3A:49 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  console=ttyS0,115200 console=tty1 root=PARTUUID=4c6fc505-02 rootfstype=ext4 fsck.repair=yes rootwait ipv6.disable=1

Inspect IP addresses.

$ ip -br a
lo               UNKNOWN        127.0.0.1/8 
eth0             UP             172.16.1.102/16 
wlan0            DOWN     

Take advantage of modprobe configuration

Inspect current IPv4/IPv6 addresses.

$ ip -br a
lo               UNKNOWN        127.0.0.1/8 ::1/128 
eth0             UP             172.16.1.103/16 fe80::14b8:a330:21a2:24aa/64 

wlan0            DOWN

Display module parameters.

$ modinfo ipv6
name:           ipv6
filename:       (builtin)
alias:          net-pf-10
license:        GPL
file:           net/ipv6/ipv6
description:    IPv6 protocol stack for Linux
author:         Cast of dozens
parm:           disable:Disable IPv6 module such that it is non-functional (int)
parm:           disable_ipv6:Disable IPv6 on all interfaces (int)
parm:           autoconf:Enable IPv6 address autoconfiguration on all interfaces (int)

Blacklist IPv6 module.

$ echo "options ipv6 disable=1" | sudo tee  /etc/modprobe.d/ipv6.conf
options ipv6 disable=1

Reboot operating system.

$ sudo reboot

Inspect IP addresses.

$ ip -br a
lo               UNKNOWN        127.0.0.1/8 
eth0             UP             172.16.1.103/16 
wlan0            DOWN