大网数据广告活动
服务器运维问答

create one thousand macvlan , ping local ip failed

· 52CE 我爱测

I want to create 1000 macvlan with diffrent ip. And use ip rule routing different public ip to internet with multiple interfaces. First create 1000 macvlan: ip link add link eth0 address %02x:%02x:%02x:%02x:%02x:%02x eth0_%d type…

问题原文

原帖链接 · jianxi sun · CC BY-SA 4.0

I want to create 1000 macvlan with diffrent ip. And use ip rule routing different public ip to internet with multiple interfaces.

First create 1000 macvlan:

ip link add link eth0 address %02x:%02x:%02x:%02x:%02x:%02x eth0_%d type macvlan

%02x is mac address, %d is 0-999.

Then use ifconfig set each macvlan different public ip. At last, use ip rule:

ip route add default via ${router} dev ${interface} src ${ip} table ${interfaceidx}
ip rule add from ${ip} table ${interfaceidx}

each macvlan will add a rule, and a table.

Use the other server ping any macvlan ip is ok.

root@ubuntu:/tmp# ping 222.217.107.102
PING 222.217.107.102 (222.217.107.102) 56(84) bytes of data.
64 bytes from 222.217.107.102: icmp_seq=1 ttl=56 time=57.5 ms
64 bytes from 222.217.107.102: icmp_seq=2 ttl=56 time=58.0 ms
64 bytes from 222.217.107.102: icmp_seq=3 ttl=56 time=60.1 ms
64 bytes from 222.217.107.102: icmp_seq=4 ttl=56 time=57.5 ms

But ping macvlan in host will drop packet:

[root@localhost ~]# ping 222.217.107.102
PING 222.217.107.102 (222.217.107.102) 56(84) bytes of data.
64 bytes from 222.217.107.102: icmp_seq=1 ttl=64 time=0.124 ms
ping: sendmsg: Invalid argument
64 bytes from 222.217.107.102: icmp_seq=3 ttl=64 time=0.049 ms
ping: sendmsg: Invalid argument

ping 127.0.0.1 will also drop packet:

[root@localhost ~]# ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
ping: sendmsg: Invalid argument
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.050 ms
ping: sendmsg: Invalid argument
ping: sendmsg: Invalid argument
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.061 ms
ping: sendmsg: Invalid argument
ping: sendmsg: Invalid argument
ping: sendmsg: Invalid argument


[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

I think my routeing table is ok. Other pc ping is ok.Modern Linux kernels has support for 4294967295 table ids, implemented as rtnetlink attribute RTA_TABLE with 32 bit length. https://bird.network.cz/pipermail/bird-users/2013-November/008706.html

327654: from 113.15.163.120 lookup 1429 
327655: from 113.15.163.121 lookup 1511 
327656: from 113.15.163.122 lookup 1522 
327657: from 113.15.163.123 lookup 1186 
327658: from 113.15.163.125 lookup 1513 
327659: from 113.15.163.124 lookup 1190 
327660: from all lookup main 
327670: from all lookup default

已采纳解答

原帖链接 · jianxi sun · CC BY-SA 4.0

linux default arp table is 1000.

net.ipv4.neigh.default.gc_thresh1 = 8192
net.ipv4.neigh.default.gc_thresh2 = 32768
net.ipv4.neigh.default.gc_thresh3 = 65536

1000 macvlan will cause arp lost, so ping will drop. Add these line in sysctl.conf. sysctl -p.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-04-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。