[IPv6] [Ubuntu] IPv6测试配置手册(Ubuntu22.04)

Ubuntu22.04 IPv6 测试配置手册

00 设备参数

  • Linux 发行版: Ubuntu22.04
  • Linux kernel: 5.19.0-28-generic
  • 控制网口: eth0
  • 测试网口: eth1

01 禁止网络服务控制网口eth1

Ubuntun22.04系统下开展IPv6测试,需要在逐一解除netplansystemd-networkdNetworkManagereth1的控制后,直接使用sysctl配置内核参数。

以下为详细操作步骤:

1.1 解除netplaneth1的控制

进入netplan配置目录:

cd /etc/netplan

如当前文件夹下如存在xml配置文件,则查看是否存在并删除eth1相关配置。

如配置文件为:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: false
      addresses:
        - 192.165.56.155/24
      routes:
        - to: default
          via: 192.165.56.1
    eth1:               # 待删除
      dhcp4: false      # 待删除
    eth2:
      dhcp4: false
      addresses:

删除后eth1配置后为:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: false
      addresses:
        - 192.165.56.155/24
      routes:
        - to: default
          via: 192.165.56.1
    eth2:
      dhcp4: false
      addresses:

删除后执行

netplan apply

完成以上操作,即可以解除netplan对网卡eth1的控制

1.2 解除systemd-networkdeth1的控制

进入systemd-networkd配置目录 /etc/systemd/network

cd /etc/systemd/network

查看可能控制eth1的文件

ls -la *.network

如果有eth1相关配置,则备份或删除之:

# 创建备份目录
mkdir backup

# 备份文件
mv *eth1*.network  backup

# 或者删除文件
rm -f *eth1*.network  backup

重启systemd-networkd服务:

systemctl restart systemd-networkd

1.3 解除NetworkManagereth1的控制

检查NetworkManager是否在运行并且管理网卡:

# 检查NetworkManager服务状态
systemctl status NetworkManager

# 查看NetworkManager管理的所有设备
nmcli device status

如果发现eth1被NetworkManager管理(状态为connected或disconnected),可以使用以下方法解除控制:

# 编辑NetworkManager主配置文件
vim /etc/NetworkManager/NetworkManager.conf

# 在[main]或[keyfile]部分添加以下内容:
# [keyfile]
# unmanaged-devices=interface-name:eth1

重启NetworkManager使配置生效

# 重启NetworkManager服务
systemctl restart NetworkManager

# 验证eth1是否已被设置为未托管
nmcli device status | grep eth1

02 配置系统启动参数

2.1 确认是否存在all参数(全局参数),并注释

查询是否有全局的网卡参数,可能包含all、ALL、default等关键词:

# 进入sysctl配置目录
cd /etc/sysctl.d/

# 搜索所有conf文件中包含all/ALL/default的配置
grep -iHr "all\|default" *.conf 2>/dev/null || true

# 同时检查主配置文件
grep -i "all\|default" /etc/sysctl.conf 2>/dev/null || true

如果存在形如:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

编辑对应文件,将其注释:

# net.ipv6.conf.all.disable_ipv6 = 1
# net.ipv6.conf.default.disable_ipv6 = 1

重新加载系统配置

sysctl --system

重启网卡

ip link set eth1 down; ip link set eth1 up

2.2 确认是否存在旧eth1参数

搜索所有可能存在的eth1相关配置:

# 在sysctl配置目录中搜索eth1相关配置
cd /etc/sysctl.d/
grep -iHr "eth1\|\.eth1\." *.conf 2>/dev/null || true

# 在主配置文件中搜索
grep -i "eth1\|\.eth1\." /etc/sysctl.conf 2>/dev/null || true

# 检查内核启动参数
grep -i "eth1\|ipv6" /proc/cmdline 2>/dev/null || true

# 查看当前生效的eth1相关内核参数
sysctl -a 2>/dev/null | grep -i "\.eth1\." | head -20

如果发现以下类型的旧eth1配置,需要删除或注释掉:

net.ipv6.conf.eth1.disable_ipv6 = 1
net.ipv6.conf.eth1.accept_ra = 0
net.ipv6.conf.eth1.autoconf = 0
net.ipv6.conf.eth1.use_tempaddr = 2
net.ipv6.conf.eth1.forwarding = 0

注释为:

