Add IPv6 address to existing IPv4 interface not working

15,264

Your ifup probably doesn't run because the interface already has the IPv4 address and it can't add it twice. It will not even reach the IPv6 line. If you can you should bring the interface down so all addresses are removed, and then bring it up again.

Configuring IPv6 should be done in a different way though:

auto eth1
iface eth1 inet static
    address 192.168.1.2
    netmask 255.255.255.0
    gateway 192.168.1.1

iface eth1 inet6 static
    address 2001:470:28:5b2::1
    netmask 64

You can also add a gateway if you want.

PS: many people don't seem to know, but you can also use netmask 24 for IPv4. You don't have to spell out netmask 255.255.255.0.

Share:
15,264

Related videos on Youtube

Roger Nordqvist
Author by

Roger Nordqvist

Updated on September 18, 2022

Comments

  • Roger Nordqvist
    Roger Nordqvist over 1 year

    Probably a simple answer but I can't seem to find it. I am running a multihomed Debian Stable(latest) and on interface eth1 I need both IPv4 and IPv6 address. My /etc/network/interfaces looks like this:

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    source /etc/network/interfaces.d/*
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    auto eth0
    allow-hotplug eth0
    iface eth0 inet dhcp
    
    auto eth1
    iface eth1 inet static
            address 192.168.1.2
            netmask 255.255.255.0
            gateway 192.168.1.1
            up ip -6 address add 2001:470:28:5b2::1/64 dev $IFACE
    

    The problem is the interface only gets assigned the IPv4 adress, not the IPv6 address. What am I missing?

    When running ifup -av:

    g00nz@debie:~$ sudo ifup -av
    [sudo] password for g00nz:
    run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
    run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
    Configuring interface eth1=eth1 (inet)
    run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
    run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
    ip addr add 192.168.1.2/255.255.255.0 broadcast 192.168.1.255     dev eth1 label eth1
    RTNETLINK answers: File exists
    Failed to bring up eth1.
    run-parts --exit-on-error --verbose /etc/network/if-up.d
    run-parts: executing /etc/network/if-up.d/avahi-daemon
    run-parts: executing /etc/network/if-up.d/mountnfs
    run-parts: executing /etc/network/if-up.d/openssh-server
    run-parts: executing /etc/network/if-up.d/upstart
    run-parts: executing /etc/network/if-up.d/wpasupplicant
    

    It seems that eth1 is already configured and I can't add the IPv6 address but when I do it from bashprompt it works:

    sudo ip -6 addr add 2001:470:28:5b2::1/64 dev eth1
    

    and check with ifconfig eth1:

    g00nz@debie:~$ sudo ip -6 addr add 2001:470:28:5b2::1/64 dev eth1
    g00nz@debie:~$ sudo ifconfig eth1
    eth1      Link encap:Ethernet  HWaddr 00:24:9b:08:4b:aa
              inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: 2001:470:28:5b2::1/64 Scope:Global
              inet6 addr: fe80::224:9bff:fe08:4baa/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:4254 errors:0 dropped:2080 overruns:0 frame:0
              TX packets:305 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:469773 (458.7 KiB)  TX bytes:45395 (44.3 KiB)
    

    Anyone? :(

    /roger


    OK, tried this and got this in my /etc/network/interfaces now:

    auto eth1
    iface eth1 inet static
            address 192.168.1.2
            netmask 255.255.255.0
            gateway 192.168.1.1
    
    iface eth1 inet6 static
            address 2001:470:28:5b2::1
            netmask 64
    

    But still, when I check with ip a I have:

    3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:24:9b:08:4b:aa brd ff:ff:ff:ff:ff:ff
        inet 192.168.1.2/24 brd 192.168.1.255 scope global eth1
           valid_lft forever preferred_lft forever
        inet6 fe80::224:9bff:fe08:4baa/64 scope link
           valid_lft forever preferred_lft forever
    

    I does not stick :(

    Still get error with ifup:

    g00nz@debie:~$ sudo ifup -av
    [sudo] password for g00nz:
    run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
    run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
    Configuring interface eth1=eth1 (inet)
    run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
    run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
    ip addr add 192.168.1.2/255.255.255.0 broadcast 192.168.1.255     dev eth1     label eth1
    RTNETLINK answers: File exists
    Failed to bring up eth1.
    run-parts --exit-on-error --verbose /etc/network/if-up.d
    run-parts: executing /etc/network/if-up.d/avahi-daemon
    run-parts: executing /etc/network/if-up.d/mountnfs
    run-parts: executing /etc/network/if-up.d/openssh-server
    run-parts: executing /etc/network/if-up.d/upstart
    run-parts: executing /etc/network/if-up.d/wpasupplicant
    g00nz@debie:~$
    
    • xhienne
      xhienne over 7 years
      Can you add a down line, with the opposite ip -6 addr del command, force an ifdown and see if an ifup works better? Or retry your ifup after removing manually your ipv6 addr if ip -6 addr del. Forcing an ifdown is better.
  • rustyx
    rustyx over 5 years
    You can also just specify netmask as a suffix in the address: address 192.168.1.2/24