系统安全之iptables防火墙

一、简介

  工作在主机或网络边缘的,对进出的报文事先定义的规则进行检查,由软硬件两者协同工作,这就是防火墙。   


二、iptables常用选项

iptables命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
iptables — administration tool  for  IPv4 packet filtering and NAT
SYNOPSIS
    iptables [-t table] {-A|-C|-D} chain rule-specification
    iptables [-t table] -I chain [rulenum] rule-specification
    iptables [-t table] -R chain rulenum rule-specification
    iptables [-t table] -D chain rulenum
    iptables [-t table] -S [chain [rulenum]]
    iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options...]
    iptables [-t table] -N chain
    iptables [-t table] -X [chain]
    iptables [-t table] -P chain target
    iptables [-t table] -E old-chain-name new-chain-name
    rule-specification = [matches...] [target]
    match = -m matchname [per-match-options]
    target = -j targetname [per-target-options]


1)查看iptables,以数字形式显示,并且详细显示个参数 

iptables -L -n -v 或iptables -L -n -vv/iptables -L -n -vvv  


2)清除所有的规则,flush [chain],delete all the rule one by one  

iptables -F  


3)删除自定义的规则

iptables -F 


4)创建自定义的一个新链

iptables -N


5)链的记录清零   

iptables -Z   

 

6)常用的四表五链   

四表:


filter:过滤表    nat:网络地址转换    mangle:对报文进行重新的拆装    raw:关闭nat表上启用的连接追踪功能  


五链:


PREROUTING    INPUT    FORWARD    OUTPUT    POSTROUTING  

数据流向:

流入本机:PREROUTING-->INPUT

本机流出:OUTPUT-->POSTROUTING

转发:PREROUTING-->FORWARD-->POSTROUTING




三、实际操作

1)清除默认的链及其规则

iptables -F  iptables -X  iptables -Z 


2)配置允许ssh登录端口进入 

iptables -A INPUT -d 10.10.0.1 -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT  

iptables -A OUTPUT -s 10.1.0.1 -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT 


3)设置允许本机lo通信规则

iptables -A INPUT -i lo -j ACCEPT

iptables -A OUTPUT -o lo -j ACCEPT 


4、设置默认的防火墙禁止和允许规则

iptables -P INPUT DROP

iptables -P FORWARD DROP

iptables -P OUTPUT DROP 


5、开启信任的网段

iptables -A INPUT -s 10.1.0.0/16 -p all -j ACCEPT 


6、允许业务服务对外提供访问

iptables -A INPUT -p tcp --dport 80 -j ACCEPT  

iptables -A INPUT -d 10.1.249.4 -p icmp --icmp-type 8 -m limit --limit 2/second --limit-burst 5 -m state NEW,ESTABLISHED -j ACCEPT 

iptables -A OUTPUT -s 10.1.249.4 -p icmp --icmp-type 0 -m state --state ESTABLISHED -j ACCEPT  



本文转自chengong1013 51CTO博客,原文链接:http://blog.51cto.com/purify/1853419,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值