Linux 操作系统防火墙配置(centos)

1. hosts.allow和 host.deny:

文件路径/etc/hosts.allow 和 /etc/hosts.deny
当hosts.allow和 host.deny相冲突时,以hosts.allow设置为准。
配置如下

#服务:IP:动作
sshd: 192.168.88.*: ALLOW
sshd:ALL: DENY

2. 防火墙iptables

* 即时生效

iptables -A INPUT -s 192.168.11.125 -j DROP
iptables -D INPUT 1 删除序号1

*永久生效

编辑/etc/sysconfig/iptables 配置文件
保存
service iptables save
Usage: iptables {start|stop|reload|restart|condrestart|status|panic|save}

3. 防火墙firewalld

firewall-cmd --list-all 查看防火墙状态策略情况

[root@RAC ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: dhcpv6-client ssh
  ports: 5601/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule family="ipv4" source address="192.168.0.0/16" port port="5601" protocol="tcp" accept
        
*即时生效

firewall-cmd --add-port=5601/tcp
firewall-cmd --remove-port=5601/tcp

*永久生效–permanent
  • 端口方式
    firewall-cmd --permanent --zone=public --add-port=5601/tcp
    firewall-cmd --permanent --zone=public --add-port=5601/tcp
    firewall-cmd --permanent --add-port=5601/tcp
    firewall-cmd --permanent --remove-port=5601/tcp
    注:以上配置都需要重新加载才能生效
    firewall-cmd --reload
  • rich-rules
    firewall-cmd --permanent --add-rich-rule=‘rule family=“ipv4” source address=“192.168.0.0/16” port protocol=“tcp” port=“5601” accept’
    firewall-cmd --permanent --add-rich-rule="rule family=“ipv4” source address=“192.168.0.0/16” port protocol=“tcp” port=“5601” reject
    firewall-cmd --permanent --remove-rich-rule=‘rule family=“ipv4” source address=“192.168.0.0/16” port protocol=“tcp” port=“22” accept’
    注:以上配置都需要重新加载才能生效
    firewall-cmd --reload
    查看rich-rules
[root@RAC etc]# firewall-cmd --list-rich-rules
rule family="ipv4" source address="192.168.0.0/16" port port="5601" protocol="tcp" accept

猜你喜欢

转载自blog.csdn.net/Gavinqq/article/details/106902303