Disable IPv6 on Linux Permanently with sysctl

{"time":1776378046132,"version":"2.28.2","blocks":[{"type":"header","data":{"text":"Disable IPv6 on Linux","level":2}},{"type":"paragraph","data":{"text":"This guide explains how to permanently disable IPv6 on a Linux server using a persistent sysctl configuration file. The change takes effect immediately — no reboot required — and will survive future system restarts automatically."}},{"type":"header","data":{"text":"How It Works","level":2}},{"type":"paragraph","data":{"text":"The Linux kernel exposes IPv6 behavior through a set of runtime parameters found under /proc/sys/net/ipv6/. By default, IPv6 is enabled on all network interfaces. To disable it, you need to set three specific kernel parameters to 1: one for all currently active interfaces, one for any interfaces created in the future, and one for the loopback interface."}},{"type":"paragraph","data":{"text":"While you can change these parameters on the fly using the sysctl command, those changes are lost on the next reboot. To make them permanent, you write them to a configuration file inside /etc/sysctl.d/. Files in this directory are loaded automatically at boot time. Using a 99- prefix ensures your file is applied last — overriding any distribution defaults that might otherwise re-enable IPv6."}},{"type":"header","data":{"text":"Step 1 — Create a Dedicated sysctl Configuration File","level":3}},{"type":"paragraph","data":{"text":"Start by creating a new, dedicated configuration file for disabling IPv6. Keeping this setting in its own file makes it easy to identify, modify, or remove later:"}},{"type":"code","data":{"code":"sudo nano /etc/sysctl.d/99-disable-ipv6.conf"}},{"type":"paragraph","data":{"text":"Paste the following three lines into the file:"}},{"type":"code","data":{"code":"net.ipv6.conf.all.disable_ipv6 = 1\nnet.ipv6.conf.default.disable_ipv6 = 1\nnet.ipv6.conf.lo.disable_ipv6 = 1"}},{"type":"paragraph","data":{"text":"Each line targets a different scope:"}},{"type":"list","data":{"style":"unordered","items":["all — disables IPv6 on every network interface currently active on the system.","default — ensures that any new network interfaces created after boot also have IPv6 disabled.","lo — disables IPv6 on the loopback interface (localhost)."]}},{"type":"paragraph","data":{"text":"Save and close the file. In nano, press Ctrl+O to save and Ctrl+X to exit."}},{"type":"header","data":{"text":"Step 2 — Apply the Changes Immediately (No Reboot Needed)","level":3}},{"type":"paragraph","data":{"text":"Reload all sysctl configuration files, including the one you just created, with the following command:"}},{"type":"code","data":{"code":"sudo sysctl --system"}},{"type":"paragraph","data":{"text":"This reads every .conf file in /etc/sysctl.d/ (and related directories) and applies all settings to the running kernel in real time. IPv6 is disabled immediately — no reboot is required."}},{"type":"header","data":{"text":"Step 3 — Verify That IPv6 Is Disabled","level":3}},{"type":"paragraph","data":{"text":"Check whether any network interfaces still have IPv6 addresses assigned:"}},{"type":"code","data":{"code":"ip a | grep inet6"}},{"type":"paragraph","data":{"text":"If IPv6 has been fully disabled, this command will return no output at all. If you still see a ::1 address listed for the loopback interface, double-check that the net.ipv6.conf.lo.disable_ipv6 = 1 line is present and correctly formatted in your configuration file."}},{"type":"paragraph","data":{"text":"You can also verify the kernel parameter value directly:"}},{"type":"code","data":{"code":"cat /proc/sys/net/ipv6/conf/all/disable_ipv6"}},{"type":"paragraph","data":{"text":"A return value of 1 confirms IPv6 is disabled. If you see 0, IPv6 is still active and the sysctl configuration was not loaded correctly. In that case, re-run sudo sysctl --system and check your configuration file carefully for typos or formatting errors."}},{"type":"header","data":{"text":"Summary","level":2}},{"type":"paragraph","data":{"text":"Disabling IPv6 via sysctl is the most reliable and maintainable method on Linux. By placing your settings in /etc/sysctl.d/99-disable-ipv6.conf, the configuration is modular, easy to manage, and automatically applied on every boot. This approach works across most major Linux distributions, including Ubuntu, Debian, CentOS, and Rocky Linux."}}]}