CentOS 6 and CentOS 7 firewall on and off

CentOS 6.5 to check the status of the firewall:

1

[linuxidc@localhost ~]$service iptable status

  Show results:

1

2

3

4

5

[linuxidc@localhost ~]$service iptable status

Redirecting to /bin/systemctl status  iptable.service

● iptable.service

   Loaded: not-found (Reason: No such file or directory)

   Active: inactive (dead)  --表示防火墙已经关闭

    CentOS 6.5 turn off firewall

1

2

[root@localhost ~]#servcie iptables stop                    --临时关闭防火墙

[root@localhost ~]#chkconfig iptables off                    --永久关闭防火墙

    CentOS 7.2 turn off firewall

CentOS 7.0 uses firewall as the firewall by default, here is the iptables firewall step.


firewall-cmd --state #View the default firewall status (notrunning is displayed when it is closed, and running is displayed when it is opened)

1

2

[root@localhost ~]#firewall-cmd --state

not running

   Check the status of the firewall:

Starting from centos7, systemctl is used to manage services and programs, including service and chkconfig.

1

2

[root@localhost ~]#systemctl list-unit-files|grep firewalld.service            --防火墙处于关闭状态

firewalld.service                          disabled

  or

1

2

3

4

[root@localhost ~]#systemctl status firewalld.service

● firewalld.service - firewalld - dynamic firewall daemon

   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)

   Active: inactive (dead)

   Turn off the firewall:

systemctl stop firewalld.service #stop firewall
systemctl disable firewalld.service #prohibit firewall from starting

1

2

[root@localhost ~]#systemctl stop firewalld.service

[root@localhost ~]#systemctl disable firewalld.service

1

2

3

4

5

6

7

8

启动一个服务:systemctl start firewalld.service

关闭一个服务:systemctl stop firewalld.service

重启一个服务:systemctl restart firewalld.service

显示一个服务的状态:systemctl status firewalld.service

在开机时启用一个服务:systemctl enable firewalld.service

在开机时禁用一个服务:systemctl disable firewalld.service

查看服务是否开机启动:systemctl is-enabled firewalld.service;echo $?

查看已启动的服务列表:systemctl list-unit-files|grep enabled

Centos 7 firewall command:

Check out the open ports:

firewall-cmd --list-ports

open port

firewall-cmd --zone=public --add-port=80/tcp --permanent

Command meaning:

--zone #scope

–add-port=80/tcp #Add port, the format is: port/communication protocol

–permanent #Permanent effect, invalid after restart without this parameter

restart firewall

firewall-cmd --reload #重启firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #View the default firewall status (notrunning is displayed when it is closed, and running is displayed when it is opened)

CentOS 7 and below iptables command

To open port 80, 22, 8080, enter the following command

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

Then save:

/etc/rc.d/init.d/iptables save

View open ports:

/etc/init.d/iptables status

Turn off the firewall 
1) It will take effect permanently and will not be restored after restarting

On: chkconfig iptables on

Off: chkconfig iptables off

2) It takes effect immediately, and it will be restored after restarting

Start: service iptables start

Shutdown: service iptables stop

查看防火墙状态: service iptables status

下面说下CentOS7和6的默认防火墙的区别

CentOS 7默认使用的是firewall作为防火墙,使用iptables必须重新设置一下

1、直接关闭防火墙

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

2、设置 iptables service

yum -y install iptables-services

如果要修改防火墙配置,如增加防火墙端口3306

vi /etc/sysconfig/iptables 

增加规则

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

保存退出后

systemctl restart iptables.service #重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

最后重启系统使设置生效即可。

systemctl start iptables.service #打开防火墙

systemctl stop iptables.service #关闭防火墙

解决主机不能访问虚拟机CentOS中的站点

前阵子在虚拟机上装好了CentOS6.2,并配好了apache+php+mysql,但是本机就是无法访问。一直就没去折腾了。 

 

具体情况如下 

1. 本机能ping通虚拟机 

2. 虚拟机也能ping通本机 

3.虚拟机能访问自己的web 

4.本机无法访问虚拟机的web 

 

后来发现是防火墙将80端口屏蔽了的缘故。 

 

检查是不是服务器的80端口被防火墙堵了,可以通过命令:telnet server_ip 80 来测试。 

 

解决方法如下: 

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 

然后保存: 

/etc/rc.d/init.d/iptables save 

重启防火墙 

/etc/init.d/iptables restart 

 

CentOS防火墙的关闭,关闭其服务即可: 

查看CentOS防火墙信息:/etc/init.d/iptables status 

关闭CentOS防火墙服务:/etc/init.d/iptables stop 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325824749&siteId=291194637