Disable IPv6 on CentOS7

There are 2 ways to do this :
1. Disable IPv6 in kernel module (requires reboot)
2. Disable IPv6 using sysctl settings (no reboot required)

To verify if IPv6 is enabled or not, execute :

# ifconfig -a | grep inet6

1 Disable IPv6 in kernel module (requires reboot)

1.1 Edit /etc/default/grub and add ipv6.disable=1 in line GRUB_CMDLINE_LINUX, e.g.:

# cat /etc/default/grub

GRUB_TIMEOUT=5

GRUB_DEFAULT=saved

GRUB_DISABLE_SUBMENU=true

GRUB_TERMINAL_OUTPUT=”console”

GRUB_CMDLINE_LINUX=”ipv6.disable=1 crashkernel=auto rhgb quiet”

GRUB_DISABLE_RECOVERY=”true”

1.2 Regenerate a GRUB configuration file and overwrite existing one:

# grub2-mkconfig -o /boot/grub2/grub.cfg

1.3 Restart system and verify no line “inet6” in “ifconfig” command output.

# shutdown -r now

# ifconfig -a | grep inet6

2 Disable IPv6 using sysctl settings (no reboot required)

2.1 Append below lines in /etc/sysctl.conf:

net.ipv6.conf.all.disable_ipv6 = 1

net.ipv6.conf.default.disable_ipv6 = 1

NOTE : To disable IPv6 on a single interface add below lines to /etc/sysctl.conf :

net.ipv6.conf.[interface].disable_ipv6 = 1 ### put interface name here [interface]

net.ipv6.conf.default.disable_ipv6 = 1

2.2 To make the settings affective, execute :

# sysctl -p

2.3 Add the AddressFamily line to sshd_config :

# vi /etc/ssh/sshd_config

….

AddressFamily inet

….

Restart sshd for changes to get get effect :

# systemctl restart sshd

NOTE : make sure the file /etc/ssh/sshd_config contains the line AddressFamily inet to avoid breaking SSH Xforwarding if you are using the sysctl method