1
raysonx 2023-09-06 17:35:49 +08:00
问题是这么做的意义在什么地方?你机器上的服务要同时使用这么多地址吗?
|
2
terrancesiu 2023-09-06 17:36:28 +08:00 via iPhone
@raysonx 可能用来流媒体解锁
|
3
raysonx 2023-09-06 17:38:39 +08:00
@terrancesiu 256 个容易,可以写脚本搞定。添加整个/48 段的地址这种太夸张了,还不如写个脚本来动态换地址。
|
4
Leonkennedy2 OP @raysonx 不好意思,我想错了,因为我有/48 的 v6 地址,光想着怎么配置大量 ip ,我忽略了一般人没有/48 部署在一个机器上的需求
|
5
xinge666 2023-09-06 21:19:11 +08:00 via iPhone
@terrancesiu 流媒体解锁也是直接封禁一个/64 的而不是按地址封禁
|
6
Fangliding 2023-09-06 22:28:33 +08:00
eg 2a01:4f8:13a:19e5:106d:95e1:e10c:0001/112 ()
|
8
Leonkennedy2 OP @julyclyde 不是,只是好奇问问
|
9
Leonkennedy2 OP 时隔一个月,对于我提问的这个问题,我想到一个新的处理办法。shell 不方便处理 ipv6 的计算,用 python 脚本
比如说我要配置从 a 之后 256 个 ipv6 到 ens33 网卡上,python 脚本可以这么写: import subprocess import ipaddress def add_ipv6_addresses(interface, start_ipv6, count, gateway): # 将 IPv6 地址转换为 ipaddress.IPv6Address 对象 start_address = ipaddress.IPv6Address(start_ipv6) # 递增 IPv6 地址并配置到指定网卡 for i in range(count): current_address = start_address + i command = f"ip -6 addr add {current_address}/56 dev {interface}" try: subprocess.run(command, shell=True, check=True) print(f"Successfully added {current_address} to {interface}") except subprocess.CalledProcessError as e: print(f"Failed to add {current_address} to {interface}: {e}") # 设置网关为指定的 IPv6 地址 gateway_command = f"ip -6 route add default via {gateway}" try: subprocess.run(gateway_command, shell=True, check=True) print(f"Gateway set to {gateway}") except subprocess.CalledProcessError as e: print(f"Failed to set gateway to {gateway}: {e}") # IPv6 起始 IP ,数量,网关 变量 interface = "ens33" start_ipv6 = "ipv6 的起始 IP" count = 256 gateway = "ipv6 的网关" add_ipv6_addresses(interface, start_ipv6, count, gateway) 这个 py 脚本另存为一个 add256v6.py ,目录在/etc/sysconfig/network-script/ , 配置 systemctl ,创建一个服务让这个 py 脚本开机自启一次 touch /etc/systemd/system/add256v6.service add256v6.service: [Unit] Description=Add256v6 Service After=network.target [Service] ExecStart=/usr/bin/python3 /etc/sysconfig/network-script/add256v6.py [Install] WantedBy=default.target 最后 sudo systemctl enable add256v6.service && sudo systemctl start add256v6.service && sudo systemctl status add256v6.service |
10
Leonkennedy2 OP 这样的话,2k 个 IP 也可以了
|