由于centos 7版本以后默认使用firewalld后,网上关于iptables的设置方法已经不管用了,
Centos7 开放端口
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload
查询端口是否打开
firewall-cmd --query-port=80/tcp
FirewallD is not running 报错执行 systemctl start firewalld
安装firewalld
root执行 # yum install firewalld firewall-config
运行、停止、禁用firewalld
启动:# systemctl start firewalld
查看状态:# systemctl status firewalld 或者 firewall-cmd --state
停止:# systemctl disable firewalld
禁用:# systemctl stop firewalld
======================CentOS 6.5==========================
关闭命令: service iptables stop (开发测试中使用)。 [root@localhost ~]# /etc/rc.d/init.d/service iptables restart | stop |status
永久关闭防火墙:chkconfig iptables off (开发测试中使用)
两个命令同时运行,运行完成后查看防火墙关闭状态
service iptables status