Linux防火墙常用命令
centos7防火墙默认使用的是firewalld
centos6防火墙默认使用的是iptables
一、centos7
1、开放端口的命令格式:firewall-cmd --zone=public --add-port=端口/tcp --permanent
2、移除开放端口的命令格式:firewall-cmd --zone= public --remove-port=端口/tcp --permanent
3、临时关闭防火墙:systemctl stop firewalld.service
4、开启防火墙:systemctl start firewalld.service
5、永久关闭防火墙:systemctl disable firewalld.service
6、设置开机自启:systemctl enable firewalld.service
7、查看防火墙状态:firewall-cmd --state
8、查看防火墙开放端口:firewall-cmd --list-ports
9、查看某一端口是否开放: firewall-cmd --query-port=端口/tcp
10、指定ip开放端口:firewall-cmd --permanent --add-rich-rule=“rule family=“ipv4” source address=“指定的ip” port protocol=“tcp” port=“端口” accept”
11、防火墙禁ping:firewall-cmd --add-rich-rule=‘rule protocol value=icmp drop’ --permanent
二、centos6
1、开放端口命令:iptables -A INPUT -p tcp -m tcp --dport 端口 -j ACCEPT
2、指定ip开放端口:iptables -I INPUT -s 地址 -p tcp --dport 端口 -j ACCEPT
3、禁止指定ip访问:iptables -A INPUT -p tcp -s 地址 -j DROP
4、临时关闭防火墙:service iptables stop
5、重启防火墙:service iptables restart
6、永久关闭:chkconfig iptables off
7、开机自启:chkconfig iptables on
8、禁ping:iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -j DROP
9、解除禁ping:iptables -D INPUT -p icmp --icmp-type 8 -s 0/0 -j DROP