只允许指定的ip访问本机的指定端口50070:
例如允许的的ip:192.168.1.123,192.168.1.124, 192.168.1.100,其他ip都禁止访问。
1、在tcp协议中,禁止所有的ip访问本机的50070端口。
iptables -I INPUT -p tcp --dport 50070-j DROP
2、允许192.168.1.123访问本机的50070端口
iptables -I INPUT -s 192.168.1.123 -ptcp --dport 50070 -j ACCEPT
3、允许192.168.1.124访问本机的50070端口
iptables -I INPUT -s 192.168.1.124 -ptcp --dport 50070 -j ACCEPT
4、允许192.168.1.100访问本机的50070端口
iptables -I INPUT -s 192.168.1.100 -ptcp --dport 50070 -j ACCEPT
注意以上4条命令的顺序不能错。
也可以直接配置允许某一网段访问本机的50070端口
iptables -I INPUT-s 192.168.1.0/24 -p tcp --dport 50070 -j ACCEPT
或者禁止某个ip访问本机的50070端口
iptables -I INPUT -s 192.168.1.123 -ptcp --dport 50070-j DROP
其他命令:
1.iptables -F 清除预设表filter中的所有规则链的规则
2. service iptables save 保存iptables(配置完之后记得保存)
3.service iptables restart 重启iptables(每次配完保存之后重启生效)
4.启动和关闭防火墙的命令
1) 重启后生效开
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后失效
开启: service iptables start
关闭: service iptables stop
原文:https://www.cnblogs.com/zcg-cpdd/p/14633170.html