首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建1000个macvlan,ping本地ip失败

问创建1000个macvlan,ping本地ip失败
EN

Server Fault用户
提问于 2019-04-04 22:13:18
回答 1查看 1.5K关注 0票数 1

我想用不同的ip创建1000个macvlan。并使用ip rule路由不同的公共ip到多个接口的互联网。

首先创建1000 macvlan:

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

%02x是mac地址,%d是0-999.

然后使用ifconfig设置每个macvlan不同的公共ip。最后,使用ip规则:

代码语言:javascript
复制
ip route add default via ${router} dev ${interface} src ${ip} table ${interfaceidx}
ip rule add from ${ip} table ${interfaceidx}

每个macvlan将添加一个规则和一个表。

使用另一个服务器ping任何macvlan ip都可以。

代码语言:javascript
复制
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

但是主机中的ping macvlan会丢弃数据包:

代码语言:javascript
复制
[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也将丢弃数据包:

代码语言:javascript
复制
[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

我想我的路由表没问题。其他pc ping是ok.Modern Linux内核,它支持4294967295个表is,实现为32位长的rtnetlink属性RTA_TABLE。https://bird.network.cz/pipermail/bird-users/2013-November/008706.html

代码语言:javascript
复制
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
EN

回答 1

Server Fault用户

回答已采纳

发布于 2019-04-09 04:00:19

linux默认的arp表是1000。

代码语言:javascript
复制
net.ipv4.neigh.default.gc_thresh1 = 8192
net.ipv4.neigh.default.gc_thresh2 = 32768
net.ipv4.neigh.default.gc_thresh3 = 65536

1000元会导致arp丢失,所以ping会下降。在sysctl.conf中添加这一行。sysctl -p。

票数 2
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/961596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档