防火墙的配置--firewalld与iptables
2017-12-07 20:59
411 查看
管理防火墙的两种方式:firewalld与iptables(1)firewalld 管理火墙的工具,相对简单 -->windows(2)iptables 复杂,功能强大 -->route(1)、(2)不能同时起作用
更改默认指定区域:修改默认区域(1)一般情况下,默认的区域是public(2)选择Change Default Zone
开启httpd[root@route ~]# systemctl start httpd
开启httpd[root@route ~]# systemctl start httpd测试:在浏览器中可以看到无法连接
查看防火墙状态:发现没有服务中httpd
可通过编写火墙默认的public区域配置文件,来永久开启服务[root@route ~]# vim /etc/firewalld/zones/public.xml在第七行加入http服务: <service name="http"/>
重启火墙[root@route ~]# systemctl restart firewalld再测试在浏览器中可以看到已经成功访问
(二)命令行管理firewalld关于网络区域的配置:
安装软件[root@route ~]# yum install firewalld firewall-config -y(1)常用命令开启防火墙[root@route ~]# systemctl start firewalld开机自启防火墙[root@route ~]# systemctl enable firewalld关闭防火墙[root@route ~]# systemctl stop firewalld开机自动关闭防火墙[root@route ~]# systemctl disable firewalld查看防火墙状态[root@route ~]# firewall-cmd --state查看防火墙管理的设备[root@route ~]# firewall-cmd --get-active-zones查看防火墙生效的区域[root@route ~]# firewall-cmd --get-default-zone查看防火墙所有的区域[root@route ~]# firewall-cmd --get-zones列出关于public区域的服务设置[root@route ~]# firewall-cmd --zone=public --list-all列出关于trusted区域的服务设置[root@route ~]# firewall-cmd --zone=trusted --list-all列出可使用的服务[root@route ~]# firewall-cmd --get-services修改默认区域为trusted[root@route ~]# firewall-cmd --set-default-zone=trusted修改默认区域为public[root@route ~]# firewall-cmd --set-default-zone=public举例演示:
查看firewalld的区域相关配置文件[root@route ~]# cd /etc/firewalld/zones/
[root@route ~]# iptables -t filter -nL查看配置文件[root@route ~]# vim /etc/sysconfig/iptables刷新清空iptables[root@route ~]# iptables -F保存状态[root@route ~]# service iptables save列出默认表信息[root@route ~]# iptables -nL所有INPUT服务都丢弃并且不回应[root@route ~]# iptables -P INPUT DROP
添加接受来自回环地址的[root@route ~]# iptables -A INPUT -i lo -j ACCEPT添加接受tcp协议80端口的服务[root@route ~]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT添加接受tcp协议22端口的服务[root@route ~]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT拒绝全部的INPUT链服务[root@route ~]# iptables -A INPUT -j REJECT查看之,[root@route ~]# iptables -nL
3、防火墙策略优化若是第一次访问可以,则第二次访问就不会再问 ,这就是优化状态。注:系统重启会改变状态的数据包状态:第一次连接:NEW 连接中:ESTABLISHED 连接过的:RELATED[root@route ~]# iptables -F ##刷新清空策略[root@route ~]# service iptables save ##保存[root@route ~]# iptables -nL ##查看
关于iptables的参数:-t 指定表-L 列出表-A 永远加在最后一条-D 删除某一条链里面的策略-i 输入 (-i lo 表示是从回环地址进来的)-o 输出-I 插入到某一条,默认第一条(-I INPUT 3 插入到第三行,不写3的话默认添加到第一个)-m 状态-j 动作(ACCEPT | REJECT)-s 资源(无,则所有)-P 策略-p 协议-R 更改--dport 端口-N 新建一个链-E 修改链名称-X 删除链
一、firewalld相关配置
(一)图形化管理
打开图形化管理火墙界面,并打入后台不影响终端使用[root@route ~]# firewall-config #runtime 临时生效,立即生效##permanent 更改配置文件,永久的,重新加载生效动态监控配置火墙时的动态情况[root@route ~]# watch -n 1 firewall-cmd --list-all临时更改:在runtime下是临时生效,并且是立刻生效(1)可以看到初始化支持的服务有dhcpv6-client ssh (2)在public区域下勾选http服务,可以看到已经立即生效永久更改:permanent下,更改配置文件,重新加载后永久生效(1)在public区域下勾选http服务,可以看到并没有生效更改默认指定区域:修改默认区域(1)一般情况下,默认的区域是public(2)选择Change Default Zone
开启httpd[root@route ~]# systemctl start httpd
开启httpd[root@route ~]# systemctl start httpd测试:在浏览器中可以看到无法连接
查看防火墙状态:发现没有服务中httpd
可通过编写火墙默认的public区域配置文件,来永久开启服务[root@route ~]# vim /etc/firewalld/zones/public.xml在第七行加入http服务: <service name="http"/>
重启火墙[root@route ~]# systemctl restart firewalld再测试在浏览器中可以看到已经成功访问
(二)命令行管理firewalld关于网络区域的配置:
安装软件[root@route ~]# yum install firewalld firewall-config -y(1)常用命令开启防火墙[root@route ~]# systemctl start firewalld开机自启防火墙[root@route ~]# systemctl enable firewalld关闭防火墙[root@route ~]# systemctl stop firewalld开机自动关闭防火墙[root@route ~]# systemctl disable firewalld查看防火墙状态[root@route ~]# firewall-cmd --state查看防火墙管理的设备[root@route ~]# firewall-cmd --get-active-zones查看防火墙生效的区域[root@route ~]# firewall-cmd --get-default-zone查看防火墙所有的区域[root@route ~]# firewall-cmd --get-zones列出关于public区域的服务设置[root@route ~]# firewall-cmd --zone=public --list-all列出关于trusted区域的服务设置[root@route ~]# firewall-cmd --zone=trusted --list-all列出可使用的服务[root@route ~]# firewall-cmd --get-services修改默认区域为trusted[root@route ~]# firewall-cmd --set-default-zone=trusted修改默认区域为public[root@route ~]# firewall-cmd --set-default-zone=public举例演示:
(2)高级配置
临时添加服务(默认的区域)[root@route ~]# firewall-cmd --add-service=https临时删除服务(默认的区域)[root@route ~]# firewall-cmd --remove-service=https 永久添加服务(默认的区域)[root@route ~]# firewall-cmd --add-service=https --permanent永久删除服务(默认的区域)[root@route ~]# firewall-cmd --remove-service=https --permanent 临时添加端口(默认的区域)[root@route ~]# firewall-cmd --add-port=8080/tcp临时删除端口(默认的区域)[root@route ~]# firewall-cmd --remove-port=8080/tcp 永久添加端口(默认的区域)[root@route ~]# firewall-cmd --add-port=8080/tcp --permanent永久删除端口(默认的区域)[root@route ~]# firewall-cmd --remove-port=8080/tcp --permanent 添加接口(默认的区域)[root@route ~]# firewall-cmd --add-interface=eth1删除接口(默认的区域)[root@route ~]# firewall-cmd --remove-interface=eth1 临时拒绝主机172.25.254.86的所有网络连接[root@route ~]# firewall-cmd --add-source=172.25.254.86 --zone=block永久拒绝主机172.25.254.86的所有网络连接[root@route ~]# firewall-cmd --add-source=172.25.254.86 --zone=block --permanent不中断连接,重启防火墙策略[root@route ~]# firewall-cmd --reload中断连接,重启防火墙策略[root@route ~]# firewall-cmd --complete-reload关闭上述[root@route ~]# firewall-cmd --remove-source=172.25.254.86 --zone=block[root@route ~]# firewall-cmd --remove-source=172.25.254.86 --zone=block --permanent 查看firewalld的服务相关配置文件[root@route ~]# cd /usr/lib/firewalld/services/查看firewalld的区域相关配置文件[root@route ~]# cd /etc/firewalld/zones/
二、iptables的相关配置
(1)iptables的常用命令
[root@route ~]# yum install iptables-services.x86_64 -y[root@route ~]# systemctl start iptables[root@route ~]# systemctl enable iptables[root@route ~]# systemctl stop iptables[root@route ~]# systemctl disable iptables(2)iptables的高级配置
关闭firewalld并且开机自动关闭[root@route ~]# systemctl stop firewalld[root@route ~]# systemctl disable firewalld[root@route ~]# systemctl mask firewalld开启iptables,并且开机自启动[root@route ~]# yum install iptables -y[root@route ~]# systemctl start iptables.service[root@route ~]# systemctl enable iptables.service列出指定filter表信息[root@route ~]# iptables -t filter -nL查看配置文件[root@route ~]# vim /etc/sysconfig/iptables刷新清空iptables[root@route ~]# iptables -F保存状态[root@route ~]# service iptables save列出默认表信息[root@route ~]# iptables -nL所有INPUT服务都丢弃并且不回应[root@route ~]# iptables -P INPUT DROP
添加接受来自回环地址的[root@route ~]# iptables -A INPUT -i lo -j ACCEPT添加接受tcp协议80端口的服务[root@route ~]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT添加接受tcp协议22端口的服务[root@route ~]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT拒绝全部的INPUT链服务[root@route ~]# iptables -A INPUT -j REJECT查看之,[root@route ~]# iptables -nL
3、防火墙策略优化若是第一次访问可以,则第二次访问就不会再问 ,这就是优化状态。注:系统重启会改变状态的数据包状态:第一次连接:NEW 连接中:ESTABLISHED 连接过的:RELATED[root@route ~]# iptables -F ##刷新清空策略[root@route ~]# service iptables save ##保存[root@route ~]# iptables -nL ##查看
关于iptables的参数:-t 指定表-L 列出表-A 永远加在最后一条-D 删除某一条链里面的策略-i 输入 (-i lo 表示是从回环地址进来的)-o 输出-I 插入到某一条,默认第一条(-I INPUT 3 插入到第三行,不写3的话默认添加到第一个)-m 状态-j 动作(ACCEPT | REJECT)-s 资源(无,则所有)-P 策略-p 协议-R 更改--dport 端口-N 新建一个链-E 修改链名称-X 删除链
相关文章推荐
- centos7 && centos6.5部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发
- Linux防火墙配置(iptables, firewalld)
- netfilter/iptables 简介使用 netfilter/iptables 为 Linux(内核 2.4.x)配置防火墙
- Linux中防火墙firewalld的配置与基本命令解释
- Linux 中使用iptables配置防火墙
- 配置iptables防火墙(二)
- Linux iptables防火墙详解 + 配置抗DDOS攻击策略实战
- Linux系统Iptables的常用防火墙配置方法
- iptables 简单防火墙配置
- iptables防火墙的配置
- iptables防火墙的基本配置
- CentOS下配置iptables防火墙
- Centos 配置iptables防火墙
- CentOS7下iptables防火墙配置
- Centos 7禁用firewalld安装iptables防火墙
- 配置防火墙,开启80端口、3306端口 & iptables 使用详解
- CentOS防火墙iptables的配置方法详解
- 阿里云Centos配置iptables防火墙
- CentOS 7.0 升级之防火墙 firewalld 取代 iptables