0、iptables(ACL)的匹配原则:

与cisco等一致,从上到下依次匹配。

1、iptables的基本用法:。

(1)命令格式

iptables [–ttable] command [match] [target]

table:表,有三个:filter(过滤) nat(转发) mangle(更改)

表的组成格式:链表。

command:命令,有很多:

-A –append:添加

-D –delete:  删除

-G –policy:  策略

-N –new-chain 链表

-L –list:      列出链中规则

-R –replace:  替换链表匹配的规则

-C –check:   检查匹配

-I –insert:     插入规则

举例:

-A INPUT

-I OUTPUT 3(插入到第3条)

-D INPUT 10(删除第10条)

match:匹配

-p:策略

-s:源

-d:目的

--sport:源端口

--dport:源地址

-i:入接口

-o:出接口

target:目标或者说操作

accept、drop、reject、return、log、tos 、snat、dnat、masquerade、redirect、mark、return(返回主链,中间可以转到自定义链)

(2)简单操作介绍:

接收数据包:

iptables –A INPUT –s192.168.1.0/24 –j ACCEPT

拒绝数据包:

iptable –A INPUT –s192.168.1.2 --dport 80 -j DROP

查看规则表

Iptables -L –nv

2、扩展:

--icmp-type:对应icmp的类型

--tcp-flag :syn ack fin psh rst urg(至少匹配两个为1 不匹配强制匹配为0)

3、iptables的实例:

(1)filter

要求:内网用户sale只能访问内网http服务器内网接口,tech只能访问ftp,ping全部关闭。telnet全部关闭。内部用户不能上外网。外网用户只能访问http外网接口。(nat部分后面介绍)

iptables

默认链清空iptables –Z

开始:

(1)                  对于inside口:(都有-i inside 或 –oinside,写不开了)

*iptables –t filter–A INPUT –s 192.168.1.0/24 –d 192.168.254.2 –p tcp –dport 21,22 –j ACCEPT

*iptables –tfilter –A INPUT –s 192.168.2.0/24 –d 192.168.254.1 –p tcp –dport 80 –j ACCEPT

*iptables –tfilter –A INPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP

*iptables–t filter–A OUTPUT –s 192.168.254.2 –d 192.168.1.0/24 –p tcp –sport 21,22 –j ACCEPT

*iptables –tfilter –A OUTPUT –s 192.168.254.1 –d 192.168.2.0/24 –p tcp –sport 80 –j ACCEPT

*iptables –tfilter –A OUTPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP

(2)                  对于outside口:(都有-i outside 或 –o outside,写不开了)

*ipables –t filter–A INPUT –s 0.0.0.0/0 –d 202.200.200.1 –p tcp –dport 80 –j ACCEPT

*ipables –t filter–A INPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP

*iptables –tfilter –A OUTPUT –s 202.200.200.1 –p –sport 80 –j ACCEPT

*iptables –tfilter –A OUTPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP

(3)                  对于DMZ口:(都有-i DMZ 或 –oDMZ,写不开了):重复性的

*iptables –t filter–A INPUT –s 192.168.1.0/24 –d 192.168.254.2 –p tcp –dport 21,22 –j ACCEPT

*iptables –tfilter –A INPUT –s 192.168.2.0/24 –d 192.168.254.1 –p tcp –dport 80 –j ACCEPT

ipables –t filter–A INPUT –s 0.0.0.0/0 –d 202.200.200.1 –p tcp –dport 80 –j ACCEPT

*iptables –tfilter –A INPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP

*iptables–t filter–A OUTPUT –s 192.168.254.2 –d 192.168.1.0/24 –p tcp –sport 21,22 –j ACCEPT

*iptables –tfilter –A OUTPUT –s 192.168.254.1 –d 192.168.2.0/24 –p tcp –sport 80 –j ACCEPT

*iptables –tfilter –A OUTPUT –s 202.200.200.1 –p –sport 80 –j ACCEPT

*iptables –tfilter –A OUTPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP

(2)nat

要求:主机20.20.20.2做地址转换;服务器10.10.10.2做端口映射。

*iptables –t nat–A POSTROUTING –o out –s 20.20.20.2 –j SNAT –to 192.168.1.49

*iptables –t nat–A POSTROUTING –i out –s 0.0.0.0/0 –j SNAT –to 192.168.1.48

*iptables –t nat–A POSTROUTING –o out –s 10.10.10.2 –j DNAT –to 192.168.1.50

*iptables –t nat–A POSTROUTING –i out –s 0.0.0.0/0 –p tcp –port 80 –j REDIRECT

--to-port 1080

