之前总结的CentOS中间件系列安装教程都是在关闭防火墙的前提下进行的。在实战中,你可能会遇到端口故障等情况。如果是ECS云服务器,可以修改安全组策略。开启或关闭端口访问,但如果是自己的机器,需要手动关闭防火墙(或开启指定端口访问),下面介绍CentOS7和CentOS6防火墙的常用设置首先,确认服务器操作系统版本:shell>cat/etc/redhat-releaseCentOSLinuxrelease7.6.1810(Core)CentOS71,防火墙服务1)查看状态Active:active(运行),防火墙已启用shell>systemctlstatusfirewalldfirewalld.service-firewalld-动态防火墙守护进程已加载:已加载(/usr/lib/systemd/system/firewalld.service;已禁用;供应商预设:已启用)活动:自2020年4月6日星期一00:03:45CST起活动(运行);2s前Docs:man:firewalld(1)MainPID:5463(firewalld)CGroup:/system.slice/firewalld.service└─5463/usr/bin/python2-Es/usr/sbin/firewalld--nofork--nopidActive:不活动(死),防火墙关闭shell>systemctlstatusfirewalldfirewalld.service-firewalld-动态防火墙守护进程加载:加载(/usr/lib/systemd/system/firewalld.service;禁用;供应商预设:启用)活动:不活跃的ve(dead)Docs:man:firewalld(1)2)start&stopstartshell>systemctlstartfirewalldstopshell>systemctlstopfirewalldrestartshell>systemctlrestartfirewalld3)bootself-startallowbootshell>systemctlenablefirewalld禁止启动shell>systemctldisablefirewalld综上所述,如果CentOS7想简单粗暴的彻底关闭防火墙,直接执行:shell>systemctlstopfirewalldshell>systemctldisablefirewalld2,firewall命令1)查看运行状态,防火墙已启用shell>firewall-cmd--staterunningnotrunning,防火墙未启用interfaces:enp2s0sources:services:sshdhcpv6-clientports:3888/tcp2181/tcpprotocols:masquerade:noforward-ports:source-ports:icmp-blocks:richrules:3)端口控制查看所有启用的端口shell>firewall-cmd--list-ports3888/tcp2181/tcp查看指定端口是否开启shell>firewall-cmd--query-port=3306/tcpnoshell>firewall-cmd--query-port=2181/tcpyesaddportshell>防火墙-cmd--add-port=2888/tcp--permanentsuccessshell>firewall-cmd--add-port=65001-65010/tcp--permanentshell>firewall-cmd--reloadsuccess#查看是否添加成功shell>firewall-cmd--list-ports3888/tcp2181/tcp2888/tcpdeleteportshell>firewall-cmd--remove-port=2888/tcp--permanentsuccessshell>firewall-cmd--reloadsuccess#查看是否删除成功shell>firewall-cmd--list-ports3888/tcp2181/tcprangeaddshell>firewall-cmd--add-port=65001-65010/tcp--permanentsuccessshell>firewall-cmd--reloadsuccessshell>firewall-cmd--list-ports3888/tcp2181/tcp65001-65010/tcpreload(修改防火墙规则后需要执行reload)shell>firewall-cmd--reloadsuccessCentOS61,查看防火墙是否开启状态shell>serviceiptablesstatusTable:filterChainINPUT(policyACCEPT)numtargetprotoptsourcedestination1ACCEPTtcp--0.0.0.0/00.0.0.0/0tcpdpt:88882ACCEPTtcp--0.0.0.0/00.0.0.0/0tcpdpt:92003接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:90004接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:70025接受tcp--0.0.0.0/00.0。0.0/0tcpdpt:156726接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:156727接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:80008接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:80829接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:801010接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:876911接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:637912接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:330613接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:567214接受tcp--0.0.0.0/00.0.0.0/0tcpdpt:1567215ACCEPTtcp--0.0.0.0/00.0.0.0/0tcpdpt:218116接受所有--0.0.0.0/00.0.0.0/0状态相关,已建立17接受icmp--0.0.0.0/00.0.0.0/018接受所有--0.0.0.0/00.0.0.0/019接受tcp--0.0.0.0/00.0.0.0/0状态新tcpdpt:2220接受tcp--0.0.0.0/00.0。0.0/0状态NEWtcpdpt:8021REJECTall--0.0.0.0/00.0.0.0/0reject-withicmp-host-prohibited22ACCEPTtcp--0.0.0.0/00.0.0.0/0tcpdpt:700223ACCEPTtcp--0.0.0.0/00.0.0.0/0tcpdpt:800124ACCEPTtcp--0.0.0.0/00.0.0.0/0多端口dports8888ChainFORWARD(policyACCEPT)numtargetprotoptsourcedestination1拒绝所有--0.0.0.0/00.0.0。0/0reject-withicmp-host-prohibitedChainOUTPUT(policyACCEPT)numtargetprotoptsourcedestinationfirewallisclosedshell>serviceiptablesstatusiptables:Firewallisnotrunning.2,start&stopopenfirewallshell>服务iptablesstartiptables:应用防火墙规则:[确定]关闭防火墙外壳>服务iptablesstopiptables:将链设置为策略接受:过滤器[确定]iptables:刷新防火墙规则:[确定]iptables:卸载模块:[确定]重新启动防火墙外壳>服务iptablesrestartiptables:将链设置为策略接受:过滤[OK]iptables:刷新防火墙规则:[OK]iptables:卸载模块:[OK]iptables:应用防火墙规则:[OK]3.引导自启动允许引导shell>chkconfigiptablesonprohibits启动shell>chkconfigiptablesoff综上所述,如果CentOS6要简单粗暴的完全关闭防火墙,直接执行:shell>serviceiptablesstopshell>chkconfigiptablesoff4,开启指定端口shell>vim/etc/sysconfig/iptables添加如下内容(假设开启的端口为“2888”)-AINPUT-ptcp-mtcp--dport2888-jACCEPTrestartfirewallshell>serviceiptablesrestartshell>serviceiptablesstatus表:filterChainINPUT(policyACCEPT)numtargetprotoptsourcedestination...16ACCEPTtcp--0.0.0.0/00.0.0.0/0TCPdpt:2888...
