centos7防火墙之iptables与firewalld

1、iptables

  1)查看是否安装iptables

rpm -qa | grep iptables

  2)查看是否启动iptables

systemctl status iptables.service

  3)启动iptables

systemctl start iptables.service

  4)临时禁用一个端口,禁掉8002端口,无需重启iptables

iptables -I INPUT -p tcp --dport 8002 -j DROP

  清掉临时规则,执行完这一句8002端口又能访问了,无需重启iptables

iptables -F

2、firewall

  防火墙基础操作

1)查看防火墙状态
[root@localhost ~]# service firewalld status(方法1)
[root@localhost ~]# systemctl status firewalld(方法2)
[root@localhost ~]# firewall-cmd --state(方法3)
2)开始防火墙 [root@localhost ~]# service firewalld start(方法1) [root@localhost ~]# systemctl start firewalld(方法2)
3)关闭防火墙 [root@localhost ~]# service firewalld stop(方法1) [root@localhost ~]# systemctl stop firewalld(方法2)

4)禁用防火墙(重启生效)
[root@localhost ~]# systemctl disable firewalld

  防火墙基于端口的操作:

1)查看所有开放端口
[root@localhost ~]# firewall-cmd --zone=public --list-ports

2)查看mysql端口是否开放
[root@localhost ~]# firewall-cmd --query-port=3306/tcp

3)开放mysql端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

4)关闭mysql端口
firewall-cmd --zone=public --remove-port=3306/tcp --permanent
5)使设置立即生效
[root@localhost ~]# firewall-cmd --reload
备注:
1)--permanent:永久性的,如果不加它,系统重启后会失效
2)开放或关闭端口后,要执行reload,否则操作不生效

  防火墙基于服务的操作:

1)查看所有开放的服务
[root@localhost ~]# firewall-cmd --zone=public --list-services

2)查看mysql服务是否开放
[root@localhost ~]# firewall-cmd --query-service mysql

3)开放mysql服务
[root@localhost ~]# firewall-cmd --add-service=mysql --permanent

4)拦截mysql服务
[root@localhost ~]# firewall-cmd --remove-service=mysql --permanent

  

 

 

posted @ 2020-05-12 17:46  雷雨客  阅读(711)  评论(0编辑  收藏  举报