LINUX IPTABLES 防火墙配置的更多相关文章

  1. Linux学习笔记 --iptables防火墙配置

    iptables防火墙配置 一.防火墙简介 1.功能: 1)通过源端口,源IP地址,源MAC地址,包中特定标记和目标端口,IP,MAC来确定数据包是否可以通过防火墙 2)分割内网和外网[附带的路由器的 ...

  2. iptables防火墙配置

    iptables防火墙配置 一.防火墙简介 1.功能: 1)通过源端口,源IP地址,源MAC地址,包中特定标记和目标端口,IP,MAC来确定数据包是否可以通过防火墙 2)分割内网和外网[附带的路由器的 ...

  3. Linux iptables 防火墙

    内容摘要 防火墙 防火墙定义 防火墙分类 netfilter/iptables netfilter 设计架构 iptables 简述 iptables 命令详解 命令语法 table 参数 comma ...

  4. linux iptables 防火墙简介

    iptables防火墙简介 Netfilter/Iptables(以下简称Iptables)是unix/linux自带的一款优秀且开放源代码的安全自由的基于包过滤的防火墙工具,它的功能十分强大,使用非 ...

  5. Keepalived 无法自动转换主备角色,请关注 iptables 防火墙配置

    最近在研究服务器高可用集群 (HA)…… 搭建了主备两台Keepalived,配置什么的全是网上照抄的,被验证过无数遍的示例…… 然而Master和Backup无法自动切换.两边会同时绑定浮动IP(V ...

  6. 15.linux iptables防火墙规则vsftp服务

    一.服务所开启的端口号.          dhcp 67       samba 139 445       http 80  https 443       mysql 3306         ...

  7. Linux iptables防火墙

    查找安装包yum list | grep iptables 安装iptables yum install iptables-services 重启防火墙使配置文件生效 systemctl restar ...

  8. Linux iptables 防火墙设置

    1.查看防火墙iptables -L -niptablesb -L -n --line-number  显示规则行号看到 INPUT ACCEPT, FORWARD ACCEPT , OUTPUT A ...

  9. CentOS Linux iptables 防火墙

    快速安装,配置,启动,检查 - 关闭 5002 - 5011 端口开放所有其它 yum install iptables iptables -F iptables -X iptables -Z ipt ...

随机推荐

  1. 开源图形数据库Neo4j使用 php开发

    先看看它的示例数据 打开 Neo4j Browser :play movie graph 写代码,然后点play执行 Cypher, the graph query language.Neo4j提供了 ...

  2. DIV内滚动条滚动到指定位置

    相对浏览器,将指定div滚到到指定位置,其用法如下: $("html,body").animate({scrollTop: $(obj).offset().top},speed); ...

  3. 16 款最流行的JavaScript 框架

    1. jQuery – Javascript框架 jQuery 是最流行的 JavaScript 框架,它简化了HTML 文档遍历.事件处理.动画和Ajax交互.jQuery插件非常之多. 2. Do ...

  4. gulp配置安装使用

    安装 $ npm install gulp -g //全局安装gulp,让你可存取gulp的CLI //接着需要在本地端的专案进行安装,cd到专案根目录,执行 $ npm install gulp - ...

  5. 基于Dedup的数据打包技术

    基于Dedup的数据打包技术 0.引言    Tar, winrar, winzip是最为常见的数据打包工具软件,它们把文件集体封装成一个单独的数据包,从而方便数据的分布.传输.归档以及持久保存等目的 ...

  6. 时间操作(struct tm、time_t)求指定日期 前n天的日期

    1.在标准C/C++中,我们可通过tm结构来获得日期和时间,tm结构在time.h中的定义如下: #ifndef _TM_DEFINED struct tm { int tm_sec; /* 秒–取值 ...

  7. Oracle数据库表空间与数据文件的关系描述正确的是( )

    Oracle数据库表空间与数据文件的关系描述正确的是( ) A.一个表空间只能对应一个数据文件 B.一个表空间可以对应多个数据文件 C.一个数据文件可以对应多个表空间 D.表空间与数据文件没任何对应关 ...

  8. e557. 在Applet中显示图片

    See also e551 精简的Applet. Image image; public void init() { // Load image image = getImage(getDocumen ...

  9. 使用Ultra Librarian转换芯片的Altium Designer封装格式

    第一步:找到对应芯片的CAD文件,以OPA350为例: http://www.ti.com/product/opa350   RE: 使用Ultra Librarian转换TI芯片的Altium De ...

  10. linux下安装dovecot

    Dovecot是一个开源的,为Linux/Unix-like系统提供IMAP,POP3服务的软件.主要是为了安全产生的,不管大小应用,Dovecot都是一个非常优秀的选择.它非常快,配置简单,不需要专 ...