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

Ara*_*anu 5 fedora ipv6 amazon-ec2 cloud-init dhcpv6

我似乎无法在 Amazon EC2 的 Fedora 28 中使用 IPv6(因此使用 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
Run Code Online (Sandbox Code Playgroud)

生成的/etc/sysconfig/network是:

NOZEROCONF=yes
DEVTIMEOUT=10

# Created by cloud-init on instance boot automatically, do not edit.
#
NETWORKING=yes
Run Code Online (Sandbox Code Playgroud)

生成的/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
Run Code Online (Sandbox Code Playgroud)

我的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
Run Code Online (Sandbox Code Playgroud)

操作系统版本:

[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 ~]$ 
Run Code Online (Sandbox Code Playgroud)

小智 6

这是因为目前的云版本的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.
Run Code Online (Sandbox Code Playgroud)

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

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


以下是我为 Fedora 28(云版)在 Amazon EC2 上的现有实例上启用 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 网络配置,因此您应该仍然可以。