首先可以查看有哪些端口是开放状态:
netstat -ntpl
Centos 7.0 之前的版本,防火墙用的是 iptables,7.0 之后使用 firewalld 代替了 iptables,那么我们来分别看看这两种防火墙的命令操作:
iptables
1. 查看防火墙状态
systemctl status firewalld
service iptables status
2. 暂时关闭防火墙
systemctl stop firewalld
service iptables stop
3. 永久关闭防火墙
systemctl disable firewalld
chkconfig iptables off
4. 重启防火墙
systemctl enable firewalld
service iptables restart
5. 开放指定端口
编辑文件: vi /etc/sysconfig/iptables
添加开放端口:iptables -I INPUT -p tcp –dport 端口号 -j ACCEPT
保存配置:service iptables save
重启防火墙:service iptables restart
firewalld
1. 查看防火墙状态
systemctl status firewalld
firewall-cmd –state
2. 启动防火墙
systemctl start firewalld
3.禁用防火墙
systemctl stop firewalld
4.设置开机启动
systemctl enable firewalld
5.停止并禁用开机启动
sytemctl disable firewalld
6.重启防火墙
systemctl restart firewalld.service
firewall-cmd –reload
7. 开放指定端口
添加端口: firewall-cmd –zone=public –add-port=端口号/tcp –permanent
重启防火墙:systemctl restart firewalld.service