linux之iptable案例
转自:http://blog.csdn.net/bill_lee_sh_cn/article/details/4401896
1.一对一流量完全DNAT
首先说一下网络环境,普通主机一台做防火墙用,网卡两块
eth0 192.168.0.1 内网
eth1 202.202.202.1 外网
内网中一台主机 192.168.0.101
现在要把外网访问202.202.202.1的所有流量映射到192.168.0.101上
命令如下:
- #将防火墙改为转发模式
- echo 1 > /proc/sys/net/ipv4/ip_forward
- iptables -F
- iptables -t nat -F
- iptables -t mangle -F
- iptables -X
- iptables -t nat -X
- iptables -t mangle -X
- iptables -A INPUT -i lo -j ACCEPT
- iptables -A OUTPUT -o lo -j ACCEPT
- iptables -P INPUT ACCEPT
- iptables -P OUTPUT ACCEPT
- iptables -P FORWARD ACCEPT
- iptables -t nat -A PREROUTING -d 202.202.202.1 -j DNAT --to-destination 192.168.0.101
- iptables -t nat -A POSTROUTING -d 192.168.0.101 -j SNAT --to 192.168.0.1
2.多对多流量完全DNAT
说是多对多,实际上这里的配置是指定了多个一对一
环境:
eth0 192.168.0.1 内网
eth1 202.202.202.1 、202.202.202.2 外网
内网中2台主机 192.168.0.101、192.168.0.102
现在要把外网访问202.202.202.1的所有流量映射到192.168.0.101上,同时把把外网访问202.202.202.2的所有流量映射到192.168.0.102上
这里顺便提一下如何为网卡配置多个IP
- ifconfig eth1:1 202.202.202.2 netmask 255.255.255.0 up
命令如下:
- #将防火墙改为转发模式
- echo 1 > /proc/sys/net/ipv4/ip_forward
- iptables -F
- iptables -t nat -F
- iptables -t mangle -F
- iptables -X
- iptables -t nat -X
- iptables -t mangle -X
- iptables -A INPUT -i lo -j ACCEPT
- iptables -A OUTPUT -o lo -j ACCEPT
- iptables -P INPUT ACCEPT
- iptables -P OUTPUT ACCEPT
- iptables -P FORWARD ACCEPT
- iptables -t nat -A PREROUTING -d 202.202.202.1 -j DNAT --to-destination 192.168.0.101
- iptables -t nat -A POSTROUTING -d 192.168.0.101 -j SNAT --to 192.168.0.1
- iptables -t nat -A PREROUTING -d 202.202.202.2 -j DNAT --to-destination 192.168.0.102
- iptables -t nat -A POSTROUTING -d 192.168.0.102 -j SNAT --to 192.168.0.1
3.一对多根据协议DNAT
这个最常用,一般是内网或DMZ区内有多个应用服务器,可以将不同的应用流量映射到不同的服务器上
环境:
eth0 192.168.0.1 内网
eth1 202.202.202.1 外网
内网中2台主机 192.168.0.101(Web服务器)、192.168.0.102(邮件服务器)
现在要把外网访问202.202.202.1的Web流量映射到192.168.0.101上,同时把把外网访问202.202.202.1的邮件访问流量映射到192.168.0.102上
命令如下:
- #将防火墙改为转发模式
- echo 1 > /proc/sys/net/ipv4/ip_forward
- iptables -F
- iptables -t nat -F
- iptables -t mangle -F
- iptables -X
- iptables -t nat -X
- iptables -t mangle -X
- iptables -A INPUT -i lo -j ACCEPT
- iptables -A OUTPUT -o lo -j ACCEPT
- iptables -P INPUT ACCEPT
- iptables -P OUTPUT ACCEPT
- iptables -P FORWARD ACCEPT
- iptables -t nat -A PREROUTING -d 202.202.202.1 -p tcp --dport 80 -j DNAT --to-destination 192.168.0.101:80
- iptables -t nat -A POSTROUTING -d 192.168.0.101 -p tcp --dport 80 -j SNAT --to 192.168.0.1
- iptables -t nat -A PREROUTING -d 202.202.202.1 -p tcp --dport 25 -j DNAT --to-destination 192.168.0.102:25
- iptables -t nat -A POSTROUTING -d 192.168.0.102 -p tcp --dport 25 -j SNAT --to 192.168.0.1
- iptables -t nat -A PREROUTING -d 202.202.202.1 -p tcp --dport 110 -j DNAT --to-destination 192.168.0.102:110
- iptables -t nat -A POSTROUTING -d 192.168.0.102 -p tcp --dport 110 -j SNAT --to 192.168.0.1
linux之iptable案例的更多相关文章
- 《Linux企业应用案例精解(第2版)》新书开始发售
<Linux企业应用案例精解(第2版)>新书开始发售 650) this.width=650;" title="linux企业应用案例精解 第2版" alt= ...
- 《Linux企业应用案例精解》一书配套视频发布
<Linux企业应用案例精解>一书配套视频发布(每周更新视频教程),通过读者平台账号,可以在平台下载AVI格式.所有读者都能获得本书中涉及的软件资料,轻松搭建你的学习环境. 当当购书地址: ...
- Linux系统故障处理案例(一)【转】
2016-08-05 14:41 运行环境:CentOS6.7 故障原因: 昨天在线执行命令yum -y update 在命令执行途中,强制中断并直接运行poweroff命令关机.再次开机出现如图所示 ...
- 《Linux企业应用案例精解》一书已由清华大学出版社出版
<Linux企业应用案例精解>简介 650) this.width=650;" border="0" alt="223754878.jpg" ...
- LINUX企业应用案例精解 第2版 李晨光
LINUX企业应用案例精解 第2版 李晨光 下载地址:https://pan.baidu.com/s/1AAKpc-l-qGTSX5h03M01XA 关注微信公众号获取提取码: 输入:lin7 获取提 ...
- 《Linux企业应用案例精解(第2版)》新书发售啦
本书在出版当年就获得了不错的销量,同时被中国科学院国家科学图书馆.中国国家图书馆.首都图书馆.清华大学.北京大学等上百所国内综合性大学图书馆收录为馆藏图书,在IT业界赢得了良好的口碑.随后2012年年 ...
- JMeter监控Linux服务器资源案例
JMeter是一款压力测试工具,我们也可以用它来监控服务器资源使用情况.JMeter正常自带可以通过Tomcat的/manager/status来监控服务资源使用情况.这种情况只能监控Tomcat支持 ...
- Linux系统故障处理案例(一)
运行环境:CentOS6.7 故障原因: 昨天在线执行命令yum -y update 在命令执行途中,强制中断并直接运行poweroff命令关机.再次开机出现如图所示故障指示: 根据提示信息分析,可能 ...
- linux之iptable
转自:http://seanlook.com/2014/02/23/iptables-understand/ 一. netfilter与iptables Netfilter是由Rusty Russel ...
随机推荐
- Python进阶--GUI编程
一.图形用户图面(GUI编程) 1. wxpython下载和安装: 下载url: http://wxpython.org/download.php 2.创建示例GUI应用程序 : ①开始需要导入wx ...
- String类的实现,内部采用字符数组实现
#include <iostream> using namespace std; class String{ public: String(const char *str = NULL); ...
- 04737_C++程序设计_第5章_特殊函数和成员
例5.1 分析下面程序中析构函数与构造函数的调用顺序. #include<iostream> using namespace std; class object { private: in ...
- 【Deep Learning】genCNN: A Convolutional Architecture for Word Sequence Prediction
作者:Mingxuan Wang.李航,刘群 单位:华为.中科院 时间:2015 发表于:acl 2015 文章下载:http://pan.baidu.com/s/1bnBBVuJ 主要内容: 用de ...
- pywebkitgtk安装出现的问题
configure 文件里 print sys.prefix 等不能支持python3的原因 依据http://blog.csdn.net/jklfjsdj79hiofo/article/detail ...
- 用ssh建立机器之间的信任机制
继续整理以前的博客,第二弹:用ssh建立机器之间的信任机制 #!/bin/bash #需要远程添加信任机制的机器 REMOTE[]=db-XXX-XXX1.db01 REMOTE[]=db-XXX-X ...
- 错误:类Byte是公共的,应在名为Byte.java 的文件中声明public class Byte{}一个错误
解决:文件名是xyz,那你的这个类名也应该是xyz.
- Java随机输出验证码包含数字、字母、汉字
//随机验证码,有数字.字符 //生成随机数,然后再截取,还要限定随机数的范围 String zimu = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn ...
- hadoop之hdfs学习
简介 HDFS(Hadoop Distributed File System )Hadoop分布式文件系统.是根据google发表的论文翻版的.论文为GFS(Google File System)Go ...
- Notepad++使用技法
Alt+H 隐藏行 Ctrl+Tab 实现在多个打开的窗口间切换 Ctrl+Shift+Q区块注释 Ctrl+K行注释(取消Ctrl+Shift+K) 文件 新建文件 Ctrl+N 打开文件 C ...