• iptables


    防火墙的发展
    版本       机制       命令
    2.2版本    ipfw         ipfwadm
    2.4版本   ipchain     ipchains
    2.6版本   netfilter   iptables

    iptables的结构:四张表
    raw                mangle           nat            filter

    每张表还包含了链
    INPUT
    OUTPUT
    FORWARD


    man iptables
    表里面包含链,链里面写一条一条的规则
    ---->链---->规则

    规则的应用顺序
    表的匹配顺序
    raw-->mangle-->nat-->filter
    链的匹配顺序 取决于数据流向
    规则的匹配顺序
    第一条规则,匹配上就不会再向后
    如果匹配不到,再匹配第二条
    如果所有匹配完还没匹配,使用默认规则

    iptables标准用法
    iptables [-t 表名] 命令选项 [链名] [条件匹配] [-j目标动作 或 跳转]
    不写表名代表的是filter表
    =======
    命令选项:
    -A 追加
    -D 删除表里面链的规则
    -I 插入一条规则 默认插入到第一个规则
    -L 罗列
    -F 清空
    -X 删除一个链,一般删除自定义链
    -P  默认规则
    -E  重命名一个链
    iptables -t nat -L 查看nat表
    关于icmp协议进站的都丢弃
    iptables -t filter -A INPUT -p icmp -j DROP
    iptables -nL 不做名称解析罗列
    关于icmp协议的都接收
    iptables -t fileter -I INPUT -p icmp -j ACCEPT
    删除filter表里面input链的第一条规则
    iptables -D INPUT 1
    清空filter表INPUT链
    iptables -F INPUT
    iptables -F 清空filter表
    iptables -P OUTPUT DROP
    限定端口号 dport目标端口  sport源端口
    iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    ========
    条件匹配:
    协议匹配
    地址匹配 -s源地址 -d目标地址  -i网络接口=对应接收数据包 -o网络接口=发送数据包
    filter表里面来自这个ip地址的进站消息全部丢弃
    iptables -A INPUT -s 192.168.0.250 -j DROP
    只要是出站的目标地址是它的就丢弃
    iptables -I OUTPUT -d 192.168.0.250 -j DROP
    进站的 eth0接口的进站的全部丢弃
    iptables -I INPUT -i eth0 -j DROP
    etho接口出站的
    iptables -I OUTPUT -o eth0

    iptables -I INPUT -p icmp -s 192.168.0.250 -j DROP

    使用某个协议匹配某个端口来过滤服务
    iptables -A INPUT -p tcp --dport 22 -j DROP
    iptables -A INPUT -p tcp --dport 53 -j DROP tcp53端口是DNS服务

    仅允许 254 和 自己 去访问自己的httpd服务
    iptables -I INPUT -s 192.168.0.254 -p tcp --dport 80  -j ACCEPT
    iptables -A INPUT -s 192.168.0.250 -p tcp --dport 80  -j ACCEPT
    iptables -P INPUT -p tcp --dport 80 DROP

    iptables -A INPUT   -s 192.168.0.250 -p tcp --dport 80  -j ACCEPT
    iptables -I INPUT  ! -s 192.168.0.254 -p tcp --dport 80  -j DROP
    端口匹配必须和协议匹配结合一起使用

    man icmp得到icmp的一些参数 0接收包  8回应包
    iptables -A INPUT -p icmp --icmp-type 8 -j DROP 回应包drop掉

    =====
    目标动作和跳转
    DROP ACCEPT REJECT
    DROP直接丢弃数据包不会给你任何响应信息,REJECT拒绝数据包通过,不过会给数据发送端响应信息
    iptables -N Mylan1
    iptables -nL
    由源地址过来的都交给Mylan1来处理
    iptables -A INPUT -s 192.168.0.250 -j Mylan1
    iptables -A Mylan1 -p icmp -j DROP
    iptables -X Mylan1 删除自定义的链
    但是删除前要先清空该链
    iptables  -F

    ========
    nat表  网络地址转换

    snat 源地址转换
    来自于这个网段的地址 从eth1这个接口出去的 做源地址转换 转换成219地址
    iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j SNAT --to-soruce 219.29.30.31

    dnat 目标地址转换
    iptables -t nat -A PRTROUTING -d 218.29.30.31 -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.0.254


    重启生效
    /etc/init.d/iptables save 保存,自动保存到下面的文件中
    vim /etc/sysconfig/iptables
    iptables-save > /etc/sysconfig/iptables
    iptables-restore < /etc/sysconfig/iptables
    chkconfig iptables on


    tcp_wrappers tcp被包裹起来的机制
    ldd  /usr/bin/ssh 查看它是非被wrapp机制包裹

    /etc/host.allow  允许那些客户端来访问
    ALL:127.  所有服务自己可以访问
    sshd: ALL 所有人都可以sshd
    rpcbind,mountd  192.168.0.0

    /etc/host.deny   拒绝哪些客户端来访问
    ALL:ALL 

    先匹配host.allow,匹配到就允许,匹配不到再去再去deny文件

  • 相关阅读:
    Django admin 注册自己的路由
    django admin字段设置大全
    Python 装饰器原理
    css hack中遇到的一些问题
    阿里巴巴iconfont的正确使用方法
    css中position(absolute)与margin同时使用的情况
    关于IE浏览器不支持border-radius,box-shadow,text-shadow的解决方法
    大唐项目的总结
    js中的词法作用域
    easyui中datagrid自带loading效果
  • 原文地址:https://www.cnblogs.com/augustyang/p/6087240.html
Copyright © 2020-2023  润新知