我想用一个 linux-box 测试一个网络,它应该有 100 个不同的 IP 地址,每个都有自己的 MAC,在与其他设备通信时应该用作源 MAC 地址。
我已经编写了这个脚本:
#!/bin/bash
for i in `seq 0 10 `; do
hex=`perl -e "printf ('%02X', $i)"`
echo tap$i / $hex
ip link add link eth0 address 00:00:13:37:00:$hex eth0-$i type macvlan
done
sleep 2
for i in `seq 0 10 `; do
echo eth0-$i ip
while ! ifconfig eth0-$i &>/dev/null; do
sleep 1
done
ii=`expr $i + 100`
ip addr add 10.254.251.$ii/24 dev eth0-$i
ifconfig eth0-$i up
done
Run Code Online (Sandbox Code Playgroud)
然后我让我的设备拥有自己的 IP 和自己的 MAC …