• 防火墙设置命令记录(iptables、firewall-cmd 命令记录)


    • firewall-cmd防火墙设置,add 是添加,remove 是删除
    [root@localhost nginx-1.16.0]# iptables -F    #清空iptables防火墙
    [root@localhost nginx-1.16.0]# firewall-cmd --permanent --zone=public --add-service=https	#允许https和http流量通过
    success
    [root@localhost nginx-1.16.0]# firewall-cmd --permanent --zone=public --add-service=http
    success
    [root@localhost nginx-1.16.0]# firewall-cmd --reload 
    success
    
    [root@michael ~]# firewall-cmd --get-default-zone	#查看当前默认使用的区域,public
    [root@michael ~]# firewall-cmd --get-zone-of-interface=ens160	#查看网卡绑定区域
    [root@michael ~]# firewall-cmd --set-default-zone=drop	#修改默认区域为drop
    # 查询public区域是否允许http流量通过
    [root@michael ~]# firewall-cmd --zone=public --query-service=http
    [root@michael ~]# firewall-cmd --zone=public --add-service=http	#添加允许http流量
    # 查询https服务是否在public区域永久生效
    [root@michael ~]# firewall-cmd --permanent --zone=public --query-service=https
    #放行tcp协议的8800-8888端口
    [root@localhost ~]# firewall-cmd --zone=public --add-port=8800-8888/tcp
    [root@localhost ~]# firewall-cmd --list-ports	#查询有哪些端口被允许使用
    [root@localhost ~]# firewall-cmd --list-services	#查询有哪些服务被允许使用
    #拒绝某个服务用 --remove-service,拒绝某个端口用 --remove-port
    [root@localhost ~]# firewall-cmd --permanent --zone=public --remove-service=https
    [root@localhost ~]# firewall-cmd --reload
    #端口号转发使用参数 --add-forward-port
    [root@localhost ~]# firewall-cmd --permanent --zone=public --add-forward-port=port=8888:proto=tcp:toport=22:toaddr=192.168.0.40
    #添加复规则 --add-rich-rule,删除复规则 --remove-rich-rule
    [root@localhost ~]# firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.0.0/24" service name="ssh" reject"
    

    • iptables 防火墙常用命令示例:
    [root@michael ~]# iptables -P INPUT DROP	#拒绝所有访问
    [root@michael ~]# iptables -I INPUT -s 127.0.0.1 -p icmp -j ACCEPT	#添加ping自己
    [root@michael ~]# iptables -I INPUT -s 192.168.0.5 -p icmp -j ACCEPT
    #设置可以访问http、https的端口
    [root@michael ~]# iptables -I INPUT -s 192.168.0.5 -p tcp --dport 80 -j ACCEPT
    [root@michael ~]# iptables -I INPUT -s 192.168.0.5 -p tcp --dport 443 -j ACCEPT
    
    [root@michael ~]# iptables -P INPUT ACCEPT	#允许所有访问,开启所有规则
    [root@michael ~]# iptables -I INPUT -s 192.168.0.5 -p icmp -j REJECT #拒绝ping包
    [root@michael ~]# iptables -I INPUT -s 192.168.0.5 -p icmp -j DROP	#直接丢包
    [root@michael ~]# iptables -I INPUT -s 192.168.0.0/24 -p tcp --dport 80 -j DROP
    [root@michael ~]# iptables -I INPUT -s 192.168.0.0/24 -p tcp --dport 10000:15000 -j DROP
    [root@michael ~]# service iptables save		#保存规则
    [root@michael ~]# iptables -L		#查看规则
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    DROP       tcp  --  192.168.0.0/24       anywhere             tcp dpts:ndmp:hydap
    DROP       tcp  --  192.168.0.0/24       anywhere             tcp dpt:http
    ACCEPT     icmp --  192.168.0.5          anywhere            
    DROP       icmp --  192.168.0.5          anywhere            
    REJECT     icmp --  192.168.0.5          anywhere             reject-with icmp-port-unreachable
    ACCEPT     tcp  --  192.168.0.5          anywhere             tcp dpt:https
    ACCEPT     tcp  --  192.168.0.5          anywhere             tcp dpt:http
    ACCEPT     icmp --  192.168.0.5          anywhere            
    ACCEPT     icmp --  localhost            anywhere            
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination
    
  • 相关阅读:
    【转】有关Managed code和Native code的区别
    【转】wince6.0 vs2005 编译选项详解
    【转】Wince Device Emulator使用介绍Device Emulator 2.0
    Dapper基础增删查改、事务和存储过程
    SharpCompress的压缩文件解压和文件夹压缩
    MVC WebAPI 的基本使用
    prepare for travel 旅行准备
    gossip
    JS笔记(3) 词汇结构(待续。。。)
    Good Points Bad Points
  • 原文地址:https://www.cnblogs.com/Micro0623/p/15520162.html
Copyright © 2020-2023  润新知