linux 防火墙

linux防火墙

  1. selinux 
    在配制远程连接时是要关闭selinux的。 
    临时关闭selinux:

     setenforce 0

    永久关闭要编辑配置文件

     vim /etc/selinux/config
    
     SELINUX=disabled

    平时一般关闭selinux

2.iptables

iptables是linux的防火墙机制。在centos6时,是用的netfilter机制,centos7时用的是firewalld机制。 
由于我们装的是centos7,防火墙机制就是firewalld,想使用netfilter,就必须将firewald停掉,开启netfilter. 
关闭firewalld:

不让firewalld开机启动:

[root@shuai-01 network-scripts]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

停掉firewalld服务:

[root@shuai-01 network-scripts]# systemctl stop firewalld

安装netfilter:

[root@shuai-01 network-scripts]# yum install -y iptables-services

开启iptables服务:

[root@shuai-01 network-scripts]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@shuai-01 network-scripts]# systemctl start iptables

netfilter的五个表:(filter ,nat , mangle , raw , security) 
这里主要了解filter和nat 。 
filter表主要用于过滤包,包含三个链INPUT , OUTPUT , FORRWARD. 
nat表主要用于网络地址转换,包含三个链PREROUTING , OUTPUT , POSTROUTING 。

当数据包进来,是本机数据包:PREROUTING , INPUT ,localhost , OUTPUT , POSTROUTING 
不是本机数据包: PREROUTING , FORWARD , POSTROUTING 
一个讲IPtables的五个表的文章: 
http://blog.51cto.com/907832555/1944919

