OpenWRT 添加静态ARP (ARP绑定)
在路由器上为我的主机添加一条静态ARP条目
arp -s 192.168.1.99 00:24:1d:d4:a1:e8
arp -i br-lan -s 192.168.1.99 00:24:1d:d4:a1:e8
或者
ip neigh add 192.168.1.99 lladdr 00:24:1d:d4:a1:e8 nud permanent dev br-lan
(nud permanent表明是永久性的,除非你手动删除这个条目, 或者系统重启)
用arp -s 命令设置过后, ip neigh show 就显示 PERMANENT 了
cat /proc/net/arp 显示 Flags 为 6
前提是 busybox必须包含了 arp 这两个命令, 默认情况下arp命令只能查看,不能修改arp表
编译是, 在 Base System –> busybox –> Network Utilities 下 选中arp
busybox中ip 命令不够完整
必须安装 iproute2 (就是 ip命令)
显示arp条目的命令是
arp -a
或者
ip neigh show
完整的arp命令在 net-tools 中实现
openwrt参考连接
https://github.com/981213/luci-1/commit/5bdd4b8edff904753d6a26137894e265d17b905b
- 1. 启动脚本
-
applications/luci-app-arpbind/root/etc/init.d/arpbind
+#!/bin/sh /etc/rc.common +# OpenWrt 静态ARP绑定 启动脚本 +# Copyright (C) 2015 GuoGuo <gch981213@gmail.com> + +. /lib/functions.sh +. /lib/functions/network.sh + +#清除单接口ARP +#参数:$1:接口名称 +if_clean_arp() +{ + [ -z "$1" ] && return + ip link set arp off dev $1 + ip link set arp on dev $1 +} + +#清除系统所有ARP +#参数:无 +clean_arp() +{ + for i in $(ls /sys/class/net) + do + if_clean_arp $i + done +} + +#添加静态ARP绑定 +#参数:$1:IP地址 $2:MAC地址 $3:接口名称 +add_arp() +{ + [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] && return + echo "Adding ARP:IP Addr:$1 MAC Addr:$2 Interface:$3" + ip neigh add $1 lladdr $2 nud permanent dev $3 +} + +arpconf_foreach() +{ + config_get ipaddr "$1" 'ipaddr' + config_get macaddr "$1" 'macaddr' + config_get ifname "$1" 'ifname' + [ -z "$ifname" ] && return + add_arp $ipaddr $macaddr $ifname +} + +start() +{ + config_load 'arpbind' + config_foreach arpconf_foreach 'arpbind' +} + +stop() +{ + clean_arp +} +
- 2. luci包
- applications/luci-app-arpbind/Makefile
+# +# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org> +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=ARP Binding +LUCI_DEPENDS:=+ip-full + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature +