"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld

"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld
"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld
"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld
"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld
"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld
"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld
"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld
"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld
"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld
"Linux in respect of such a study" Chapter 8 iptables firewall and firewalld

Chapter 8 iptables firewall and firewalld

配置网卡的四种方式:1、编辑网卡的配置文件:[root@localhost 桌面]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777728IPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_FAILURE_FATAL=noNAME=eno16777728UUID=3c287b0a-f9a0-4dc4-a587-565df0458e76ONBOOT=yesIPADDR0=192.168.1.120PREFIX0=24GATEWAY0=192.168.1.1DNS1=114.114.114.114BOOTPROTO=noneDEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_FAILURE_FATAL=no[root@localhost 桌面]# systemctl restart network[root@localhost 桌面]# service network restart2、nmtui图形化工具RHEL7:nmtuiRHEL5/6:setup[root@localhost /]# nmtui3、nm-connection-editor图形化工具[root@localhost /]# nm-connection-editor4、图形化工具8.1 防火墙管理工具8.2 Iptables8.2.1 策略与规则链iptables服务把用于处理或过滤流量的策略条目称之为规则,多条规则可以组成一个规则链,而规则链则依据数据包处理位置的不同进行分类,具体如下:处理流入的数据包(INPUT);处理流出的数据包(OUTPUT);处理转发的数据包(FORWARD);在进行路由选择前处理数据包(PREROUTING);在进行路由选择后处理数据包(POSTROUTING)。一般来说,从内网向外网发送的流量一般都是可控且良性的,因此我们使用最多的就是INPUT规则链,该规则链可以增大***人员从外网***内网的难度。8.2.2 基本的命令参数 iptables是一款基于命令行的防火墙策略管理工具,好在对于日常的防火墙策略配置来讲,大家无需深入了解诸如“四表五链”的理论概念,只需要掌握常用的参数并做到灵活搭配即可,这就足以应对日常工作了。 iptables命令可以根据流量的源地址、目的地址、传输协议、服务类型等信息进行匹配,一旦匹配成功,iptables就会根据策略规则所预设的动作来处理这些流量。允许 accept拒绝 reject拒绝 log日志 drop查看防火墙已有策略:[root@localhost ~]# iptables -L清空防火墙已有策略:[root@localhost ~]# iptables -F限制一切流量通过:[root@localhost ~]# iptables -P INPUT DROP允许一切流量通过:[root@localhost ~]# iptables -P INPUT ACCEPT向INPUT 规则链添加允许icmp流量进入:-I 是在头部添加,-p 是协议,-j 是执行的动作。[root@localhost ~]# iptables -I INPUT -p icmp -j ACCEPT向INPUT 规则链中添加拒绝192.168.1.0/24网段的主机远程连接本机:[root@localhost ~]# iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 22 -j REJECT删除INPUT 规则链中刚刚加入的拒绝192.168.1.0/24网段的主机远程连接本机的规则链:[root@localhost ~]# iptables -D INPUT 1向INPUT 规则链中添加允许192.168.1.0/24网段的主机远程连接本机的22端口[root@localhost ~]# iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 22 -j ACCEPT向INPUT规则链中添加拒绝所有人访问本机12345端口的策略规则:[root@localhost ~]# iptables -I INPUT -p tcp --dport 12345 -j REJECT[root@localhost ~]# iptables -I INPUT -p udp --dport 12345 -j REJECT向INPUT规则链中添加拒绝所有主机访问本机1000~1024端口的策略规则:[root@localhost ~]# iptables -A INPUT -p tcp --dport 1000:1024 -j ACCEPT[root@localhost ~]# iptables -A INPUT -p udp --dport 1000:1024 -j ACCEPT向INPUT规则链中添加允许192.168.1.0/24 网段的主机访问本机80端口(Web服务)的策略规则:[root@localhost ~]# iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT8.3 firewalldiptables与firewall同时启用,iptables优先级更高?iptables运行在数据链路层,二者都是内核级别的。firewalld中常见的区域名称(默认为public)以及相应的策略规则如表8-2所示。表8-2 firewalld中常用的区域名称及策略规则区域默认规则策略trusted允许所有的数据包home拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh、mdns、ipp-client、amba-client与dhcpv6-client服务相关,则允许流量internal等同于home区域work拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh、ipp-client与dhcpv6-client服务相关,则允许流量public拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh、dhcpv6-client服务相关,则允许流量external拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh服务相关,则允许流量dmz拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh服务相关,则允许流量block拒绝流入的流量,除非与流出的流量相关drop拒绝流入的流量,除非与流出的流量相关电脑 firewall 当前使用的区域 是全局的防火墙[root@localhost 桌面]# firewall-cmd --get-default-zonepublic电脑 firewall 当前网卡使用的区域[root@localhost 桌面]# firewall-cmd --get-zone-of-interface=eno16777728public切换当前默认使用的区域为dmz:[root@localhost 桌面]# firewall-cmd --set-default-zone=dmzWarning: ZONE_ALREADY_SET: dmz[root@localhost 桌面]# firewall-cmd --get-default-zonedmz再改回来 当前默认使用的区域为public:[root@localhost 桌面]# firewall-cmd --set-default-zone=publicWarning: ZONE_ALREADY_SET: public[root@localhost 桌面]# firewall-cmd --get-default-zonepublic[root@localhost 桌面]# firewall-cmd --permanent --zone=publicsuccess修改网卡所在防火墙中的区域,永久生效[root@localhost 桌面]# firewall-cmd --permanent --zone=dmz --change-interface=eno16777728success永久生效模式:[root@localhost 桌面]# firewall-cmd --permanent --get-zone-of-interface=eno16777728dmz当前模式:需要重启服务器后,可以看到当前模式改为dmz。[root@localhost 桌面]# firewall-cmd --get-zone-of-interface=eno16777728public切断所有网络链接:panic紧急模式[root@localhost 桌面]# firewall-cmd --panic-onsuccess[root@localhost 桌面]# firewall-cmd --panic-offsuccess当前生效模式:查询当前public区域有没有放行ssh服务:[root@localhost 桌面]# firewall-cmd --zone=public --query-service=sshyes查询当前public区域有没有放行https服务:[root@localhost 桌面]# firewall-cmd --zone=public --query-service=httpsno添加放行https服务:[root@localhost 桌面]# firewall-cmd --zone=public --add-service=httpssuccess[root@localhost 桌面]# firewall-cmd --zone=public --query-service=httpsyes查询当前public区域有没有放行mysql服务:[root@localhost 桌面]# firewall-cmd --zone=public --query-service=mysqlno添加放行 mysql服务:[root@localhost 桌面]# firewall-cmd --zone=public --add-service=mysqlsuccess添加放行 mysql服务,永久生效模式:[root@localhost 桌面]# firewall-cmd --permanent --zone=public --add-service=httpssuccess[root@localhost 桌面]# firewall-cmd --reloadsuccess移除一个服务:[root@localhost 桌面]# firewall-cmd --zone=public --remove-service=sshsuccess[root@localhost 桌面]# firewall-cmd --zone=public --query-service=sshno添加一个服务:[root@localhost 桌面]# firewall-cmd --zone=public --add-service=sshsuccess[root@localhost 桌面]# firewall-cmd --zone=public --query-service=sshyes添加端口号:[root@localhost 桌面]# firewall-cmd --zone=public --add-port=8000-8800/tcpsuccess查询当前放通的端口:[root@localhost 桌面]# firewall-cmd --zone=public --list-ports8000-8800/tcp[root@localhost 桌面]# firewall-cmd --zone=public --add-port=22/tcpsuccess[root@localhost 桌面]# firewall-cmd --zone=public --add-port=3306/tcpsuccess[root@localhost 桌面]# firewall-cmd --zone=public --list-ports3306/tcp 8000-8800/tcp 22/tcp把原本访问本机888端口的流量转发到22端口,要且求当前和长期均有效:流量转发命令格式为firewall-cmd --permanent --zone=<区域> --add-forward-port=port=<源端口号>:proto=<协议>:toport=<目标端口号>:toaddr=<目标IP地址>:[root@localhost 桌面]# firewall-cmd --permanent --zone=public --add-forward-port=port=888:proto=tcp:toport=22:toaddr=192.168.2.120success[root@localhost 桌面]# firewall-cmd --reloadsuccess富规则:firewalld中的富规则表示更细致、更详细的防火墙策略配置,它可以针对系统服务、端口号、源地址和目标地址等诸多信息进行更有针对性的策略配置。它的优先级在所有的防火墙策略中也是最高的。比如,我们可以在firewalld服务中配置一条富规则,使其拒绝192.168.10.0/24网段的所有用户访问本机的ssh服务(22端口):[root@localhost 桌面]# firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" service name="ssh" reject"success[root@localhost 桌面]# firewall-cmd --reloadsuccessfirewall-config

Four-way firewall configuration: 1, iptables: 2, firewall-cmd: command operations 3, firewall-config: graphical user 4, access control lists services based on TCP Wrappers configuration file the application layer. Devil vim /etc/hosts.deny file vim /etc/hosts.allow file priority over the Angel Devil file when configuring TCP Wrappers services need to follow two principles:

  1. When writing to refuse policy rules, fill in the name of the service, rather than the protocol name;
  2. It is recommended to refuse to write policy rules, then write rules to allow policy to visually see the corresponding effect.

Reproduced in: https: //blog.51cto.com/13615251/2409375

Guess you like

Origin blog.csdn.net/weixin_34357267/article/details/93024368