linux防火墙配置基本步骤 win7防火墙设置


linux防火墙配置基本步骤 win7防火墙设置


在上节的笔记中,大家还记得那条防火墙的设置命令么?为什么要使用防火墙呢?Linux 系统中,安全的第一道防线就是它 。跟 Windows 中防火墙一样,都是要设置端口的开放与关闭 。那除了增加的命令之外,还有没有其它的操作呢?是如何实现的?那我们本节进行简单地讲解一下与防火墙有关的笔记内容 。
防火墙的配置,在 Centos 6 以前是使用命令 iptables,而到了 Centos 7 以之后的版本,改成了 firewall-cmd 命令,为了大家更方便的理解,我把整个过程分解成(查看状态、增加端口操作、其它安全设置)三个方面给大家讲解,让大家尽可能明白防火墙是如何去配置的 。
一、如何去查看防火墙的状态以及防火墙开启与关闭
1、iptables 版本命令:
启动: service iptables start
关闭: service iptables stop
查看状态: service iptables status
设置开机禁用 : chkconfig iptables off
设置开机启用 : chkconfig iptables on
iptables 配置文件目录/etc/sysconfig/iptables,如果不想使用命令,也可以直接使用 vim/vi 来编辑配置文件,使用 cat 命令来查看配置内容 。
实例:
[root@localhost ~]# service iptables status //查看防火墙状态,开了就会有下面的内容表格:filterChain INPUT (policy ACCEPT) //接入的端口信息 numtargetprot opt sourcedestination1ACCEPTtcp--0.0.0.0/00.0.0.0/0tcp dpt:8089 Chain FORWARD (policy ACCEPT) //numtargetprot opt sourcedestinationChain OUTPUT (policy ACCEPT) //接出允许信息 numtargetprot opt sourcedestination[root@localhost ~]# service iptables status //没开防火墙的提示 iptables:未运行防火墙 。[root@localhost ~]# service iptables stop //关闭防火墙 iptables:将链设置为政策 ACCEPT:filter[确定]iptables:清除防火墙规则:[确定]iptables:正在卸载模块:[确定][root@localhost ~]# service iptables start //开启防火墙 iptables:应用防火墙规则:[确定][root@localhost ~]# 2firewall-cmd 版本命令
这里要对 systemctl 这个命令注释一下:
systemctl 命令结合了 service 与 chkconfig 两个命令的功能,是 Centos 7 版本后用来对“服务”进行管理的一个命令 。而 service 与 chkconfig 两个命令之后版本都没再出现过 。
启动服务:systemctl start firewalld
关闭服务:systemctl stop firewalld
重启服务:systemctl restart firewalld
显示服务的状态:systemctl status firewalld
开机时启用服务:systemctl enable firewalld
开机时禁用服务:systemctl disable firewalld
实例:
[root@localhost ~]# systemctl status firewalld //已开启防火墙状态● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: active (running) since 三 2021-10-13 22:43:01 CST; 3 weeks 6 days agoDocs: man:firewalld(1) Main PID: 840 (firewalld)//或者使用以下命令也可以查看[root@localhost ~]# firewall-cmd --staterunning[root@localhost ~]# systemctl state firewalld//未开启防火墙的提示 Unknown operation 'state'.[root@localhost ~]# systemctl status firewalld● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: inactive (dead) since 三 2021-11-10 17:50:09 CST; 17s agoDocs: man:firewalld(1)Process: 840 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS) Main PID: 840 (code=exited, status=0/SUCCESS)[root@localhost ~]# firewall-cmd --state//另外一种提示命令 not running 二、端口的放行及关闭
防火墙的端口开放与关闭,是运维工作当中常用的操作,安全配置上也有相关的要求 。因此我们要比较熟悉的学习到这一块的内容 。当连接数据库或远程登陆等与网络相关的故障,我们都要第一时间想到防火墙的配置问题,可以让我们走少很多的弯路 。

推荐阅读