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

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

我似乎無法在 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

產生的結果/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


以下是我在適用於 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 網路配置,因此您應該仍然沒問題。

相關內容