firewall常用操作
服务启停
service firewalld stop && chkconfig firewalld off
service firewalld start
开放端口&重载配置
firewall-cmd --zone=public --permanent --add-port=8080/tcp
firewall-cmd --reload
参数解析
--zone=public
--permanent 配置持久化但不会立即生效
--add-port 配置端口和协议
--reload 重载配置
根据ip开放或者限制
方式1: firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port port=8080 protocol=tcp accept'
方式2: firewall-cmd --permanent --zone=public --add-rich-rule='rule family=ipv4 source address=192.168.1.100 port port=8080 protocol=tcp accept'
参数解析
--add-rich-rule 添加规则,具体ip,协议,端口等
--remove-rich-rule 删除规则
动作:
accept 允许
drop 丢弃
reject 拒绝
使用iptables
Centos7默认使用firewalld,如果使用多了Centos6可能对命令不是很习惯,那么可以安装iptables使用
yum -y install iptables-services
service iptables save