arp cache refresh problem

arp cache refresh problem

  • If you want to set the aging time of your ARP cache on Linux, execute sysctl -w net.ipv4.neigh.ethX.base_reachable_time=Y . If you set something else, it only affects performance. In Linux, the aging of the ARP cache is based on its change to the stale state, not based on the deletion of its entries. The stale state only affects the cache. Cached;
  • Always remember that when changing an IP address to another device on this network segment , broadcast gratuitous ARP as quickly as possible. You can use arping to play tricks on Linux .

Modify a single parameter (directly modify sysctl -w) ( permanent effect )

[root@ufo130 eth0]# sysctl -w net.ipv4.neigh.eth0.base_reachable_time=5
net.ipv4.neigh.eth0.base_reachable_time = 5
[root@ufo130 eth0]# 
[root@ufo130 eth0]# cat base_reachable_time
5
[root@ufo130 eth0]# cat base_reachable_time_ms 
5000

Batch modify parameters (modify /etc/sysctl.conf, just load it) ( permanent effect )

[root@ufo130 eth0]# cat /etc/sysctl.conf | grep net.ipv4.neigh.eth0.base_reachable_time
net.ipv4.neigh.eth0.base_reachable_time = 10
[root@ufo130 eth0]# /sbin/sysctl -p /etc/sysctl.conf
[root@ufo130 eth0]# cat base_reachable_time
10
[root@ufo130 eth0]# cat base_reachable_time_ms 
10000

arping LAN refresh (floating IP floats to other node IP in this network segment)

# 添加浮动ip
[root@ufo130 eth0]# ip a add 192.168.71.160/24 dev eth0
# 删除浮动ip
[root@ufo130 eth0]# ip a del 192.168.71.160/24 dev eth0
# ip a 查看

# arping -I 网卡地址 -c 3 -s VIP地址 网关地址
[root@ufo130 eth0]# arping -I eth0 -c 3 -s 192.168.71.160 192.168.71.2
ARPING 192.168.71.2 from 192.168.71.160 eth0
Unicast reply from 192.168.71.2 [00:50:56:EA:BD:C4]  3.136ms
Unicast reply from 192.168.71.2 [00:50:56:EA:BD:C4]  0.879ms
Unicast reply from 192.168.71.2 [00:50:56:EA:BD:C4]  0.994ms
Sent 3 probes (1 broadcast(s))
Received 3 response(s)

View Linux ARP cache aging time

cat /proc/sys/net/ipv4/neigh/eth0/base_reachable_time

View Linux ARP cache status

[root@ufo130 eth0]# ip neigh
192.168.71.1 dev eth0 lladdr 00:50:56:c0:00:08 REACHABLE
192.168.71.2 dev eth0 lladdr 00:50:56:ea:bd:c4 STALE
  • Execute the arping command, unable to add a new arp cache. But the STALE cache can be refreshed to REACHABLE state
  • Ping can only add arp cache, but it cannot refresh the STALE cache to REACHABLE state. And the ping works, which also shows that STALE is still being quoted
  • The aging of the ARP cache is based on its change to the stale state, not based on the deletion of its entries. The stale state only caches the cache again
[root@ufo130 eth0]# ip neigh
192.168.71.1 dev eth0 lladdr 00:50:56:c0:00:08 REACHABLE
192.168.71.2 dev eth0 lladdr 00:50:56:ea:bd:c4 STALE
[root@ufo130 eth0]# arping -I eth0 -c 3 -s 192.168.71.130 192.168.71.2
ARPING 192.168.71.2 from 192.168.71.130 eth0
Unicast reply from 192.168.71.2 [00:50:56:EA:BD:C4]  1.592ms
Unicast reply from 192.168.71.2 [00:50:56:EA:BD:C4]  0.973ms
Unicast reply from 192.168.71.2 [00:50:56:EA:BD:C4]  0.865ms
Sent 3 probes (1 broadcast(s))
Received 3 response(s)
[root@ufo130 eth0]# ip neigh
192.168.71.1 dev eth0 lladdr 00:50:56:c0:00:08 REACHABLE
192.168.71.2 dev eth0 lladdr 00:50:56:ea:bd:c4 REACHABLE

Related reference materials:
[Analysis of the principle of ARP cache aging time implemented by Linux]
https://younger.blog.csdn.net/article/details/79216211

[Virtual IP understanding]
https://www.cnblogs.com/crazylqy/p/7741958.html

Guess you like

Origin blog.csdn.net/qq_42226855/article/details/111403311