Linux 配置防火墙
一、图形化的形式
1.开启LAMP
systemctl start httpd
2.查看本地IP地址
ip addr
 3.本地IP为
192.168.31.150
本地访问  外部浏览器就无法访问  4.此时配置防火墙
firewall-config
此时,出现图形化界面,需要输入密码  改变服务http  Runtime表示的是临时的,Permanent是永久的,就算是重启了之后,也是不变 选择public域,勾选http,在我们的电脑上即可访问
 当我们取消http的时候,需要输入密码   5.关闭http服务,开放80端口   因为不是管理员权限,所以每次都需要输入密码  6.开放80端口  7.当我们再次访问时,一样可以访问 
二、命令行的形式
1.查看状态
firewall-cmd --state
 2.我们将前面设置好的80端口进行,移除  3.在此使用物理机上的浏览器访问时,无法访问  4.尝试开放80端口
firewall-cmd --zone=public --add-port=80/tcp #允许80端口的TCP流量
 当我们访问时,可以正常访问  5.关闭80端口
firewall-cmd --zone=public --remove-port=80/tcp
 6.列出所有规则
firewall-cmd --list-all

三、iptables防火墙
1.使用firewalld关闭防火墙
systemctl stop firewalld ###关闭防火墙
systemctl status firewalld ###查看状态
出现dead 说明,防火墙已经关闭 
2.iptables语法构成
iptables [-t 表名] 选项 [链名] [条件] [-j控制类型]
-j:数据包的常见控制类型: ACCEPT :允许通过 DROP :直接丢弃,不给出任何回应
-p:指定协议类型:TCP 、UDP 、ICMP
-m:表示启用扩展功能,一般和-p配合使用
3.首先关闭firewalld防火墙,进行访问
systemctl stop firewalld

4.发现可以访问,此时我们使用iptables命令关闭80端口
iptables -t filter -A INPUT -p TCP -j DROP --dport 80
 5.在此使用外部浏览器访问时,发现无法访问  6.iptables查看规则命令
iptables -L ###查看规则

可以看出来,我们将http服务的包直接丢掉,转发和出站的服务没有开启
7.iptables删除规则的命令
iptables -D ##清空一条指定的规则
iptables -F ##清空所有的规则
 可以看到所有的规则,都被清空,在此访问时,可以成功 
|