将 IPv6 地址添加到现有 IPv4 接口不起作用

将 IPv6 地址添加到现有 IPv4 接口不起作用

可能是一个简单的答案,但我似乎找不到它。我正在运行多宿主 Debian Stable(最新),并且在接口 eth1 上我需要 IPv4 和 IPv6 地址。我的 /etc/network/interfaces 看起来像这样:

# 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

问题是接口只分配了 IPv4 地址,而不是 IPv6 地址。我缺少什么?

跑步时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

似乎 eth1 已配置,我无法添加 IPv6 地址,但当我从 bashprompt 执行此操作时,它可以工作:

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

并检查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)

任何人? :(

/罗杰


好的,尝试一下,现在将其添加到我的 /etc/network/interfaces 中:

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

但是,当我检查时ip 一个我有:

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

我不坚持:(

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:~$

答案1

您的ifup程序可能无法运行,因为接口已经具有 IPv4 地址并且无法添加两次。它甚至不会到达 IPv6 线路。如果可以的话,您应该关闭该接口,以便删除所有地址,然后再次打开它。

配置 IPv6 应该以不同的方式完成:

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

如果需要,您还可以添加网关。

PS:很多人好像不知道,其实netmask 24IPv4也可以用。你不必拼写出来netmask 255.255.255.0

相关内容