iptables相关的命令和用法:

  • 查看iptables相关规则:

    命令:iptables 
    选项: 
    -t 后接表名,表示选择那张表(默认是filter表) 
    -nvL 表示查看表的规则 
    -F 表示清空规则 
    -Z 表示把包的流量计数器置零

    [root@shuai-01 network-scripts]# iptables -nvL

    防火墙的规则保存在/etc/sysconfig/iptables中

    • 查看nat表的规则:

              [root@shuai-01 network-scripts]# iptables -t nat -nvL
              Chain PREROUTING (policy ACCEPT 2 packets, 152 bytes)
               pkts bytes target     prot opt in     out     source               destination         
      
      - 清空filter表的规则:
      
      [root@shuai-01 network-scripts]# iptables -F
      [root@shuai-01 network-scripts]# iptables -nvL
      Chain INPUT (policy ACCEPT 5 packets, 356 bytes)
       pkts bytes target     prot opt in     out     source               destination         
      
      Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
       pkts bytes target     prot opt in     out     source               destination         
      
      Chain OUTPUT (policy ACCEPT 4 packets, 448 bytes)
       pkts bytes target     prot opt in     out     source  
    • 重启标的规则:

      [root@shuai-01 network-scripts]# service iptables restart
      Redirecting to /bin/systemctl restart  iptables.service
      [root@shuai-01 network-scripts]# iptables -nvL
      Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
       pkts bytes target     prot opt in     out     source               destination         
         24  1688 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
          0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
          0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
          0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
          0     0 REJECT     all  --  *      *       0.0.0.0/0  

  • 增加/删除一条规则

    命令:iptables 
    选项: 
    -A/-D :表示增加/删除一条规则(后接INPUT,OUTPUT) 
    -I : 表示插入一条规则(后接INPUT,OUTPUT) 
    -P :表示预设策略 
    -p :表示指定协议(tcp , udp , icmp) 
    –sport :表示指定源端口,跟-p一起使用 
    –dport : 表示指定目标端口,跟-p一起使用 
    -s : 表示指定源IP 
    -d :表示指定目的IP 
    -j :后跟动作(ACCEPT表示允许包,DROP表示丢掉包,REJECT表示拒绝包) 
    -i :指定网卡

    • 增加一条规则 
      将来源10.12.11.13的22端口到目的12.11.13.14的80端口的tcp包丢掉

       [root@shuai-01 network-scripts]# iptables -A INPUT -s 10.12.11.13 -p tcp --sport 22 -d 12.11.13.14 --dport 80 -j DROP
    • 插入一条规则 将来源1.1.1.1的所有数据包丢掉

      [root@shuai-01 network-scripts]# iptables -I INPUT -s 1.1.1.1 -j DROP
    • 添加一条规则 将来源2.2.2.2的到本机80端口的tcp包丢掉

       [root@shuai-01 network-scripts]# iptables -A INPUT -s 2.2.2.2 -p tcp --dport 80 -j DROP
    • 删除一条规则(将来源1.1.1.1的所有数据包丢掉)

      [root@shuai-01 network-scripts]# iptables -D INPUT -s 1.1.1.1 -j DROP
    • 按行删除规则

            [root@shuai-01 network-scripts]# iptables -nvL --line-number
      Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
      num   pkts bytes target     prot opt in     out     source               destination         
      1      534 37016 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
      2        0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
      3        0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
      4        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
      5        0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
      6        0     0 DROP       tcp  --  *      *       10.12.11.13          12.11.13.14          tcp spt:22 dpt:80
      7        0     0 DROP       tcp  --  *      *       2.2.2.2              0.0.0.0/0            tcp dpt:80
      
      Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
      num   pkts bytes target     prot opt in     out     source               destination         
      1        0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
      
      Chain OUTPUT (policy ACCEPT 31 packets, 2932 bytes)
      num   pkts bytes target     prot opt in     out     source               destination         
      [root@shuai-01 network-scripts]# iptables -D INPUT 7
      [root@shuai-01 network-scripts]# iptables -nvL
      Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
       pkts bytes target     prot opt in     out     source               destination         
        605 41764 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
          0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
          0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
          0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
          0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
          0     0 DROP       tcp  --  *      *       10.12.11.13          12.11.13.14          
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
从其他地方下载下来的。在这里与大家分享。 内容简介   《Linux防火墙》创造性地将防火墙技术和入侵检测技术相结合,充分展示开源软件的威力。书中全面阐述了iptables防火墙,并详细讨论了如何应用psad、fwsnort、fwknop 3个开源软件最大限度地发挥iptables检测和防御攻击的效力。大量真实例子以及源代码更有助于读者理解安全防御的原理、技术和实际作。 作者简介   Michael Rash,世界级的安全技术专家,以防火墙、入侵检测系统等方面的造诣享誉安全界。他是psad、fwsnort和fWknop等著名开源安全软件的开发者。也是屡获大奖的Dragon入侵防御系统的安全架构师。除本书外.他还与人合撰Snort 2.1 Intrusion Detection和Intrusion Prevention and Active Response。他同时还是Linux Joumal、SysAdmin和login等著名技术媒体的专栏作家。 目录   第1章 iptables使用简介 1   1.1 iptables 1   1.2 使用iptables进行包过滤 2   1.2.1 表 2   1.2.2 链 2   1.2.3 匹配 3   1.2.4 目标 3   1.3 安装iptables 4   1.4 内核配置 5   1.4.1 基本Netfilter编译选项 6   1.4.2 结束内核配置 7   1.4.3 可加载内核模块与内置编译和安全 7   1.5 安全性和最小化编译 9   1.6 内核编译和安装 9   1.7 安装iptables用户层二进制文件 10   1.8 默认iptables策略 11   1.8.1 策略需求 11   1.8.2 iptables.sh脚本的开头 12   1.8.3 INPUT链 13   1.8.4 OUTPUT链 15   1.8.5 FORWARD链 15   1.8.6 网络地址转换 16   1.8.7 激活策略 17   1.8.8 iptables-save与iptables-restore 18   1.8.9 测试策略:TCP 20   1.8.10 测试策略:UDP 21   1.8.11 测试策略:ICMP 22   1.9 本章总结 23   第2章 网络层的攻击与防御 24   2.1 使用iptables记录网络层首部信息 24   2.2 网络层攻击的定义 27   2.3 滥用网络层 28   2.3.1 Nmap ICMP Ping 28   2.3.2 IP欺骗 28   2.3.3 IP分片 30   2.3.4 低TTL值 30   2.3.5 Smurf攻击 31   2.3.6 DDoS攻击 32   2.3.7 Linux内核IGMP攻击 32   2.4 网络层回应 33   2.4.1 网络层过滤回应 33   2.4.2 网络层阈值回应 33   2.4.3 结合多层的回应 34   第3章 传输层的攻击与防御 35   3.1 使用iptables记录传输层首部 35   3.1.1 记录TCP首部 35   3.1.2 记录UDP首部 37   3.2 传输层攻击的定义 38   3.3 滥用传输层 38   3.3.1 端口扫描 38   3.3.2 端口扫射 46   3.3.3 TCP序号预测攻击 46   3.3.4 SYN洪泛 47   3.4 传输层回应 47   3.4.1 TCP回应 47   3.4.2 UDP回应 50   3.4.3 防火墙规则和路由器ACL 51   第4章 应用层的攻击与防御 53   4.1 使用iptables实现应用层字符串匹配 53   4.1.1 实际观察字符串匹配扩展 54   4.1.2 匹配不可打印的应用层数据 55   4.2 应用层攻击的定义 56   4.3 滥用应用层 56   4.3.1 Snort签名 57   4.3.2 缓冲区溢出攻击 57   4.3.3 SQL注入攻击 59   4.3.4 大脑灰质攻击 60   4.4 加密和应用层编码 62   4.5 应用层回应 63   第5章 端口扫描攻击检测程序psad简介 64   5.1 发展历史 64   5.2 为何要分析防火墙日志 64   5.3 psad特性 65   5.4 psad的安装 65   5.5 psad的 67   5.5.1 启动和停止psad 68   5.5.2 守护进程的唯一性

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值