使用iptables基于MAC地址进行访控

近日完成一台基于CentOS的SVN服务器配置,由于该服务器上的文件非常重要,仅部分用户需要访问,最后决定采用iptables来做访控,并且是根据MAC地址来限制,为了便于后期维护,防火墙的配置是通过一个bash脚本来完成的,该脚本内容如下:

#!/bin/bash
iptables=/sbin/iptables
#Flush chains
$iptables –F
#Change the INPUT chains
$iptables -A INPUT -m state --state INVALID -j DROP
$iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
#Read allowed mac from file /root/allow_mac
for i in $(grep -v '^#' /root/allow_mac)
do
    $iptables -A INPUT -m mac --mac-source $i -j ACCEPT
done
#Change the INPUT chain's default Policy to DROP
$iptables -P INPUT DROP

   把允许访问的机器的MAC地址放入文件/root/allow_mac中,每个mac独占一行,然后编辑/etc/rc.local文件让系统在启动的时候执行该防火墙脚本即可。
---------------------
作者:windowsxpwyd
来源:CSDN
原文:https://blog.csdn.net/windowsxpwyd/article/details/6253307
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/ricks/p/10259627.html