Linux防火墙命令


Linux防火墙常用命令


centos7防火墙默认使用的是firewalld
centos6防火墙默认使用的是iptables


一、centos7

1、开放端口的命令格式:firewall-cmd --zone=public --add-port=端口/tcp --permanent
2、移除开放端口的命令格式:firewall-cmd --zone= public --remove-port=端口/tcp --permanent
3、临时关闭防火墙:systemctl stop firewalld.service
4、开启防火墙:systemctl start firewalld.service
5、永久关闭防火墙:systemctl disable firewalld.service
6、设置开机自启:systemctl enable firewalld.service
7、查看防火墙状态:firewall-cmd --state
8、查看防火墙开放端口:firewall-cmd --list-ports
9、查看某一端口是否开放: firewall-cmd --query-port=端口/tcp
10、指定ip开放端口:firewall-cmd --permanent --add-rich-rule=“rule family=“ipv4” source address=“指定的ip” port protocol=“tcp” port=“端口” accept”
11、防火墙禁ping:firewall-cmd --add-rich-rule=‘rule protocol value=icmp drop’ --permanent

二、centos6

1、开放端口命令:iptables -A INPUT -p tcp -m tcp --dport 端口 -j ACCEPT
2、指定ip开放端口:iptables -I INPUT -s 地址 -p tcp --dport 端口 -j ACCEPT
3、禁止指定ip访问:iptables -A INPUT -p tcp -s 地址 -j DROP
4、临时关闭防火墙:service iptables stop
5、重启防火墙:service iptables restart
6、永久关闭:chkconfig iptables off
7、开机自启:chkconfig iptables on
8、禁ping:iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -j DROP
9、解除禁ping:iptables -D INPUT -p icmp --icmp-type 8 -s 0/0 -j DROP

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值