查看firewalld是否开启
# systemctl is-enabled firewalld
enabled停止firewalld
# systemctl stop firewalld
确认firewalld是否停止
# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: inactive (dead)Jun 22 16:34:23 zabbix.cc systemd[1]: Stopped firewalld - dynamic ....
Hint: Some lines were elliized, use -l to show in full.关闭firewalld的开机自动启动
# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.确认firewalld开机自动启动以关闭
# systemctl is-enabled firewalld
disabled
那么停用了默认的防火墙,而用回之前的iptables,怎么设置呢?
如下:
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。
1、关闭firewall:
systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)2、iptables防火墙(这里iptables已经安装,可看另一篇博客,下面进行配置)
vi/etc/sysconfig/iptables #编辑防火墙配置文件 # sampleconfiguration for iptables service # you can edit thismanually or use system-config-firewall # please do not askus to add additional ports/services to this default configuration *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT[0:0] :OUTPUT ACCEPT[0:0] -A INPUT -m state--state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -jACCEPT -A INPUT -i lo -jACCEPT -A INPUT -p tcp -mstate --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -jACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEPT -A INPUT -j REJECT--reject-with icmp-host-prohibited -A FORWARD -jREJECT --reject-with icmp-host-prohibited COMMIT :wq! #保存退出备注:这里使用80和8080端口为例。***部分一般添加到“-A INPUT -p tcp -m state --state NEW -m tcp--dport 22 -j ACCEPT”行的上面或者下面,切记不要添加到最后一行,否则防火墙重启后不生效。
systemctlrestart iptables.service #最后重启防火墙使配置生效 systemctlenable iptables.service #设置防火墙开机启动