iptable之禁用端口

通过防火墙规则实现,现在需要在防火墙上设置一个黑名单,具体操作如下:
1. 开启防火墙
Centos5/6:

/etc/init.d/iptables  start 
Chkconfig  iptables on

Centos7:

systemctl start firewalld
systemctl enable firewalld

2. 设置黑名单

iptables –F
iptables –X
iptables -I INPUT -p tcp --dport 137 -j DROP
iptables -I INPUT -p udp --dport 137 -j DROP
service iptables save(centos6/7)

注意:如果在centos7中执行service iptables save时报错(The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.)。解决方法如下:

systemctl stop firewalld 关闭防火墙
yum install iptables-services 安装或更新服务
systemctl enable iptables 开机启动iptables
systemctl start iptables 打开iptables
service iptables save
    原文作者:灬紫荆灬
    原文地址: https://blog.csdn.net/weixin_43279032/article/details/102794640
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