1 )重启后有效
打开: chkconfig iptables on
关闭: chkconfig iptables off
2 )即时生效,重启后失效
打开:服务启用启动
关闭:服务启用停止
此外,在Linux上的其他服务中,可以使用上述命令进行打开和关闭操作。
打开防火墙时,请设置以下内容,然后打开相关端口:
按如下方式修改/etc/sysconfig/iptables文件:
- arh-firewall-1-input-mstate-- statenew-mtcp-ptcp-- dport 80-j accept
- arh-firewall-1-input-mstate-- statenew-mtcp-ptcp-- dport 22-j accept
默认情况下,CentOS 7.0使用防火墙作为防火墙,但现在将其更改为iptables防火墙步骤。
1、关闭防火墙:
停止systemctlstopfirewalld.service # firewall
systemctldisablefirewalld.service #禁止启动防火墙
firewall-cmd --state #查看默认防火墙状态(禁用时显示为notrunning,启用时显示为running ) ) ) ) ) ) ) ) )。
2、iptables防火墙(这里安装了iptables。 配置如下) )。
编辑vi/etc/sysconfig/iptables #防火墙配置文件
# sampleconfigurationforiptablesservice
# youcaneditthismanuallyorusesystem-config-firewall
# pleasedonotaskustoaddadditionalports/servicestothisdefaultconfiguration
*过滤器
:INPUT ACCEPT [0:0]
:前锋accept [ 0:0 ]
:OUTPUT ACCEPT[0:0]
- a输入- m状态- -状态related,ESTABLISHED -j ACCEPT
- a输入- p icmp-j接受
- a输入- I lo-j accept
- a输入- ptcp-mstate-- statenew-mtcp-- dport 22-j accept
- a输入- ptcp-mstate-- statenew-mtcp-- dport 80-j accept
- a输入- ptcp-mstate---statenew-mtcp-- dport 8080-j accept
- a input-j reject-- reject-with icmp-host-prohibited
- aforward-j reject-- reject-with icmp-host-prohibited
命令式
:wq! #保存结束
备注:以下是使用80和8080端口的示例。 **部分通常添加到“- a input-ptcp-mstate-- statenew-mtcp-- dport 22-j accept”行的上方或下方。 请不要添加到最后一行。 防火墙重新启动时不会生效。
systemctlrestartiptables.service #最后重新启动防火墙以启用配置
systemctlenableiptables.service #配置打开防火墙并启动
全文结束.
---------分割线---------
---------分割线---------