[root@servera ~]# dhcpd -t Internet Systems Consortium DHCP Server 4.3.6 Copyright 2004-2017 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ ldap_gssapi_principal is not set,GSSAPI Authentication for LDAP will not be used Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file Config file: /etc/dhcp/dhcpd.conf Database file: /var/lib/dhcpd/dhcpd.leases PID file: /var/run/dhcpd.pid Source compiled to use binary-leases
[root@serverb ~]# ip a s eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:01:fa:0b brd ff:ff:ff:ff:ff:ff inet 172.25.250.100/24 brd 172.25.250.255 scope global dynamic noprefixroute eth1 valid_lft 595sec preferred_lft 595sec inet6 fe80::51d6:1bf5:3111:5ae5/64 scope link noprefixroute valid_lft forever preferred_lft forever
[root@serverb ~]# nmcli connection down dhcptest ;nmcli connection up dhcptest [root@serverb ~]# ip a s eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:01:fa:0b brd ff:ff:ff:ff:ff:ff inet 172.25.250.110/24 brd 172.25.250.255 scope global dynamic noprefixroute eth1 valid_lft 597sec preferred_lft 597sec inet6 fe80::51d6:1bf5:3111:5ae5/64 scope link noprefixroute valid_lft forever preferred_lft forever
配置 IPv6 地址分配
IPv6 地址自动配置概述
IPv6 具有多个可用于配置网络接口的方法。
无状态地址自动配置 (SLAAC)
适用于 IPv6 的动态主机配置协议 (DHCPv6)
两者都要依赖于自动配置的本地链路地址才能发挥作用。
无状态地址自动配置 (SLAAC)
无状态地址自动配置 (SLAAC) 方法依赖于路由器为客户端系统提供网络配置。这可能包括 IPv6 网络的前缀(客户端可以使用它来创建地址)和 DNS 信息。对于这种方法,必须在路由器上激活和配置邻居发现协议 (NDP)。路由器公告消息仅提供网络前缀
[客户端系统启动或连接到 IPv6 网络] | v [生成基于 MAC 地址的 EUI-64 接口标识符] | v [使用本地链路地址发送路由器请求消息到 ff02::2] | v [路由器接收到请求后发送路由器公告消息(包含网络前缀等参数)] | v [客户端使用网络前缀和 EUI-64 生成全局单播地址] | v [进行地址冲突检测(DAD)] | v [如果 DAD 成功,客户端使用该地址进行通信] | v [如果 DAD 失败,客户端生成新的地址并重新进行 DAD] | v [路由器定期发送路由器公告消息以更新网络配置和宣告存在] | v [客户端根据路由器公告更新网络配置]
[root@host1 ~]# radvdump # # radvd configuration generated by radvdump 2.19 # based on Router Advertisement from fe80::20c:29ff:fea7:41b5 # received by interface ens160 #
prefix 2001:db8:1::/64 { AdvValidLifetime 86400; AdvPreferredLifetime 14400; AdvOnLink on; AdvAutonomous on; AdvRouterAddr off; }; # End of prefix definition
}; # End of interface definition
路由器提供了前缀之后,我们来看看IPV6地址,成功具有正确前缀的IPV6地址
1 2 3 4 5 6 7 8 9 10
[root@host1 ~]# ip a s ens160 2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:a7:41:b5 brd ff:ff:ff:ff:ff:ff altname enp3s0 inet 192.168.8.100/24 brd 192.168.8.255 scope global noprefixroute ens160 valid_lft forever preferred_lft forever inet6 2001:db8:1:0:20c:29ff:fea7:41b5/64 scope global dynamic noprefixroute valid_lft 86383sec preferred_lft 14383sec inet6 fe80::20c:29ff:fea7:41b5/64 scope link noprefixroute valid_lft forever preferred_lft forever
也成功提供了网关信息
1 2 3 4
[root@host1 ~]# ip -6 route ::1 dev lo proto kernel metric 256 pref medium 2001:db8:1::/64 dev ens160 proto ra metric 100 pref medium fe80::/64 dev ens160 proto kernel metric 1024 pref medium
[root@host1 ~]# radvdump # # radvd configuration generated by radvdump 2.19 # based on Router Advertisement from fe80::20c:29ff:fea7:41b5 # received by interface ens160 #
[root@servera ~]# nmcli con add con-name lxhdhcpv6 type ethernet \ ifname eth1 ipv6.addresses fde2:6494:1e09:2::a/64 ipv6.method manual [root@servera ~]# nmcli con up lxhdhcpv6
确认地址配置完成
1 2 3 4 5 6
[root@servera ~]# ip -6 a s eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000 inet6 fde2:6494:1e09:2::a/64 scope global noprefixroute valid_lft forever preferred_lft forever inet6 fe80::a5:8862:cccb:2607/64 scope link noprefixroute valid_lft forever preferred_lft forever
[root@servera ~]# yum install radvd -y [root@servera ~]# radvdump # # radvd configuration generated by radvdump 2.17 # based on Router Advertisement from fe80::ef0:1eaf:de3b:7a88 # received by interface eth1 #
interface eth1 { AdvSendAdvert on; # Note: {Min,Max}RtrAdvInterval cannot be obtained with radvdump AdvManagedFlag on; AdvOtherConfigFlag on; AdvReachableTime 0; AdvRetransTimer 0; AdvCurHopLimit 64; AdvDefaultLifetime 180; AdvHomeAgentFlag off; AdvDefaultPreference medium; AdvSourceLLAddress on; }; # End of interface definition
[root@servera ~]# dhcpd -t -6 -cf /etc/dhcp/dhcpd6.conf Internet Systems Consortium DHCP Server 4.3.6 Copyright 2004-2017 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ ldap_gssapi_principal is not set,GSSAPI Authentication for LDAP will not be used Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file Config file: /etc/dhcp/dhcpd6.conf Database file: /var/lib/dhcpd/dhcpd6.leases PID file: /var/run/dhcpd6.pid
[root@serverb ~]# nmcli device status DEVICE TYPE STATE CONNECTION eth0 ethernet connected Wired connection 1 eth1 ethernet disconnected -- eth2 ethernet disconnected -- lo loopback unmanaged --
要使用 SLAAC 检索网络参数,可将 auto 用于 ipv6.method 参数
1 2 3 4
[root@serverb ~]# nmcli con add con-name lxhdhcpv6test type ethernet \ ifname eth1 ipv6.method auto
[root@serverb ~]# nmcli con up lxhdhcpv6test
客户端成功获得ipv6地址、dns、网关
1 2 3 4 5 6
[root@serverb ~]# ip -6 a s eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000 inet6 fde2:6494:1e09:2::60/128 scope global dynamic noprefixroute valid_lft 514sec preferred_lft 289sec inet6 fe80::1b06:e035:2b4:d985/64 scope link noprefixroute valid_lft forever preferred_lft forever
[root@serverb ~]# ip -6 route ::1 dev lo proto kernel metric 256 pref medium fde2:6494:1e09:2::60 dev eth1 proto kernel metric 100 pref medium fe80::/64 dev eth1 proto kernel metric 100 pref medium fe80::/64 dev eth0 proto kernel metric 106 pref medium default via fe80::ef0:1eaf:de3b:7a88 dev eth1 proto ra metric 100 pref medium
注意网关是serverd的本地链路地址
1 2 3 4 5 6 7
[root@serverd ~]# ip a s eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:01:fa:0d brd ff:ff:ff:ff:ff:ff inet6 fde2:6494:1e09:2::d/64 scope global noprefixroute valid_lft forever preferred_lft forever inet6 fe80::ef0:1eaf:de3b:7a88/64 scope link noprefixroute valid_lft forever preferred_lft forever
DHCPv6地址保留
DHCPv6 是基于DUID做的地址保留,DUID 是一种用于 DHCPv6 客户端和服务器之间通信的唯一标识符,它在 DHCPv6 协议中用于识别和跟踪客户端。DUID 可以基于多种信息生成,包括但不限于 MAC 地址,它允许客户端即使在更改其 MAC 地址或在不同网络接口上操作时也能保持其身份
先让客户端从dhcpv6获取一个地址,看看duid是多少
1 2 3
[root@serverc ~]# nmcli con add con-name lxh-dhcpv6-keep type ethernet \ ifname eth1 ipv6.method auto [root@serverc ~]# nmcli connection up lxh-dhcpv6-keep
在服务器上执行后,得到了duid,看到它分配了fde2:6494:1e09:2::59
1 2
[root@servera ~]# journalctl -u dhcpd6.service | grep duid Aug 23 21:02:21 servera.lab.example.com dhcpd[26745]: Reply NA: address fde2:6494:1e09:2::59 to client with duid 00:04:49:f0:60:cc:52:78:26:57:89:6f:f8:bf:35:6f:e0:7a iaid = 713252315 valid for 600 seconds
[root@serverc ~]# nmcli connection down lxh-dhcpv6-keep [root@serverc ~]# nmcli connection up lxh-dhcpv6-keep
再次查询客户端地址,发现已经按照我们的预期分配了地址
1 2 3 4 5 6 7
[root@serverc ~]# ip a s eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:01:fa:0c brd ff:ff:ff:ff:ff:ff inet6 fde2:6494:1e09:2::33/128 scope global dynamic noprefixroute valid_lft 591sec preferred_lft 366sec inet6 fe80::7991:af5c:3599:ece6/64 scope link noprefixroute valid_lft forever preferred_lft forever