Centos7
Centos7 的firewalld 取代了iptables
查看开放端口
firewall-cmd --list-ports
1
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
1
开启范围端口 8080 - 9090范围的端口
firewall-cmd --zone=public --add-port=8080-9090/tcp --permanent
1
命令含义
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
1
2
3
防火墙命令
firewall-cmd --reload #重启firewall
firewall-cmd --state #查看防火墙状态
systemctl start firewalld.service #开启firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
1
2
3
4
5
Centos6
#查看开放端口
service iptables status
#开启8080端口
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
#开启命令:
service iptables start
#关闭命令:
service iptables stop
#永久关闭防火墙:
chkconfig iptables off
1
2
3
4
5
6
7
8
9
10
11
12
13
14
可能发生的异常
1.启动或者关闭防火墙没任何的提示
[root@ethnicity ~]# service iptables start
[root@ethnicity ~]# service iptables stop
1
2
2.查看防火墙的状态直接提示模块未加载
[root@ethnicity ~]# service iptables status
iptables: Firewall modules are not loaded.
1
2
修复方法
modprobe ip_tables #加载ip_tables模块
modprobe iptable_filter #加载iptable_filter模块
[root@ethnicity ~]# lsmod | grep iptable #查看模块,有模块即解决了
iptable_filter 2173 0
ip_tables 9567 1 iptable_filter