Astra linux disable ipv6

Linux disable IPv6 properly (with or without reboot)

In this tutorial I will share the steps required to disable IPv6 completely from your Linux server. There are couple of methods to achieve this requirement, I will share the ones which I am familiar with. Normally we disable IPv6 in the network but we somehow miss to update this on other dependent configuration files such as /etc/hosts , sshd_config file etc. So it is important that you update all the dependent configuration files to not use IPv6 any more.

You may also read my previous article to configure IPv6 address in Linux.

Method-1: Linux Disable IPv6 using grubby (Requires reboot)

In this example we will use grubby command to update the kernel boot entries and disable IPv6. grubby command is very user friendly and can be used for automation via scripts. We will use below command to update the kernel arguments of the DEFAULT kernel with ipv6.disable=1 . This parameter will make sure that IPv6 is disabled on the next reboot.

# grubby --args ipv6.disable=1 --update-kernel DEFAULT

Verify the updated entries of kernel arguments on the default kernel

Below is a snippet from my server terminal

Disable IPv6 using GRUBBY

Next reboot the server and post reboot check the output for below command

You should get empty output which means that all the ipv6 modules are unloaded from the kernel

Next go to the last section of this tutorial to disable IPv6 across different configuration files

Method-2: Linux disable IPv6 using GRUB2 configuration (Requires Reboot)

In this section we will use GRUB2 configuration to disable IPv6 completely. You need to append ipv6.disable=1 at the end of line with GRUB_CMDLINE_LINUX in /etc/default/grub file. You can use below sed for this purpose as I have used below or manually open the file using any editor and append:

# sed -i '/GRUB_CMDLINE_LINUX/ s/"$/ ipv6.disable=1"/' /etc/default/grub

Now verify if ipv6.disable=1 was properly added:

# grep ipv6 /etc/default/grub GRUB_CMDLINE_LINUX color: #00ff00;">ipv6.disable=1"

Next rebuild your grub2 configuration file:

Читайте также:  Запуск файла командной строки linux

Below command is for legacy BIOS, on UEFI-based machines: ~]# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file . done

Next reboot your server and check the output for below command

You should get empty output which means that all the ipv6 modules are unloaded from the kernel

Next go to the last section of this tutorial to disable IPv6 across different configuration files

Method-3: Linux disable IPv6 using sysctl (Without Reboot)

This is another method to disable IPv6 but in this case we don’t unload the IPv6 modules as we did with above methods, instead we will just disable IPv6 so that it cannot be configured or used.

This method may break SSH Xforwarding unless sshd_config contains AddressFamily inet. So if you are planning to use this method and are also using XForwarding then it is strongly recommended to add » AddressFamily inet » in /etc/ssh/sshd_config and restart the sshd service

Before I start, you can check that currently an inet6 address is assigned to my eth0 interface

How to disable Ipv6 in Linux

To disable IPv6 runtime, append 1 to the below sysctl configuration files

# echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6 # echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6

Next you can verify, you will not see inet6 when you list the available interfaces and their IP addresses with ip a command

how to disable ipv6

As you see, there is no inet6 interface for eth0 anymore.

So IPv6 is disabled without any reboot. But these changes are not persistent across reboot so to make it permanent we need to add these to sysctl configuration file. Create a new config file inside /etc/sysctl.d/ and add below lines

# cat /etc/sysctl.d/98-disable_ipv6.conf net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1

In some cases you may have to also add net.ipv6.conf..disable_ipv6 = 1 in this file. Replace with all the interface from your Linux server, for example: eth0, eth1 etc

Next execute sysctl -p to update the configuration (anyhow since we have manually added 1 to these entries earlier, you may skip this step)

# sysctl -p /etc/sysctl.d/98-disable_ipv6.conf net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1

Create a backup of the initramfs:

# cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).bak.$(date +%m-%d-%H%M%S).img

Then rebuild the Initial RAM Disk Image using, this command may give a long list of output on the screen:

Verify the content of initramfs to make sure the newly added sysctl configuration file is part of the initramfs

# lsinitrd /boot/initramfs-$(uname -r).img | grep 'etc/sysctl.d/98-disable_ipv6.conf' -rw-r--r-- 1 root root 75 Sep 6 2019 etc/sysctl.d/98-disable_ipv6.conf

Now even if your server is rebooted, the IPv6 changes will be persistent across reboot.

Lastly go to the next section of this tutorial to disable IPv6 across different configuration files

4. Post Action — Disable IPv6 across Linux configuration files

Now since you have disabled IPv6 in the network, you should also consider to disable the same across multiple Linux configuration files or you may get different errors reported on your Linux server.

Читайте также:  Linux kernel build header

4.1: In /etc/hosts

Comment out any IPv6 addresses found in /etc/hosts, including ::1 localhost address

# cp -p /etc/hosts /etc/hosts.disableipv6 # sed -i 's/^[[:space:]]*::/#::/' /etc/hosts

4.2: In /etc/ssh/sshd_config

As informed earlier if problems with X forwarding are encountered on systems with IPv6 disabled, edit /etc/ssh/sshd_config and make either of the following changes:
Change the line

# systemctl restart sshd.service

4.3: In Postfix (/etc/postfix/main.cf)

If you are using postfix then you should also make these changes in the /etc/postfix/main.cf and comment out the localhost part of the config and use ipv4 loopback.

#inet_interfaces = localhost inet_interfaces = 127.0.0.1
# systemctl restart postfix

4.4: In /etc/ntp.conf

If you are using legacy ntp.conf to sync your local time with NTP server then comment the line related to IPV6 in /etc/ntp.conf

Next restart ntpd service

4.5: In /etc/netconfig

To disable RPCBIND ipv6 (rpcbind, rpc.mountd, prc.statd) remark out the udp6 and tcp6 lines in /etc/netconfig:

udp tpi_clts v inet udp - - tcp tpi_cots_ord v inet tcp - - #udp6 tpi_clts v inet6 udp - - #tcp6 tpi_cots_ord v inet6 tcp - - rawip tpi_raw - inet - - - local tpi_cots_ord - loopback - - -

You don’t need to restart any service and the changes will take affect runtime.

4.6: In chrony

If you are using chrony instead of NTP to sync your local server with Network timezone, then to disable chronyd service on a upd6 socket create /etc/sysconfig/chronyd file using any text editor, with line below:

# systemctl restart chronyd

You can verify the same using netstat to lists chronyd process listening on udp6

# netstat -plan | egrep 'tcp6|udp6'

Conclusion

In this tutorial we learned about how we can disable IPv6 properly across all the relevant configuration files and network. You can achieve this with or without reboot. Although in most environment I have observed issues when I disabled IPv6 using sysctl as the the module is still loaded on the server so some application may fail to work or throw error so I prefer to completely unload the ipv6 module from the Linux server to avoid any conflicts.

References

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

4 thoughts on “Linux disable IPv6 properly (with or without reboot)”

sed '/GRUB_CMDLINE_LINUX/ s/"$/ ipv6.disable=1"/' /etc/default/grub

That doesn’t actually output to the file. Just displays the modification Should be something similar to

sed '/GRUB_CMDLINE_LINUX/ s/"$/ ipv6.disable=1"/' /etc/default/grub > /etc/default/grub

Thanks for highlighting this, I missed -i argument to do infile changes. I have updated the command Reply

# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file . done

On RHEL/CentOS and similar distribution we use grub2-mkconfig
On Ubuntu/Debian we have grub-update or grub2-update . Reply

Читайте также:  Linux узнать mac адрес сетевой карты

Источник

Отключить IPv6 на Linux

Если адреса IPv6 не используется на компьютере или сервере с Linux, то стоит отключить их функционал совсем. Это необходио для обеспечения безопасности. Потому что можно забыть настроить правило фаервола для IPv6, сделав это для IPv4.

Отключение IPv6 на работающей системе

Для отключения поддержки IPv6 в системе необходимо перейти в файл конфигурации /etc/sysctl.conf от лица суперпользователя и прописать в конце файла следующие строки:

# IPv6 disabled net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1
$ sysctl net.ipv6.conf.all.disable_ipv6 net.ipv6.conf.all.disable_ipv6 = 1 $ sysctl net.ipv6.conf.default.disable_ipv6 net.ipv6.conf.default.disable_ipv6 = 1 $ sysctl net.ipv6.conf.lo.disable_ipv6 net.ipv6.conf.lo.disable_ipv6 = 1

Если после каждого запроса возвращается строка с «= 1«, то это означает, что для ядра ОС выставлены параметры, которые не позволяют использовать протокол IPv6.

Обратите внимание, что внесённые изменения в файл настройки будут читаться системой каждый раз во время загрузки. Поэтому IPv6 будет отключена всегда (перезагрузка не сбросит значения). Если нужно отключить IPv6 только для текущего сеанса, то необходимо не менять файл, а выполнить такие три команды:

sysctl -w net.ipv6.conf.all.disable_ipv6 sysctl -w net.ipv6.conf.default.disable_ipv6 sysctl -w net.ipv6.conf.lo.disable_ipv6

Отключение ipv6 из автозагрузки

Чтобы не утруждать систему загрузкой библиотек для работы с IPv6 можно отключить их на стадии старта системы. Делается это с помощью передачи параметра загрузчику GRUB. Для этого необходимо открыть от лица суперпользователя файл /etc/default/grub и добавить параметр ipv6.disable=1 в следующие ключи:

GRUB_CMDLINE_LINUX_DEFAULT GRUB_CMDLINE_LINUX 

Источник

Как отключить IP версии 6 в Linux

Обновлено

Обновлено: 16.05.2020 Опубликовано: 23.03.2019

IPv6 далеко не всегда может использоваться в системе. Более того, он может вызвать некоторые проблемы при обращении к локальной петле (127.0.0.1) — запросы могут пойти на адрес ::1, что может привести к тому, что некоторые приложения будут работать не корректно.

В данной инструкции используются универсальные методы, которые подойдут для различных систем, например, Ubuntu, CentOS, Debian, Red Hat и так далее.

Отключение через ядро Linux

Быстрее всего отключить IPv6 через настройку ядра. Это универсальный способ и он подойдет для многих дистрибутивов на базе Linux.

Глобально (для всех интерфейсов)

Создаем или открываем файл:

* 99-sysctl.conf является основным конфигурационным файлом, а 10-ipv6-privacy.conf в каталоге sysctl.d — дополнительным. Для удобства лучше использовать последний.

Добавляем следующие строки:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

Если вносили изменения в файл /etc/sysctl.d/99-sysctl.conf:

Если вносили изменения в файл /etc/sysctl.d/10-ipv6-privacy.conf:

sysctl -p /etc/sysctl.d/10-ipv6-privacy.conf

Проверяем — должны остаться только адреса IPv4:

Для определенного интерфейса

Если нужно отключить IPv6 только для одного интерфейса, например, для eth0, также открываем настройку ядра.

Источник

Оцените статью
Adblock
detector