172.28.225.0/24 dev eth0.2 proto kernel scope link src 172.28.225.10
172.28.225.0/24 dev eth1.13 proto kernel scope link src 172.28.225.13
这两个vlan路由冲突了,用下面的方法解决。。
#!/bin/bash
# 使用macvlan解决路由冲突
# 0. 清理旧配置
ip link del eth0.2 2>/dev/null
ip link del macvlan1 2>/dev/null
ip link del macvlan2 2>/dev/null
# 1. 创建VLAN接口
echo "1. 创建VLAN接口 eth0.2..."
ip link add link eth0 name eth0.2 type vlan id 2
ip link set eth0.2 up
# 2. 在VLAN接口上创建两个macvlan
echo "2. 创建macvlan接口..."
# macvlan1: 172.28.225.10
ip link add link eth0.2 name macvlan1 type macvlan mode bridge
ip link set macvlan1 address 00:11:22:33:44:55
ip addr add 172.28.225.10/24 dev macvlan1
ip link set macvlan1 up
# macvlan2: 172.28.225.13
ip link add link eth0.2 name macvlan2 type macvlan mode bridge
ip link set macvlan2 address 00:11:22:33:44:66
ip addr add 172.28.225.13/24 dev macvlan1
ip link set macvlan2 up
# 3. 禁用eth0.2的IP(避免路由冲突)
echo "3. 清理VLAN接口IP..."
ip addr flush dev eth0.2
# 4. 查看路由表
echo "4. 查看路由表..."
ip route show | grep "172.28.225.0/24"
# 5. 验证配置
echo ""
echo "=== 配置完成 ==="
echo "接口列表:"
ip link show | grep -E "(eth0.2|macvlan)"
echo ""
echo "IP地址配置:"
ip addr show | grep -A2 -E "(eth0.2|macvlan)"
iptables -A FORWARD -i macvlan1 -d 255.255.255.255 -j DROP