
IPv6 may be undesirable in certain situations, for systems that can run without IPv6, and only running on IPv4, the IPv6 protocol can be disabled.
On Red Hat and CentOS 7 the IPv6 stack can be disabled as follows
1 2 3 4 5 |
vi /etc/sysctl.conf net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 |
If one interface should run without IPv6, e.g. ens160.
1 2 |
net.ipv6.conf.ens160.disable_ipv6 = 1 |
Save the sysctl.conf file and enable the setting.
1 2 |
sysctl -p |
If you want to deactivate IPv6 during operation, the following command applies.
1 2 3 4 5 6 7 8 |
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6 echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6 Or sysctl -w net.ipv6.conf.all.disable_ipv6=1 sysctl -w net.ipv6.conf.default.disable_ipv6=1 |
IPv6 is now disabled, a reboot is not necessary.
If the removal of IPv6 for running daemons is a disaster, e.g. SSH Server, the configuration can be changed.
1 2 3 4 5 6 7 8 9 10 |
vi /etc/ssh/sshd_config #AddressFamily any AddressFamily inet or hash() remove. #ListenAddress 0.0.0.0 ListenAddress 0.0.0.0 |
Then restart the SSH daemon.
1 2 |
systemctl restart sshd |
Postfix may also require to customize the ipv4 loopback interface.
1 2 3 4 5 |
vi /etc/postfix/main.cf #inet_interfaces = localhost inet_interfaces = 127.0.0.1 |
With CentOS 6, the kernel module can be customized.
1 2 3 4 |
vi /etc/modprobe.d/ipv6.conf options ipv6 disable=1 |
Disable the IPv6 stack.
1 2 |
chkconfig ip6tables off |
Server reboots.
1 2 |
reboot |
Checking for IPv6 addresses.
1 2 3 4 |
ifconfig | grep inet6 CentOS7 ip a | grep inet6 |