OpenWRT 添加靜態ARP (ARP綁定)

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 <[email protected]>
    +
    +. /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 <[email protected]>
    +#
    +# 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
    +
    
    發表評論
    所有評論
    還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
    相關文章