在新创建的 rhel9 VM 中,环回接口不包含 IPv6 地址,但/etc/hosts
包含::1
localhost 条目
[vagrant@el9-test-fd5843e6 ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:02:41:69 brd ff:ff:ff:ff:ff:ff
altname enp0s3
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute eth0
valid_lft 85325sec preferred_lft 85325sec
inet6 fe80::a00:27ff:fe02:4169/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[vagrant@el9-test-fd5843e6 ~]$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 rhel9.localdomain
如何为环回接口配置 IPv6 地址?作为参考,我使用以下 vagrant box 对此进行了测试https://app.vagrantup.com/generic/boxes/rhel9
答案1
这与 RHEL 9 无关。您使用的 Vagrant 映像明确禁用了 IPv6;看一下/etc/sysctl.conf
:
[root@node1 sysctl.d]# cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv6.conf.all.disable_ipv6 = 1
删除或注释掉该行并重新启动(或直接运行sysctl -w net.ipv6.conf.all.disable_ipv6=0
),然后就一切就绪了。只需将sysctl
结果更改为:
[root@node1 sysctl.d]# ip -6 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 state UNKNOWN qlen 1000
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
inet6 fe80::5054:ff:fe62:ca84/64 scope link
valid_lft forever preferred_lft forever