{"id":4192,"date":"2024-02-23T08:17:11","date_gmt":"2024-02-23T13:17:11","guid":{"rendered":"https:\/\/www.both.org\/?p=4192"},"modified":"2024-02-23T08:17:11","modified_gmt":"2024-02-23T13:17:11","slug":"how-i-disabled-ipv6-on-linux","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=4192","title":{"rendered":"How I disabled IPv6 on Linux"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"4192\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p>Simplify your network by disabling IPv6.<\/p>\n\n\n\n<p>IPv6 is a good thing for the Internet in general, but I find it unnecessarily complex for use in most home and small- to medium-size businesses. Like many others, I continue to use private IPv4 address ranges for my own internal networks and those for which I have some level of responsibility. My ISP only provides IPv4 addresses anyway, so it makes no sense to use IPv6 internally when all external packets are IPv4. Besides, IPv4 is much simpler, and one of my Linux Philosophy tenets is &#8220;Find the Simplicity.&#8221;<\/p>\n\n\n\n<p>As a result, I disabled IPv6 on all my hosts. It seemed easy\u2014at first. Here is how I did it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing for IPv6<\/h2>\n\n\n\n<p>My hosts run the <a href=\"https:\/\/spins.fedoraproject.org\/xfce\/download\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\">Fedora 36 Xfce spin<\/a> along with many packages and configuration changes I perform after the initial default installation. All of my hosts have the most recent updates installed. One of those hosts is my firewall\/router, which is the first host on which I disabled IPv6.<\/p>\n\n\n\n<p>You can check to see whether IPv6 is currently active on your Linux host. The <code>nmcli<\/code> command results below are from my router\/firewall host. All the active NICs have both IPv4 and IPv6 addresses.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># <strong>nmcli<\/strong>\nenp4s0: connected to enp4s0\n        \"Realtek RTL8111\/8168\/8411\"\n        ethernet (r8169), 84:16:F9:04:44:03, hw, mtu 1500\n        ip4 default\n        inet4 45.20.209.41\/29\n        route4 45.20.209.40\/29 metric 102\n        route4 default via 45.20.209.46 metric 102\n        inet6 2600:1700:7c0:860:8616:f9ff:fe04:4403\/64\n        inet6 fe80::8616:f9ff:fe04:4403\/64\n        route6 fe80::\/64 metric 256\n        route6 default via fe80::a698:13ff:fee5:fa10 metric 1024\n        route6 2600:1700:7c0:860::\/64 metric 256\n\nenp1s0: connected to enp1s0\n        \"Realtek RTL8111\/8168\/8411\"\n        ethernet (r8169), 84:16:F9:03:E9:89, hw, mtu 1500\n        inet4 192.168.10.1\/24\n        route4 192.168.10.0\/24 metric 101\n        inet6 fe80::8616:f9ff:fe03:e989\/64\n        route6 fe80::\/64 metric 256\n\nenp2s0: connected to enp2s0\n        \"Realtek RTL8111\/8168\/8411\"\n        ethernet (r8169), 84:16:F9:03:FD:85, hw, mtu 1500\n        inet4 192.168.0.254\/24\n        route4 192.168.0.0\/24 metric 100\n        inet6 fe80::8616:f9ff:fe03:fd85\/64\n        route6 fe80::\/64 metric 256\n\nlo: unmanaged\n        \"lo\"\n        loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536\n\nDNS configuration:\n        servers: 192.168.0.52 8.8.8.8 8.8.4.4\n        interface: enp4s0\n\n        servers: 192.168.0.52 8.8.8.8\n        interface: enp2s0\n\n        servers: 192.168.0.52 8.8.8.8\n        interface: enp1s0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Use GRUB to configure the kernel<\/h2>\n\n\n\n<p>GRUB\u2013the Grand Unified Bootloader\u2013loads the kernel into memory and sets many kernel parameters during the Linux boot process. The current bootloader is actually GRUB2, the second major version of GRUB, but it is easier just to call it GRUB.<\/p>\n\n\n\n<p>The GRUB configuration file <code>\/boot\/grub2\/grub.cfg<\/code> provides the startup configuration for the kernel, but you should not modify it directly. The location of the UEFI GRUB configuration file may vary depending on your distribution. However, its location is irrelevant for this purpose. Linux startup kernel configuration can be easily modified using the <code>\/etc\/default\/grub<\/code> configuration file, which configures the kernel properly regardless of whether it boots using UEFI.<\/p>\n\n\n\n<p>There are two command line arguments to add to the <code>\/etc\/default\/grub<\/code> file to configure the Linux kernel to disable IPv6. The first, <strong>GRUB_CMDLINE_LINUX=&#8221;ipv6.disable=1&#8243;<\/strong> adds <strong>&#8220;ipv6.disable=1&#8221;<\/strong> to the kernel command line.<\/p>\n\n\n\n<p>The second, <strong>GRUB_CMDLINE_LINUX_DEFAULT=&#8221;ipv6.disable=1 quiet splash&#8221;<\/strong> is a little more complicated. When you set <strong>GRUB_DISABLE_RECOVERY<\/strong> to <strong>true<\/strong>, one menu entry will be generated for each Linux kernel. When set to <strong>false<\/strong>, two menu entries are created for each kernel: One default entry and one entry for recovery mode. This option lists command-line arguments to be added only to the default menu entry, after those listed in <strong>GRUB_CMDLINE_LINUX<\/strong>.<\/p>\n\n\n\n<p>The other two arguments define how the kernel startup looks on the display. The <strong>&#8220;quiet&#8221;<\/strong> argument disables most of the informational messages emitted by the kernel during its startup and self-configuration. The <strong>&#8220;splash&#8221;<\/strong> argument causes the splash screen to be displayed during kernel startup. The splash screen can be a graphic such as a logo or an animation.<\/p>\n\n\n\n<p>My <code>\/etc\/default\/grub<\/code> file looks like this after making those additions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GRUB_TIMEOUT=5\nGRUB_DISTRIBUTOR=\"$(sed 's, release .*$,,g' \/etc\/system-release)\"\nGRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true\nGRUB_TERMINAL_OUTPUT=\"console\"\nGRUB_CMDLINE_LINUX=\"rhgb quiet\"\nGRUB_DISABLE_RECOVERY=\"true\"\nGRUB_ENABLE_BLSCFG=true\nGRUB_CMDLINE_LINUX_DEFAULT=\"ipv6.disable=1 quiet splash\"\nGRUB_CMDLINE_LINUX=\"ipv6.disable=1\"<\/code><\/pre>\n\n\n\n<p>After making these (or any) additions to the <code>\/etc\/default\/grub<\/code> file, run the <code>grub2-mkconfig<\/code> command, which adds these arguments to the kernel command line in the <code>grub.cfg<\/code> configuration file for each installed kernel. These changes do not take effect immediately. You must reboot the hosts for IPv6 to be disabled.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Automate this solution<\/h2>\n\n\n\n<p>Automating these tasks using Ansible is straightforward. Just create a playbook with the following settings and run it against the list of hosts that need this change. The first two tasks in this playbook append the desired configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- name: Play 1 - Modify \/etc\/default\/grub to configure kernel boot parameters.\n  hosts: f36vm\n\n  tasks:\n    - name: Append GRUB_CMDLINE_LINUX_DEFAULT variable to \/etc\/default\/grub\n      lineinfile:\n        path: \/etc\/default\/grub\n        insertafter: EOF\n        line: 'GRUB_CMDLINE_LINUX_DEFAULT=\"ipv6.disable=1 quiet splash\"'\n\n    - name: Append GRUB_CMDLINE_LINUX variable to \/etc\/default\/grub\n      lineinfile:\n        path: \/etc\/default\/grub\n        insertafter: EOF\n        line: 'GRUB_CMDLINE_LINUX=\"ipv6.disable=1\"'\n\n    - name: Run grub2-mkconfig to update \/boot\/grub\/grub.cfg\n      command:\n        cmd: grub2-mkconfig<\/code><\/pre>\n\n\n\n<p>Once again, you must reboot the hosts for IPv6 to be disabled. You can add the reboot to the playbook so that the changes take effect immediately, or wait until the next time the hosts need to be rebooted for other reasons.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The other solution<\/h2>\n\n\n\n<p>I created another solution; it is just not the best and most elegant option. However, I want to show my thought process because there is some information here that might be useful.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Add a local file to sysctl.d<\/h3>\n\n\n\n<p>You can use the <code>\/etc\/sysctl<\/code> file to add the configuration settings necessary, but it is much better to add a local file to the <code>\/etc\/sysctl.d<\/code> directory so that it won&#8217;t be overwritten during updates or upgrades. Note that there is already a file named <code>99-sysctl.conf<\/code>. You can use that file to set the configuration, but I created a file named <code>99-local-network.conf<\/code> with the following content for this purpose. That way, if the <code>99-sysctl.conf<\/code> changes with future updates or upgrades, my file will remain untouched. This is not an executable file; it is a configuration file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>################################################################################\n# Local NetworkManager settings - Specifically to disable IPV6                 #\n################################################################################\n#\nnet.ipv6.conf.all.disable_ipv6 = 1\nnet.ipv6.conf.default.disable_ipv6 = 1<\/code><\/pre>\n\n\n\n<p><strong>Note<\/strong>: Like many configuration files in configuration directories like this one, the files contained in the directory are read in natural sorted order. That means the value for a variable declared in a file with a later sort order will override an earlier declaration for the same variable.<\/p>\n\n\n\n<p>A reboot is usually used to cause these changes to take effect, but I later learned how to do so without a reboot. I rebooted my system and reran the <code>nmcli<\/code> command with the following results:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@wally ~]# <strong>nmcli<\/strong>\nenp4s0: connected to enp4s0\n        \"Realtek RTL8111\/8168\/8411\"\n        ethernet (r8169), 84:16:F9:04:44:03, hw, mtu 1500\n        ip4 default\n        inet4 45.20.209.41\/29\n        route4 45.20.209.40\/29 metric 101\n        route4 default via 45.20.209.46 metric 101\n\nenp1s0: connected to enp1s0\n        \"Realtek RTL8111\/8168\/8411\"\n        ethernet (r8169), 84:16:F9:03:E9:89, hw, mtu 1500\n        inet4 192.168.10.1\/24\n        route4 192.168.10.0\/24 metric 102\n\nenp2s0: connected to enp2s0\n        \"Realtek RTL8111\/8168\/8411\"\n        ethernet (r8169), 84:16:F9:03:FD:85, hw, mtu 1500\n        inet4 192.168.0.254\/24\n        route4 192.168.0.0\/24 metric 100\n\nlo: unmanaged\n        \"lo\"\n        loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536\n\nDNS configuration:\n        servers: 192.168.0.52 8.8.8.8 8.8.4.4\n        interface: enp4s0\n\n        servers: 192.168.0.52 8.8.8.8\n        interface: enp2s0\n\n        servers: 192.168.0.52 8.8.8.8\n        interface: enp1s0<\/code><\/pre>\n\n\n\n<p>This shows that my simple fix worked.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Except&#8230;<\/h3>\n\n\n\n<p>Except that solution only works on one of my twelve Linux computers. After writing the preceding part of this article, I started installing this fix on all of my other hosts. I had only done one system when I realized that this approach did not always work. I then tried it on one of my VMs and it also failed there. As best I can tell, it only works on one host\u2014the one I use as my firewall and router.<\/p>\n\n\n\n<p>After some additional research on a VM, I discovered that these settings could also be issued as commands using <code>sysctl<\/code> so that the system would not need a reboot. I could enter those commands from the command line to deactivate IPv6. Here&#8217;s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@f36vm ~]# <strong>sysctl -w net.ipv6.conf.all.disable_ipv6=1<\/strong>\nnet.ipv6.conf.all.disable_ipv6 = 1\n&#91;root@f36vm ~]# <strong>sysctl -w net.ipv6.conf.default.disable_ipv6=1<\/strong>\nnet.ipv6.conf.default.disable_ipv6 = 1\n&#91;root@f36vm ~]# <strong>nmcli<\/strong>\nenp0s3: connected to Wired connection 1\n        \"Intel 82540EM\"\n        ethernet (e1000), 08:00:27:07:CD:FE, hw, mtu 1500\n        ip4 default\n        inet4 192.168.0.136\/24\n        route4 192.168.0.0\/24 metric 100\n        route4 default via 192.168.0.254 metric 100\n\nlo: unmanaged\n&lt;SNIP><\/code><\/pre>\n\n\n\n<p>It took some time to research this and determine that the file I created was not being read\u2013or at least not processed\u2013by <code>sysctl<\/code> during the Linux startup. Or, if it was, it was being ignored or the settings were being overwritten later by the same variables with different values. After this, I knew that there was no deeper problem preventing it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">About sysctl<\/h3>\n\n\n\n<p>At this point, I looked into the <code>sysctl<\/code> command in more detail. The purpose of the <code>sysctl<\/code> command is to set kernel parameters in the <code>\/proc<\/code> directory. The root user can use it to set individual parameters from the command line. In addition\u2013and this is the key to my solution\u2013you can use it to view and set all of the kernel parameters stored in several locations, including <code>\/etc\/sysctl.conf<\/code> and in files located in <code>\/etc\/sysctl.d<\/code>. The <code>sysctl<\/code> command is used during Linux startup to set the kernel parameters.<\/p>\n\n\n\n<p>I repeat: The system and the sysadmin can use the <code>sysctl<\/code> command to view and set kernel variables while the system is up and running and without a reboot. This command and the power it offers the Linux sysadmin is one of the most significant differences between Linux and other operating systems. It gives us a tool to do things impossible on other operating systems.<\/p>\n\n\n\n<p>I tested this by rebooting the VM and running the following command to set the variables in all locations listed on the <code>sysctl<\/code> man page:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@f36vm ~]# <strong>sysctl --system<\/strong>\n* Applying \/usr\/lib\/sysctl.d\/10-default-yama-scope.conf ...\nkernel.yama.ptrace_scope = 0\n* Applying \/usr\/lib\/sysctl.d\/50-coredump.conf ...\nkernel.core_pattern = |\/usr\/lib\/systemd\/systemd-coredump %P %u %g %s %t %c %h\nkernel.core_pipe_limit = 16\nfs.suid_dumpable = 2\n* Applying \/usr\/lib\/sysctl.d\/50-default.conf ...\nkernel.sysrq = 16\nkernel.core_uses_pid = 1\nnet.ipv4.conf.default.rp_filter = 2\nsysctl: setting key \"net.ipv4.conf.all.rp_filter\": Invalid argument\nnet.ipv4.conf.default.accept_source_route = 0\nsysctl: setting key \"net.ipv4.conf.all.accept_source_route\": Invalid argument\nnet.ipv4.conf.default.promote_secondaries = 1\nsysctl: setting key \"net.ipv4.conf.all.promote_secondaries\": Invalid argument\nnet.ipv4.ping_group_range = 0 2147483647\nnet.core.default_qdisc = fq_codel\nfs.protected_hardlinks = 1\nfs.protected_symlinks = 1\nfs.protected_regular = 1\nfs.protected_fifos = 1\n* Applying \/usr\/lib\/sysctl.d\/50-libkcapi-optmem_max.conf ...\nnet.core.optmem_max = 81920\n* Applying \/usr\/lib\/sysctl.d\/50-libreswan.conf ...\nnet.ipv6.conf.default.accept_redirects = 0\nnet.ipv6.conf.all.accept_redirects = 0\nnet.ipv4.conf.default.send_redirects = 0\nnet.ipv4.conf.default.accept_redirects = 0\nnet.ipv4.conf.all.send_redirects = 0\nnet.ipv4.conf.all.accept_redirects = 0\n* Applying \/usr\/lib\/sysctl.d\/50-pid-max.conf ...\nkernel.pid_max = 4194304\n* Applying \/etc\/sysctl.d\/99-local-network.conf ...\nnet.ipv6.conf.all.disable_ipv6 = 1\nnet.ipv6.conf.default.disable_ipv6 = 1\n* Applying \/etc\/sysctl.d\/99-sysctl.conf ...\n* Applying \/etc\/sysctl.conf ...\n\n&#91;root@f36vm ~]#<\/code><\/pre>\n\n\n\n<p>Checking the status of the NIC with the <code>nmcli<\/code> command showed that IPv6 had been disabled and that IPv4 was still up and running. Yes, I do see the other errors in that data stream, but I am ignoring them for now. Be sure to read the man page for the <code>sysctl<\/code> command as it is quite interesting. It provides a method for processing all <code>sysctl<\/code> configuration files with the <code>--service<\/code> option.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The solution<\/h3>\n\n\n\n<p>Now that I understood the true nature of the problem, I could create a real solution\u2013even if it might be only a temporary circumvention. I was able to do so in a way that is in keeping with the original intent of the Linux startup sequence and the <code>sysctl.d<\/code> method for configuring the kernel.<\/p>\n\n\n\n<p>I left my new configuration file in place in <code>\/etc\/sysctl.d<\/code>. I created the simple Bash script shown below to run the <code>sysctl --system<\/code> command and stored it in <code>\/usr\/local\/bin<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n&lt;SNIP \u2013 discarded a bunch of comments to save space&gt;\nsysctl --system<\/code><\/pre>\n\n\n\n<p>I tested this script multiple times before proceeding to ensure that it worked. If you do this, be sure to test it multiple times, both with and without rebooting, to return to the original kernel configuration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create the service<\/h3>\n\n\n\n<p>The real key to this solution was to create a new <code>systemd<\/code> service that would work similarly to the old <code>rc.local<\/code> SystemV script. In this case, I called it the <code>MyStartup.service<\/code>, and I renamed the script I created above and called it <code>MyStartup.sh<\/code>. To create the service itself, I created a new <code>systemd<\/code> unit file in the <code>\/usr\/local\/lib\/systemd\/system<\/code> directory, which I also had to make. This service will run once at startup. I named this new file <code>MyStartup.service<\/code> and added the following content:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;SNIP \u2013 discarded a bunch of comments to save space&gt;\n&#91;Unit]\nDescription=Runs \/usr\/local\/bin\/MyStartup.sh\n\n&#91;Service]\nExecStart=\/usr\/local\/bin\/MyStartup.sh\n\n&#91;Install]\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p>Note that <code>systemd<\/code> unit files like this one don&#8217;t need to be executable. It is owned by root.root with 664 permissions. It&#8217;s pretty simple to create this service, and I can use it for so many local startup tasks that I plan to keep it even when there is a permanent fix to the extant problem.<\/p>\n\n\n\n<p>The command below enables the new service. Note that the <code>systemctl<\/code> command searches the new directory by default without any options, arguments, or prodding from me to locate the new unit file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@f36vm ~]# <strong>systemctl enable MyStartup.service<\/strong>\nCreated symlink \/etc\/systemd\/system\/multi-user.target.wants\/MyStartup.service \u2192 \/usr\/local\/lib\/systemd\/system\/MyStartup.service.<\/code><\/pre>\n\n\n\n<p>Enabling the service does not run the <code>MyStartup.sh<\/code> script. This service will run the script at every reboot.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Testing<\/h3>\n\n\n\n<p>As soon as the VM rebooted, I logged in as root and ran the following command to check the status of IPv6, but it was still active. After more testing, I determined that the service was running the commands too soon, so I added a command to the <code>MyStartup.sh<\/code> script to sleep for 25 seconds before running the commands. Here is the edited script:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n&lt;SNIP \u2013 discarded a bunch of comments to save space&gt;\n# Wait a bit for things to start up and settle. It doesn't work without this.\nsleep 25\n# Run the sysctl command.\nsysctl --system<\/code><\/pre>\n\n\n\n<p>I rebooted again and verified the status as soon as I could log in, with the result that the service was still sleeping.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@f36vm ~]# <strong>systemctl status MyStartup.service<\/strong>\n\u25cf MyStartup.service - Runs \/usr\/local\/bin\/MyStartup.sh\n     Loaded: loaded (\/usr\/local\/lib\/systemd\/system\/MyStartup.service; enabled; vendor preset: disabled)\n     Active: active (running) since Fri 2022-07-01 13:24:22 EDT; 14s ago\n   Main PID: 667 (MyStartup.sh)\n      Tasks: 2 (limit: 14129)\n     Memory: 592.0K\n        CPU: 1ms\n     CGroup: \/system.slice\/MyStartup.service\n             \u251c\u2500 667 \/bin\/bash \/usr\/local\/bin\/MyStartup.sh\n             \u2514\u2500 669 sleep 25<\/code><\/pre>\n\n\n\n<p>After waiting some additional time, I checked again, and the service had completed successfully, with the results clearly shown in the last few journal entries. Further testing showed that a delay of three seconds works reliably, while a delay of only one second always fails.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Jul 01 13:24:22 f36vm.both.org systemd&#91;1]: Started MyStartup.service - Runs \/usr\/local\/bin\/MyStartup.sh.\n\n&#91;root@f36vm ~]# <strong>systemctl status MyStartup.service<\/strong>\n\u25cb MyStartup.service - Runs \/usr\/local\/bin\/MyStartup.sh\n     Loaded: loaded (\/usr\/local\/lib\/systemd\/system\/MyStartup.service; enabled; vendor preset: disabled)\n     Active: inactive (dead) since Fri 2022-07-01 13:24:47 EDT; 358ms ago\n    Process: 667 ExecStart=\/usr\/local\/bin\/MyStartup.sh (code=exited, status=0\/SUCCESS)\n   Main PID: 667 (code=exited, status=0\/SUCCESS)\n        CPU: 9ms\n\nJul 01 13:24:47 f36vm.both.org MyStartup.sh&#91;1020]: net.ipv4.conf.all.send_redirects = 0\nJul 01 13:24:47 f36vm.both.org MyStartup.sh&#91;1020]: net.ipv4.conf.all.accept_redirects = 0\nJul 01 13:24:47 f36vm.both.org MyStartup.sh&#91;1020]: * Applying \/usr\/lib\/sysctl.d\/50-pid-max.conf ...\nJul 01 13:24:47 f36vm.both.org MyStartup.sh&#91;1020]: kernel.pid_max = 4194304\nJul 01 13:24:47 f36vm.both.org MyStartup.sh&#91;1020]: * Applying \/etc\/sysctl.d\/99-local-network.conf ...\nJul 01 13:24:47 f36vm.both.org MyStartup.sh&#91;1020]: net.ipv6.conf.all.disable_ipv6 = 1\nJul 01 13:24:47 f36vm.both.org MyStartup.sh&#91;1020]: net.ipv6.conf.default.disable_ipv6 = 1\nJul 01 13:24:47 f36vm.both.org MyStartup.sh&#91;1020]: * Applying \/etc\/sysctl.d\/99-sysctl.conf ...\nJul 01 13:24:47 f36vm.both.org MyStartup.sh&#91;1020]: * Applying \/etc\/sysctl.conf ...\nJul 01 13:24:47 f36vm.both.org systemd&#91;1]: MyStartup.service: Deactivated successfully.\n\n&#91;root@f36vm ~]#<\/code><\/pre>\n\n\n\n<p>You can see in the data output above that the configuration statements in the <code>99-sysctl.conf<\/code> file were applied. I also used the <code>nmcli<\/code> command to verify that IPv6 has been disabled.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Automate it<\/h3>\n\n\n\n<p>After figuring out how to consistently accomplish this solution, I added a set of tasks to do this to the Ansible playbook I use to distribute new and updated configuration files. That makes it easy for me to manage my 12 current hosts. I also added it to the playbook I use immediately after performing a basic installation on new hosts or ones that need a reinstallation for some reason. I added the following tasks to those playbooks.<\/p>\n\n\n\n<p>This first set of tasks is for my solution to add a new service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    - name: Install 99-local-network.conf file to disable IPV6\n      copy:\n        src: \/root\/ansible\/system-scripts\/files\/99-local-network.conf\n        dest: \/etc\/sysctl.d\n        mode: 0644\n        owner: root\n        group: root\n\n    - name: Install MyStartup.sh\n      copy:\n        src: \/root\/ansible\/system-scripts\/files\/MyStartup.sh\n        dest: \/usr\/local\/bin\n        mode: 0754\n        owner: root\n        group: root\n\n    - name: create \/root\/ansible\/system-scripts\/files\/ directory\n      file:\n        path: \/root\/ansible\/system-scripts\/files\/\n        state: directory\n        mode: 0755\n        owner: root\n        group: root  \n      \n    - name: Install MyStartup.service\n      copy:\n        src: \/root\/ansible\/system-scripts\/files\/MyStartup.service\n        dest: \/usr\/local\/lib\/systemd\/system\/\n        mode: 0664\n        owner: root\n        group: root\n\n    - name: Enable the MyStartup.service\n      systemd:\n        name: MyStartup.service\n        state: stopped\n        enabled: yes\n\n    - name: Run the raw command to disable IPV4 so a reboot is not required at this time\n      command:\n        cmd: sysctl --system<\/code><\/pre>\n\n\n\n<p>The advantage of this more complex solution of adding the configuration file to the <code>sysctl.d<\/code> directory and then running a playbook with this series of tasks is it disables IPv6 without requiring a reboot.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final thoughts<\/h2>\n\n\n\n<p>Although just installing the file with the correct kernel parameters and rebooting worked fine on one of my hosts, it failed on all of the others I tried. I looked for differences that might explain why it failed on the others while working on my router\/firewall but found nothing that provided a clue as to why this is so. I discovered this problem exists on hosts with newly installed Fedora 36 without any of the changes and post-installation configuration that I always perform and on those with my usual changes. I do plan to keep investigating. I intend to submit a bug report to Red Hat so that there might be an actual fix to this instead of either of these circumventions.<\/p>\n\n\n\n<p>Neither circumvention depends upon the existence of any NIC configuration files\u2014either the old-style interface configuration files that used to be located in <code>\/etc\/sysconfig\/network-scripts<\/code> or the newer NetworkManager interface connection files located in the <code>\/etc\/NetworkManager\/system-connections<\/code> directory. It works with or without those files. The result is global for all network interfaces on the host.<\/p>\n\n\n\n<p>My own solution is a somewhat general approach that you can use in lieu of the old <code>rc.local<\/code> script of the old SystemV startup days.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Resources<\/h3>\n\n\n\n<p>The following resources are kept as current as possible but may not be completely accurate at any given time.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The GRUB manual is available in multiple formats from the <a href=\"https:\/\/www.gnu.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">GNU website<\/a>.<\/li>\n\n\n\n<li>The Fedora documentation website has an excellent page, <a href=\"https:\/\/docs.fedoraproject.org\/en-US\/quick-docs\/bootloading-with-grub2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Bootloading with GRUB2<\/a>.<\/li>\n\n\n\n<li>The Red Hat RHEL 7 online documentation also has a good chapter about working with the GRUB2 boot loader.<\/li>\n\n\n\n<li>The <a href=\"https:\/\/kernel.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">kernel.org<\/a> website has a long list of kernel parameters and a huge amount of other information about the Linux kernel.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Simplify your network by disabling IPv6.<\/p>\n","protected":false},"author":2,"featured_media":3305,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[5,274],"tags":[286,285,287],"class_list":["post-4192","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-networking","tag-grub2","tag-ipv6","tag-sysctl"],"modified_by":"David Both","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/4192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4192"}],"version-history":[{"count":5,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/4192\/revisions"}],"predecessor-version":[{"id":4197,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/4192\/revisions\/4197"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3305"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}