Iptables包含mac模块,通过iptables的MAC地址过滤,可以限制对主机的ssh访问,但这种过滤只能限制通过以太网设备进入Iptables链的包。
阻止来自如下MAC地址的访问:
1 | iptables -A INPUT -m mac --mac-source xx-xx-xx-xx-xx-xx -j DROP |
允许来自如下MAC地址的访问:
1 2 | iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -m mac --mac-source xx-xx-xx-xx-xx -j ACCEPT |
如果需要允许其他MAC地址,只需要在iptables的配置文件中增加:
1 2 | iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -m mac --mac-source another-mac-address -j ACCEPT |
这个只能对内网进行限制了。