1. 使局域网用户可共享外网(拨号上网)

echo  > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

2. (SNAT)更改所有来自192.168.1.0/24的数据包的源ip地址为1.2.3.4:

iptables -t nat -A POSTROUTING -s 192.168.1.0/ -o eth0 -j SNAT --to 1.2.3.4

3. (DNAT)更改所有来自192.168.1.0/24的数据包的目的ip地址为1.2.3.4:

 iptables -t nat -A PREROUTING -s 192.168.1.0/ -i eth1 -j DNAT --to 1.2.3.4

4. 使外网用户可以访问到局域网192.168.138.21这台HTTP服务

echo  > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -p tcp -m tcp --dport -j DNAT --to-destination 192.168.138.21
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

5. 使局域网用户,访问外网web服务时,自动使用squid作web透明代理服务器

echo  > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -s 192.168.138.0/ -p tcp --dport -i eth0 -j DNAT --to 192.168.138.1
iptables -t nat -A PREROUTING -s 192.168.138.0/ -p tcp --dport -i eth0 -j REDIRECT --to
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

6. iptables安全策略, 网关服务器系统自生安全策略,只对内网用户开放22端口(sshd服务)

  #清空 filter table
[root@localhost]# iptables -F -t filter
[root@localhost]# iptables -X -t filter
[root@localhost]# iptables -Z -t filter #清空 nat table
[root@localhost]# iptables -F -t nat
[root@localhost]# iptables -X -t nat
[root@localhost]# iptables -Z -t nat #设置默认策略(INPUT链默认为DROP)
[root@localhost]# iptables -t filter -P INPUT DROP
[root@localhost]# iptables -t filter -P OUTPUT ACCEPT
[root@localhost]# iptables -t filter -P FORWARD ACCEPT #回环接口(lo),默认accept
[root@localhost]# iptables -A INPUT -p ALL -i lo -j ACCEPT #只对内网用户开放sshd服务
[root@localhost]# iptables -A INPUT -p tcp -s 192.168.138.0/ --dport -j ACCEPT

参考来源:

[1] http://www.51know.info/system_security/iptable/iptable.html

[2] http://oa.jmu.edu.cn/netoa/libq/pubdisc.nsf/66175841be38919248256e35005f4497/7762e8e1056be98f48256e88001ef71d?OpenDocument

〖Linux〗iptables使用实例的更多相关文章

  1. Linux iptables

    一.简介 http://liaoph.com/iptables/ 二.操作 1)查看规则 iptables -t filter -L -n iptables -t nat -L -n iptables ...

  2. Linux iptables用法与NAT

    1.相关概念 2.iptables相关用法 3.NAT(DNAT与SNAT) 相关概念 防火墙除了软件及硬件的分类,也可对数据封包的取得方式来分类,可分为代理服务器(Proxy)及封包过滤机制(IP ...

  3. linux iptables常用命令之配置生产环境iptables及优化

    在了解iptables的详细原理之前,我们先来看下如何使用iptables,以终为始,有可能会让你对iptables了解更深 所以接下来我们以配置一个生产环境下的iptables为例来讲讲它的常用命令 ...

  4. Linux iptables原理--数据包流向

    Iptable与Netfilter 在上一篇文章 linux iptables常用命令--配置一个生产环境的iptables 我们知道iptables有好几个表,如raw,mangle,nat,fil ...

  5. 15个Linux Wget下载实例终极指南

    15个Linux Wget下载实例终极指南 Linux wget是一个下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,尤其对于网络管理员,经常要下载一些软件或从远程服务器恢复备份到 ...

  6. Linux iptables 应用控制访问SSH服务

    Title:Linux iptables 应用控制访问SSH服务  --2012-02-23 17:51 今天用到了以前从来没有用到过的,iptables控制访问,只允许外部访问SSH服务(22号端口 ...

  7. linux内核模块编程实例

    linux内核模块编程实例 学号:201400814125 班级:计科141 姓名:刘建伟 1.确定本机虚拟机中的Ubuntu下Linux的版本 通过使用命令uname -a/uname -r/una ...

  8. Linux iptables 配置规则

    Linux iptables 防火墙配置规则 前言:把网上我感觉不错iptables的访问规则都统一在这里,以后做参考. modprobe ipt_MASQUERADE modprobe ip_con ...

  9. [svc]linux iptables实战

    参考: http://blog.51yip.com/linux/1404.html 链和表 参考: https://aliang.org/Linux/iptables.html 配置 作为服务器 用途 ...

  10. 常用的 Linux iptables 规则

    一些常用的 Linux iptables 规则,请根据自己的具体需要再修改. 转载自:http://mp.weixin.qq.com/s/uAPzh9_D4Qk6a3zBh7Jq5A # 1. 删除所 ...

随机推荐

  1. 预装Windows 8系统机型如何进行一键恢复

    http://support1.lenovo.com.cn/lenovo/wsi/htmls/detail_20131119141246845.html

  2. 关于OPC Client 编写2

    最近在搞到一个OPC动态库OPCAutomation.dll,该动态库在http://www.kepware.com/可下载,下面介绍如何用C#进行OPC Client开发. 1.新建C#应用程序,命 ...

  3. idea安装Lombok及使用介绍

    原文:https://blog.csdn.net/motui/article/details/79012846 Lombok使用 介绍 在项目中使用Lombok可以减少很多重复代码的书写.比如说get ...

  4. UITextView 详解

    UITextView 边框的设置   设置光标的位置   导入QuartzCote框架: #import <QuartzCore/QuartzCore.h> textView.layer. ...

  5. Python之“可变”的tuple

    前面我们看到了tuple一旦创建就不能修改.现在,我们来看一个"可变"的tuple: >>> t = ('a', 'b', ['A', 'B']) 注意到 t 有 ...

  6. TPL中限制进程数量

    The MaxDegreeOfParallelism sets the maximum number of simultaneous threads that will be used for the ...

  7. Eclipse设置打印线

    在调出Preferences之后,选中Text Editors.先选中Show print margin,在Print margin column框中填入180就可以,然后选择以下的Print mar ...

  8. cout的输出格式初探

    在C++中,cout代表的是标准输出设备,即显示器,相对于C语言中所使用的printf函数,cout显得更为灵活.下面以30.300和1024三个数为例子,简单说明cout输出时所选格式的输出.cou ...

  9. 【BestCoder】【Round#41】

    枚举+组合数?+DP+数学问题 http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=582 QAQ许久没打过比赛,来一发BC,结果还是只 ...

  10. Cesium随笔(1)部署自己的项目 【转】

    Cesium是国外开发的基于Webgl的跨浏览器的三维地球显示的Javascript开源库,只要浏览器支持Webgl,html5就可以运行.甚至部分手机浏览器都可以运行 . 首先,对Cesium进行本 ...