# net.ipv6.conf.eth1.disable_ipv6 = 1
# net.ipv6.conf.eth1.accept_ra = 0
# net.ipv6.conf.eth1.autoconf = 0
# net.ipv6.conf.eth1.use_tempaddr = 2
# net.ipv6.conf.eth1.forwarding = 0

重新加载系统配置

sysctl --system

重启网卡

ip link set eth1 down; ip link set eth1 up

2.3 写入新eth1参数

创建网卡eth1的IPv6配置参数

touch 90-ipv6-eth1.conf

写入如下内容:

# ===============================
# IPv6 配置模板 for eth1
# 支持 SLAAC + RFC7217
# ===============================

# ---------- 基本 IPv6 开关 ----------
net.ipv6.conf.eth1.disable_ipv6 = 0
net.ipv6.conf.eth1.forwarding = 0      # 主机模式,不转发
net.ipv6.conf.eth1.hop_limit = 64

# ---------- 地址自动生成 ----------
net.ipv6.conf.eth1.autoconf = 1         # 启用 SLAAC
net.ipv6.conf.eth1.addr_gen_mode = 0    # 2 = RFC7217 稳定隐私地址
net.ipv6.conf.eth1.use_tempaddr = 0     # 不生成临时地址

# ---------- DAD 设置 ----------
net.ipv6.conf.eth1.accept_dad = 1
net.ipv6.conf.eth1.dad_transmits = 2
net.ipv6.conf.eth1.max_addresses = 32

# ---------- Router Advertisement ----------
net.ipv6.conf.eth1.accept_ra = 1        # 接收 RA(必须)
net.ipv6.conf.eth1.accept_ra_defrtr = 1
net.ipv6.conf.eth1.accept_ra_mtu = 1
net.ipv6.conf.eth1.accept_ra_pinfo = 1
net.ipv6.conf.eth1.accept_ra_rt_info_max_plen = 128
net.ipv6.conf.eth1.accept_ra_rt_info_min_plen = 0
net.ipv6.conf.eth1.accept_ra_rtr_pref = 1

# ---------- Router Solicitation ----------
net.ipv6.conf.eth1.router_solicitation_interval = 4
net.ipv6.conf.eth1.router_solicitations = 3
net.ipv6.conf.eth1.router_solicitation_delay = 1
net.ipv6.conf.eth1.router_solicitation_max_interval = 4

# ---------- Redirect & Neighbor ----------
net.ipv6.conf.eth1.accept_redirects = 1
net.ipv6.conf.eth1.drop_unsolicited_na = 0

# ---------- Multicast / MLD ----------
net.ipv6.conf.eth1.force_mld_version = 0
net.ipv6.conf.eth1.force_tllao = 0

# ---------- 保留设置 ----------
net.ipv6.conf.eth1.keep_addr_on_down = 0
net.ipv6.conf.eth1.max_desync_factor = 600

重新加载系统配置:

sysctl --system

重启网卡:

ip link set eth1 down; ip link set eth1 up

验证配置是否生效:

sysctl -a | grep "net.ipv6.conf.eth1"

设备配置完成,可以开展测试工作。

03 开展IPv6测试

3.1 配置测试机TN

编辑tn.def文件

vim /usr/local/v6eval/etc/tn.def

link0设置为和待测机TUN直连的网卡名称,mac不用修改

# ......
#linkname	interface	BOGUS ether source address
#		name		of the Tester Interface
Link0		em1		00:00:00:00:01:00
#Link1		em2		00:00:00:00:01:01
# ......

3.2 配置测试机TUN

编辑tn.def文件

vim /usr/local/v6eval/etc/tun.def

link0设置为待测机TUN的待测网卡名称eth1、mac地址和ipv6的本地和全局地址

# ......
#linkname	interface	The EXACT ether source address      link-local address      global address
#		name		of the Interface Under Test
Link0		eth1		 3c:ec:ef:56:35:8b		fe80::3eec:efff:fe56:358b	3ffe:501:ffff:100:5bd0:ce80:5300:8e32
#Link1		br0		 cc:5c:de:c8:8f:81		fe80::ce5c:deff:fec8:8f81	3ffe:501:ffff:101:ce5c:deff:fec8:8f81
# ......

3.3 开展测试

进入测试目录

cd /usr/local/ipv6ready/Self_Test_5-0-9/

此位置下存在几个目录:

