Disable IPv6 in linux
When some devices of your network don’t support IPv6 (like your ISP routers!), then it’s probably better to disable IPv6 on your linux hosts.
It’s worth noting that some applications might have some issues when disabling IPv6, so some additional configuration might be needed, please read the caveats section below.
Here’s how to disable IPv6:
TO DISABLE TEMPORARILY (won’t persist after a reboot)
Execute the following from the command line (as root):
# echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6 # echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
In case you want to temporarily re-enable IPv6, substitute echo 1 with echo 0 in the previous commands
TO DISABLE PERMANENTLY (persist across reboots)
1. Add the following lines at the end of /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1
2. Execute the following (as root):
sysctl -p
To re-enable again IPv6, remove the added lines from /etc/sysctl.conf and run again sysctl -p
TO GIVE PRECEDENCE TO IPv4 TRAFFIC
In case you don’t want to disable IPv6, you can configure your host to always prefer and try an IPv4 connection before attempting IPv6:
1. Make sure this line from /etc/gai.conf is uncommented (or add it if not present):
precedence ::ffff:0:0/96 100
2. Reboot
CAVEATS
Disable IPv6 might introduce subtle malfunctioning in some applications, for example:
– SSH
When using X11 Forwarding with ssh, disabling IPv6 might break this functionality and you’ll get a warning message like this when logging in:
$ ssh -X toshiro@server X11 forwarding request failed on channel 0 Last login: Fri Dec 16 09:52:54 2016 from toshiro.biz toshiro@server $
In order to fix it, add the following to /etc/ssh/sshd_config
:
AddressFamily inet
– POSTFIX
Postfix might not start correctly when IPv6 is disabled. To fix this, edit /etc/postfix/main.cf
:
replace:
inet_interfaces = localhost
with:
inet_interfaces = 127.0.0.1
Leave a Reply