[英]deleting ipv4 address belongs to the same subnet from linux interface using netlink API
I am using netlink API rtnl_addr_delete
to delete the ipv4 address configured on interface in Linux. 我正在使用netlink API
rtnl_addr_delete
删除Linux接口上配置的ipv4地址。 Two IPs belonging to the same subnet are configured to an interface. 属于同一子网的两个IP被配置到一个接口。
When i delete the first configured IP, both IPs are getting deleted which is unexpected. 当我删除第一个配置的IP时,两个IP都将被删除,这是意外的。 But vice versa is not true, when I delete the second configured IP, the first one does not getting deleted which is expected.
但是反之亦然,当我删除第二个配置的IP时,第一个不会被删除,这是正常的。
Suppose if 2 IPs belonging to the different subnet, issue is not seen. 假设如果2个IP属于不同的子网,则不会出现问题。 That is, if i delete first then only first one is deleting.
也就是说,如果我先删除,则只有第一个删除。
Any idea weather it is how this rtnl_addr_delete
behaves or any resolutions can be made to fix this issue? 知道这是
rtnl_addr_delete
行为方式,还是可以通过任何解决方法解决此问题?
When you remove the first added IP address from one subnet (the «primary» address), all the subnet is being deleted. 当您从一个子网中删除第一个添加的IP地址(“主”地址)时,将删除所有子网。 That's the default kernel behaviour in some distributions.
在某些发行版中,这是默认的内核行为。 To change that, you have to set sysctl on the interface you work with:
要更改此设置,必须在使用的接口上设置sysctl:
$ sysctl -a | grep promote_secondaries
Say, you want to change that on eth0: 假设您要在eth0上更改它:
$ sudo sysctl -w net.ipv4.conf.eth0.promote_secondaries=1
With promote_secondaries
the rest of the subnet will not be removed, but instead one of the addresses will be promoted as the new primary. 使用
promote_secondaries
不会删除子网的其余部分,而是将其中一个地址提升为新的主要子网。
Docs: https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt 文件: https : //www.kernel.org/doc/Documentation/networking/ip-sysctl.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.