目录名 目录说明
addr.p2 RFC 4862 - IPv6 无状态地址自动配置
icmp.p2 RFC 4443 - 互联网控制报文协议版本6 (ICMPv6)
nd.p2 RFC 4861 - IPv6 邻居发现协议
pmtu.p2 RFC 8201 - IPv6 路径MTU发现
spec.p2 RFC 8200 - IPv6 规范 (基本协议)

进入各自目录可以对各个项目开展测试,此处以RFC 4862项目测试为例:

# 进入addr.p2(RFC 4862)测试文件夹
cd addr.p2

# 测试 RFC 4862 所有项目
make ipv6ready_p2_host 

# 单独测试第 11 - 13 个项目
make ipv6ready_p2_host AROPT="-s 11 -e 13"

如果项目通过,结果类似:

ipv6# make ipv6ready_p2_host AROPT="-s 11 -e 11"
===> spec.p2
/usr/local/v6eval/bin/autorun -G  -title='Section 1: RFC 8200 - IPv6 Specification'  INDEX_p2_host
Error : Already exist index.html.
        please run after delete index.html or run with -f option.
/usr/bin/perl -e 'use Pod::Html; pod2html("--noindex", @ARGV);' SPEC.pm > SPEC.html
rm -f pod2html-dircache pod2html-itemcache
/bin/rm -f index.html summary.html report.html
/usr/local/v6eval/bin/autorun -s 11 -e 11 -F -tiny  -title='Section 1: RFC 8200 - IPv6 Specification'  INDEX_p2_host
========== TEST 11 ==========
./EX_NH_Zero.seq -pkt ./EX_NH_Zero.def -log 11.html -ti "Next Header Zero"
Start Capturing Packets (Link0)
Send Echo Request (Hop-by-Hop Options Header after Hop-by-Hop Options Header)
Recv Neighbor Solicitation (Link-Local to Link-Local)
Send Neighbor Advertisement (Link-Local to Link-Local)
Recv ICMP Error (Parameter Problem, unrecognized Next Header type encountered)
OK
--- Cleanup NUT
Send Neighbor Advertisement (Link-Local Address with Different Link-layer Address)
Send Echo Request
Wait for transit target Neighbor Cache Entry to INCOMPLETE/NONCE (10 sec.)
Stop Capturing Packets (Link0)
  -> PASS
===> nd.p2
/usr/local/v6eval/bin/autorun -G  -title='Section 2: RFC 4861 - Neighbor Discovery for IPv6'  INDEX_ND_p2_host    INDEX_RD_p2_host    INDEX_REDIRECT_p2_host
Error : Already exist index.html.
        please run after delete index.html or run with -f option.
/bin/rm -f index.html summary.html report.html
/usr/local/v6eval/bin/autorun -s 11 -e 11 -F -tiny  -title='Section 2: RFC 4861 - Neighbor Discovery for IPv6'  INDEX_ND_p2_host    INDEX_RD_p2_host    INDEX_REDIRECT_p2_host

如果通过,输出结果显示为PASS,如果未通过,输出结果中带有FAIL

3.4 测试中的特殊操作

3.4.1 重启网卡

# 先禁用eth1网络接口,再重新启用eth1网络接口(相当于重启网卡)
ip link set eth1 down; ip link set eth1 up

3.4.2 观察网卡状态

# 每0.5秒刷新一次,高亮显示eth1网卡的IPv6地址配置变化
watch -n 0.5 -d ip -6 addr show dev eth1

3.4.3 ping6

# 发送1452字节的IPv6探测包到ff1e::1:2,通过eth1网卡,进行路径MTU发现
ping6 -s 1452 -c 1 -I eth1 ff1e::1:2 -M want

3.5 测试未通过项

3.5.1 RFC 8200(IPv6 Specification)

  • 完全通过

3.5.2 RFC 4861(Neighbor Discovery for IPv6)

  • No.12/13:多测试几次能通过
  • No.188/190/191/193:HOST可以略过不测

3.5.3 RFC 4862(IPv6 Stateless Address Autoconfiguration)

  • No.33: 偶尔通过
  • No.43/47/48:将addr_gen_mode改为3,再改为2之后,IPv6全局地址生成类型发生改变,再修订一下nut.conf中的全局地址以确保能够从新的IPv6中接收到DAD信息,测试通过

3.5.4 RFC 8201(Path MTU Discovery for IPv6)

  • No.17:可选项,可以不测试,大部分设备不支持

3.5.5 RFC 4443(ICMPv6)

  • 完全通过
posted on 2025-12-01 15:55  风惊庭前叶  阅读(0)  评论(0)    收藏  举报