36

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.

1

6 Answers 6

50

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.

4
  • 4
    FYI for those looking to disable all, not just one interface, simply replace "eth0" with "all"
    – Peter
    Jan 20, 2015 at 10:02
  • 3
    Actually, instead of modifying /etc/sysctl.conf, create a file in /etc/sysctl.d named for example 00_ipv6_off.conf with the above contents. ifconfig will then show interfaces bereft of IPv6 functionality. Dec 17, 2018 at 13:03
  • 1
    In one line: echo "net.ipv6.conf.eth0.disable_ipv6 = 1" > /etc/sysctl.d/00_ipv6_off.conf Jan 22, 2019 at 16:30
  • 1
    While the sysctl command works for me, adding the file in sysctl.d does not work. When the system reboots, net.ipv6.conf.ens32.disable_ipv6 is still 0 when running the sysctl command to check. I am on Ubuntu 20.04 LTS.
    – bfrguci
    Jan 6, 2022 at 17:30
17

Let the interface name be stored in the iface variable (must be adapted to your situation) :

$ iface=eth0

Then the command is :

$ sudo sysctl -w net.ipv6.conf.$iface.disable_ipv6=1

deprecates

# echo 1 > /proc/sys/net/ipv6/conf/$iface/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.$iface.disable_ipv6=1

To check if the change was kept (especially after reboot) :

$ sysctl -n net.ipv6.conf.$iface.disable_ipv6
1
6

One way to temporally remove the ipv6 on an interface is: (it will come back after reboot)

ip -6 addr flush eth0

1
  • 1
    This is great for me, I had one host (the proxmox apt repo) that was slow on ipv6 so just needed it gone for one session. Thanks!
    – trisweb
    Aug 10 at 17:56
4

You should be root to set network parameter below:

echo 1 > /proc/sys/net/ipv6/conf/wlan0/disable_ipv6
1
  • This will work in installers as well, if a debian installer is getting stuck at detect network settings. Go to console (alt+2), and type this command. Go back to the installer. Press Ctrl+C to exit the detection, and re-initialize the detection of the network.
    – lsu_guy
    Aug 4, 2019 at 5:57
3

The use of the following variables in ifcfg-eth0 or ifcfg-eth1:

IPV6INIT=no
IPV6_AUTOCONF=no

Should do the trick. To reiterate:

/etc/sysconfig/network

NETWORKING_IPV6=yes
IPV6_AUTOCONF=yes

/etc/sysconfig/network-scripts/ifcfg-eth0

IPV6INIT=no
IPV6_AUTOCONF=no

/etc/sysconfig/network-scripts/ifcfg-eth0

IPV6INIT=yes
IPV6_AUTOCONF=yes

Then make sure you restart the networking service:

% /etc/init.d/network restart

If you run ifconfig you should see inet6 on the ethernet device (either eth0 or eth1) that has ipv6 enabled.

% ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 01:26:BD:85:CA:30  
          inet addr:192.168.1.20  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::226:c7ff:fe85:a720/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2497072 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2253781 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2004576667 (1.8 GiB)  TX bytes:1296051472 (1.2 GiB)
2
  • Yes, it's a little weird. Setting "net.ipv6.conf.eth0.disable_ipv6 = 1 " is a good solution. Thanks for your answer.
    – Yves Messi
    Apr 1, 2013 at 6:10
  • 1
    Hmmmm, didn't do squat on my system (RH 6.5 X86_64 on a virtualized environment.) Good to know those for those systems where it works, though. Sep 17, 2014 at 18:39
0

sudo vi /etc/modprobe.d/ipv6.conf

# add following line 
options ipv6 disable=1

sudo reboot

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .