如何在 Amazon EC2 上的 Fedora 28 上启用 IPv6

如何在 Amazon EC2 上的 Fedora 28 上启用 IPv6

我似乎无法让 IPv6 在 Amazon EC2 中的 Fedora 28 中运行(因此使用 cloud-init 和 DHCPv6)。

它在 RHEL 7 中运行,配置如下这里。将相同的配置应用于 Fedora 28 似乎没有任何效果。特别/etc/sysconfig/network不是被重写为包含NETWORKING_IPV6=yes,也不/etc/sysconfig/network-scripts/ifcfg-eth0包含任何IPv6内容。

我的/etc/cloud/cloud.cfg.d/56-custom-networking.cfg包含:

network:
  version: 1
  config:
  - type: physical
    name: eth0
    subnets:
      - type: dhcp
      - type: dhcp6

生成的/etc/sysconfig/network是:

NOZEROCONF=yes
DEVTIMEOUT=10

# Created by cloud-init on instance boot automatically, do not edit.
#
NETWORKING=yes

生成的/etc/sysconfig/network-scripts/ifcfg-eth0是:

# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=dhcp
DEVICE=eth0
HWADDR=0e:79:0a:22:60:26
ONBOOT=yes
TYPE=Ethernet
USERCTL=no

我的ifconfig -a

[aram@eden ~]$ ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 172.31.35.163  netmask 255.255.240.0  broadcast 172.31.47.255
        inet6 fe80::c79:aff:fe22:6026  prefixlen 64  scopeid 0x20<link>
        ether 0e:79:0a:22:60:26  txqueuelen 1000  (Ethernet)
        RX packets 498  bytes 45355 (44.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 332  bytes 38967 (38.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

操作系统版本:

[aram@eden ~]$ cat /etc/os-release 
NAME=Fedora
VERSION="28 (Cloud Edition)"
ID=fedora
VERSION_ID=28
PLATFORM_ID="platform:f28"
PRETTY_NAME="Fedora 28 (Cloud Edition)"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:fedoraproject:fedora:28"
HOME_URL="https://fedoraproject.org/"
SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=28
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=28
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="Cloud Edition"
VARIANT_ID=cloud
[aram@eden ~]$ 

答案1

发生这种情况的原因是,当前的 cloud-init 版本(我测试的是 17.1)不是每次启动时重新生成网络设置。网络设置仅在第一次启动时生成。您可以通过登录 cloud-init 的日志文件来观察这一点:

$ grep 'network config' /var/log/cloud-init.log

2018-09-18 22:13:26,089 - stages.py[INFO]: Applying network configuration from ds bringup=False: {'version': 1, 'config': [{'type': 'physical', 'name': 'eth0', 'subnets': [{'type': 'dhcp4'}], 'mac_address': '12:64:78:dd:c8:62'}]}
2018-09-18 22:13:29,211 - stages.py[DEBUG]: not a new instance. network config is not applied.
2018-09-26 10:08:08,367 - stages.py[DEBUG]: not a new instance. network config is not applied.
2018-09-26 10:08:11,458 - stages.py[DEBUG]: not a new instance. network config is not applied.
2018-09-26 11:01:12,917 - stages.py[DEBUG]: not a new instance. network config is not applied.
2018-09-26 11:01:16,011 - stages.py[DEBUG]: not a new instance. network config is not applied.
2018-09-26 11:10:38,782 - stages.py[DEBUG]: not a new instance. network config is not applied.
2018-09-26 11:10:41,871 - stages.py[DEBUG]: not a new instance. network config is not applied.
2018-09-26 11:12:10,407 - stages.py[DEBUG]: not a new instance. network config is not applied.
2018-09-26 11:12:13,475 - stages.py[DEBUG]: not a new instance. network config is not applied.

如您所见,网络配置仅在首次启动时应用(当时实例还没有 IPV6)。

存在一个要求使此行为可配置的问题:https://bugs.launchpad.net/cloud-init/+bug/1765801


以下是我在 Amazon EC2 上现有 Fedora 28(云版本)实例上启用 IPV6 所采取的步骤:

  1. 添加NETWORKING_IPV6=yes/etc/sysconfig/network
  2. 添加DHCPV6C=yes/etc/sysconfig/network-scripts/ifcfg-eth0
  3. 跑步sudo systemctl restart network

完成这些步骤后,IPV6 已启用,并且重启后仍会保留。但是,如果出于某种原因重新创建了实例,并且 cloud-init 认为这是首次再次启动,则更改将丢失。但是,cloud-init 已经生成了开箱即用的 IPV6 网络配置,因此您仍然应该没问题。

相关内容