Linux实战案例(5)关闭Centos的防火墙

1、检查防火墙的状态

[root@LxfN1 ~]# service iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination

Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 DOCKER all -- 0.0.0.0/0 0.0.0.0/0
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0

Chain OUTPUT (policy ACCEPT)
num target prot opt source destination

Chain DOCKER (1 references)
num target prot opt source destination

表格:nat
Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
1 DOCKER all -- 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match dst-type LOCAL

Chain INPUT (policy ACCEPT)
num target prot opt source destination

Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
1 DOCKER all -- 0.0.0.0/0 !127.0.0.0/8 ADDRTYPE match dst-type LOCAL

Chain POSTROUTING (policy ACCEPT)
num target prot opt source destination
1 MASQUERADE all -- 172.17.0.0/16 0.0.0.0/0

Chain DOCKER (2 references)
num target prot opt source destination

2、以管理员身份关闭防火墙

[root@LxfN1 ~]# service iptables stop
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]

3、检查防火墙是否运行中

[root@LxfN1 ~]# service iptables status
iptables:未运行防火墙。

4、永久关闭防火墙

[root@LxfN1 ~]# chkconfig iptables off

5、关闭selinux

vi /etc/selinux/config

将SELINUX=enforcing改为SELINUX=disabled
需要重启机器生效!

CentOS 6:

1) 永久性生效,重启后不会复原

开启: chkconfig iptables on

关闭: chkconfig iptables off

2) 即时生效,重启后复原

开启: service iptables start

关闭: service iptables stop

CentOS 7:

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

查询TCP连接情况:

 netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

查询端口占用情况:

 netstat   -anp   |   grep  portno(例如:netstat –apn | grep 80)

原文地址:https://www.cnblogs.com/lexiaofei/p/6757352.html