How to disable ipv6 on a specific interface in Linux?
Could someone tell me how to disable ipv6 auto-config on a specific network interface in CentOS?
The current situation is:
A PC has two network adapters eth0 and eth1 that are connecting to the same LAN, in which, IPv6 router is advertising an IPv6 prefix with NDRA (Neighbor Discovery Router Advertisements) packet. As a result, both eth0 and eth1 are configuring the IPv6 address with that prefix automatically.
But, I just want to enable ipv6 on eth1 and disable it on eth0. I've tried the following methods, but they don't work.
1. /etc/sysconfig/network
NETWORKING_IPV6=no
IPV6_AUTOCONF=no
This will disable ipv6 on both eth0 and eth1.
2. /etc/sysconfig/network-scripts/ifcfg-eth0
IPV6INIT=no
IPV6_AUTOCONF=no
Then, it doesn't work. I have restarted the network service already.
Solution 1:
You can disable it from /etc/sysctl.conf with this line:
net.ipv6.conf.eth0.disable_ipv6 = 1
Take a look at /proc/sys/net/ipv6/conf/eth0. There are many options you can set in that directory, like leaving IPv6 enabled but disabling autoconf etc.
Solution 2:
$ sudo sysctl -w net.ipv6.conf.eth0.disable_ipv6=1
deprecates
# echo 1 > /proc/sys/net/ipv6/conf/eth0/disable_ipv6
In order to ensure that this change persists across reboots, you'll want to add this line to your /etc/sysctl.conf
file:
net.ipv6.conf.eth0.disable_ipv6=1
Note that using the /etc/sysconfig/network-scripts/ifcfg-eth0
file is non-portable.