
{"id":47051,"date":"2024-08-16T15:34:38","date_gmt":"2024-08-16T15:34:38","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=47051"},"modified":"2024-08-18T03:28:25","modified_gmt":"2024-08-18T03:28:25","slug":"disable-ipv6-ubuntu-24-04","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/08\/disable-ipv6-ubuntu-24-04\/","title":{"rendered":"How to Disable IPv6 in Ubuntu 24.04"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-43605\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>This is a step by step beginner&#8217;s guide shows how to disable IPv6 in Ubuntu 24.04 LTS with or without system restart.<\/p>\n<p>IPv6 is the future of internet protocols. But for some reasons, such as compatibility with certain networks, testing purpose, or security concerns, or just because don&#8217;t use that thing, users may want to disable IPv6 in their machines.<\/p>\n<p>Disabling IPv6 is generally safe. There may be small performance loss on some websites and services that are optimized for IPv6, though you can re-enable it at any time as you want.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/ipv6-disabled.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47052\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/ipv6-disabled-700x465.webp\" alt=\"\" width=\"610\" height=\"405\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/ipv6-disabled-700x465.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/ipv6-disabled-300x199.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/ipv6-disabled-768x510.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/ipv6-disabled.webp 903w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><br \/>\n<!--more--><\/p>\n<h3>Option 1: Disable IPv6 using Kernel Parameters<\/h3>\n<p>The ipv6 kernel module has options to either disable the whole functionality, or disable ipv6 on all network interfaces.<\/p>\n<p>You can either configure Grub boot-loader to load kernel with ipv6 disabled on every startup, or change the kernel parameters\u00a0at runtime without restarting your machine.<\/p>\n<h4>1. Use sysctl to disable IPv6 without reboot<\/h4>\n<p>sysctl is a command line tool configure kernel parameters at runtime.<\/p>\n<p><b>To disable ipv6 on all network interfaces<\/b>, simply use command:<\/p>\n<pre>sudo sysctl --write net.ipv6.conf.all.disable_ipv6=1<\/pre>\n<p>IPv6 will be disabled immediately and persist until you reboot the machine. To verify, either use <code>ip addr<\/code> command to see if there&#8217;s &#8220;<code>inet6<\/code>&#8221; sections or run <code>ip -6 addr<\/code> to check if there&#8217;s any ouput.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/sysctl-disable-ipv6.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47053\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/sysctl-disable-ipv6-700x393.webp\" alt=\"\" width=\"610\" height=\"342\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/sysctl-disable-ipv6-700x393.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/sysctl-disable-ipv6-300x168.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/sysctl-disable-ipv6-768x431.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/sysctl-disable-ipv6.webp 946w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>For choice, you may disable ipv6 for certain network interface. First, use the command <code>ip addr<\/code> to get network interfaces names. In my case (see the screenshot above), I have <code>lo<\/code>, <code>enp0s31f6<\/code>, <code>wlp61s0<\/code>, etc, network interfaces.<\/p>\n<p>For example, disable ipv6 only for <code>wlp61s0<\/code>, use command:<\/p>\n<pre>sudo sysctl --write net.ipv6.conf.wlp61s0.disable_ipv6=1<\/pre>\n<p>And, by replacing <b>1<\/b> in commands above with <b>0<\/b> will re-enable ipv6 for all or certain network devices.<\/p>\n<p><b>Without running the sysctl command again and again, you may write the rules into either <code>\/etc\/sysctl.conf<\/code> file or custom file under <code>\/etc\/sysctl.d\/<\/code> directory.<\/b><\/p>\n<p>To edit the <code>\/etc\/sysctl.conf<\/code> file, use command:<\/p>\n<pre>sudo nano \/etc\/sysctl.conf<\/pre>\n<p>When the file opens in the command line text editor, scroll down and add following lines to tell disable ipv6 for all, default, and lo network interfaces.<\/p>\n<pre>net.ipv6.conf.all.disable_ipv6=1\r\nnet.ipv6.conf.default.disable_ipv6=1\r\nnet.ipv6.conf.lo.disable_ipv6=1<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/etc-sysctl.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47054\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/etc-sysctl-700x505.webp\" alt=\"\" width=\"610\" height=\"440\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/etc-sysctl-700x505.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/etc-sysctl-300x216.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/etc-sysctl.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>After saving the file by pressing Ctrl+S then Ctrl+X, then, run the command below will <strong>apply the changes<\/strong> immediately:<\/p>\n<pre>sudo sysctl -p<\/pre>\n<p>In case you use custom config file (e.g., <code>\/etc\/sysctl.d\/99-ipv6.conf<\/code>) for the configuration, then apply it by running the command below instead to point out path to config file:<\/p>\n<pre>sudo sysctl -p \/etc\/sysctl.d\/99-ipv6.conf<\/pre>\n<p><b>Sadly, due to <a href=\"https:\/\/bugs.launchpad.net\/ubuntu\/+source\/procps\/+bug\/50093\" target=\"_blank\" rel=\"noopener\">this bug<\/a> since 2006, the changes you made in the <code>\/etc\/sysctl.conf<\/code> or custom file under <code>\/etc\/sysctl.d\/<\/code> do NOT persist after reboot.<\/b><\/p>\n<p>You need to either re-run the last <code>sysctl -p<\/code> command on every boot, or create a schedule job to make the command run automatically on startup. To do so, run command:<\/p>\n<pre>sudo crontab -e<\/pre>\n<p>Choose the default nano text editor if prompts, then scroll down and add line below:<\/p>\n<pre>@reboot \/usr\/bin\/sleep 15 &amp;&amp; \/usr\/sbin\/sysctl --system<\/pre>\n<p>This line tells to run <code>\/usr\/sbin\/sysctl --system<\/code> command, to load all the config files, with 15 seconds delay on every boot. Finally, press Ctrl+S to save, and Ctrl+X to exit.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crontab-sysctl.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47055\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crontab-sysctl-700x513.webp\" alt=\"\" width=\"610\" height=\"447\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crontab-sysctl-700x513.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crontab-sysctl-300x220.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crontab-sysctl-768x563.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crontab-sysctl.webp 810w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h4>2. Use Grub to load kernel with ipv6 disabled<\/h4>\n<p>If you don&#8217;t like to use crontab as a workaround to load sysctl configuration on every boot, then you can configure Grub bootloader instead.<\/p>\n<p>First, connect to your Ubuntu server or press <code>Ctrl+Alt+T<\/code> to open terminal in Ubuntu desktop, then run command to open the configuration file for Grub:<\/p>\n<pre>sudo nano \/etc\/default\/grub<\/pre>\n<p>When file opens, add either <b>ipv6.disable=1<\/b> or <b>ipv6.disable_ipv6=1<\/b> as value of GRUB_CMDLINE_LINUX_DEFAULT. Finally, press Ctrl+S to save and Ctrl+X to exit.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grub.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47057\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grub-700x469.webp\" alt=\"\" width=\"610\" height=\"409\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grub-700x469.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grub-300x201.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grub-768x515.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grub.webp 810w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>According to the <a href=\"https:\/\/docs.kernel.org\/networking\/ipv6.html\" target=\"_blank\" rel=\"noopener\">kernel docs<\/a>:<\/p>\n<ul>\n<li>The <code>ipv6.disable=1<\/code> option will disable the whole ipv6 functionality.<\/li>\n<li>While <code>ipv6.disable_ipv6=1<\/code> tells to NOT assign IPv6 addresses on any interfaces.<\/li>\n<\/ul>\n<p><b>To apply change<\/b>, you need to run the command to re-generate the boot-loader entries.<\/p>\n<pre>sudo update-grub<\/pre>\n<p>If you&#8217;re running on Ubuntu Desktop with <a href=\"https:\/\/ubuntuhandbook.org\/index.php\/2022\/04\/install-grub-customizer-ubuntu-2204\/\" target=\"_blank\" rel=\"noopener\">Grub-Customizer<\/a> installed, then you may launch the app and navigate to &#8220;General settings&#8221; tab to add the kernel parameters.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grubcustomizer.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47058\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grubcustomizer-700x502.webp\" alt=\"\" width=\"610\" height=\"437\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grubcustomizer-700x502.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grubcustomizer-300x215.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grubcustomizer-768x551.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-ipv6-grubcustomizer.webp 928w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Option 2: Disable IPv6 using Network Manager<\/h3>\n<p>The network manager also provides options to disable ipv6 on either per-device basis or per-connection basis.<\/p>\n<p>First, run command to list connections:<\/p>\n<pre>nmcli connection show<\/pre>\n<p>As the screenshot below shows, in my case I have <code>wlp61s0<\/code> wifi device connected to <code>elite01<\/code> wifi network, <code>lo<\/code> the loopback interface to communicate with servers on local machine, and <code>lxcbr0<\/code> for containers.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/nmcli-connection.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47059\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/nmcli-connection-700x424.webp\" alt=\"\" width=\"610\" height=\"369\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/nmcli-connection-700x424.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/nmcli-connection-300x182.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/nmcli-connection.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>To disable ipv6 on per device basis, <code>wlp61s0<\/code> for example, use command:<\/p>\n<pre>nmcli device modify wlp61s0 ipv6.method \"disabled\"<\/pre>\n<p>Then verify by running either <code>ip addr<\/code> to check all network interfaces or <code>ip addr show wlp61s0<\/code> for certain interface (<code>wlp61s0<\/code> in the case).<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/nmcli-disable-ipv6.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47060\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/nmcli-disable-ipv6-700x370.webp\" alt=\"\" width=\"610\" height=\"322\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/nmcli-disable-ipv6-700x370.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/nmcli-disable-ipv6-300x158.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/nmcli-disable-ipv6.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>To disable ipv6 on per connection basis, <code>elite01<\/code> wifi network for example, use command:<\/p>\n<pre>nmcli connection modify elite01 ipv6.method \"disabled\"<\/pre>\n<p>This method only disable ipv6 for selected connection, while the network device is still having ipv6 address assigned. And for Ubuntu Desktop, there is usually graphical network options to do the same job.<\/p>\n<p><strong>To undo the changes above<\/strong>, just re-run the last commands by replacing <code>\"disabled\"<\/code> with <code>\"auto\"<\/code>.<\/p>","protected":false},"excerpt":{"rendered":"<p>This is a step by step beginner&#8217;s guide shows how to disable IPv6 in Ubuntu 24.04 LTS with or without system restart. IPv6 is the future of internet protocols. But for some reasons, such as compatibility with certain networks, testing purpose, or security concerns, or just because don&#8217;t use that thing, users may want to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":43605,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[1317],"class_list":["post-47051","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-network"],"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=47051"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47051\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/43605"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=47051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=47051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=47051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}