|
|
本帖最后由 chtomato 于 2016-4-16 00:12 编辑
原文地址:http://www.op10000.com/2016/04/14/openwrt用iptable绑定mac和ip/
用 iptables 限制只有对应的 MAC 和 IP 才能上网。这里是通过 mac.sh 脚本读取 mac.txt 的内容进行的。
- mac.txt 格式: MAC IP 备注
- 00:11:09:09:8B:33 192.168.1.3 PC1-wired
- 00:23:5A:40:64:55 192.168.1.5 PC2-wired
- 00:1A:73:D3:3A:11 192.168.1.250 PC3-wireless
- mac.sh
- #! /bin/bash
- macfile=”/var/mac.txt”
- cat $macfile| while read line
- do
- ip=$(echo $line|awk ‘{print $2}’);
- mac=$(echo $line|awk ‘{print $1}’);
- #echo $mac $ip;
- echo iptables -A FORWARD -s $ip -m mac –mac-source $mac -j ACCEPT
- done
- iptables -A FORWARD -s 192.168.1.0/24 -j Drop
复制代码
|
|