iptables做nat网络地址转换
iptables做nat网络地址转换。
0. 权威文档
http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO-6.html
e文好的直接跳过本文。
1. Source NAT
在POSTROUTING链里面定义,用-j SNAT,--to-source 省略成--to,ip ,ip段,地址段
## Change source addresses to 1.2.3.4.
# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4
## Change source addresses to 1.2.3.4, 1.2.3.5 or 1.2.3.6
# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4-1.2.3.6
## Change source addresses to 1.2.3.4, ports 1-1023
# iptables -t nat -A POSTROUTING -p tcp -o eth0 -j SNAT --to 1.2.3.4:1-1023
Masquerading
其实是snat中的一种特殊情况,用在来源动态的地址。而且不能指定source address,只能指定来源端口(interface).
But more importantly, if the link goes down, the connections (which are now lost anyway) are forgotten, meaning fewer glitches when connection comes back up with a new IP address.
## Masquerade everything out ppp0.
# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
2. Destination NAT
定义在PREROUTING链。用-j DNAT,--to-destination指定ip,ip段,端口段。
## Change destination addresses to 5.6.7.8
# iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 5.6.7.8
## Change destination addresses to 5.6.7.8, 5.6.7.9 or 5.6.7.10.
# iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 5.6.7.8-5.6.7.10
## Change destination addresses of web traffic to 5.6.7.8, port 8080.
# iptables -t nat -A PREROUTING -p tcp --dport 80 -i eth0 -j DNAT --to 5.6.7.8:8080
Redirection
Redirection是dnat一种特殊情况,将数据库转发到相同interface的另一个端口。
## Send incoming port-80 web traffic to our squid (transparent) proxy
# iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 \
-j REDIRECT --to-port 3128
squid做透明代理的时候就用这条规则。
iptables做nat网络地址转换的更多相关文章
- [译] NAT - 网络地址转换(2016)
[译] NAT - 网络地址转换(2016) Published at 2019-02-17 | Last Update 译者序 本文翻译自 2016 年的一篇英文博客 NAT - Network A ...
- NAT 网络地址转换
NAT 网络地址转换(Network Address Translation) NAT(Network Address Translation,网络地址转换)是1994年提出的. 属接入广域网(WA ...
- CCNA学习 NAT网络地址转换
CCNA基础 NAT网络地址转换 在计算机网络中,网络地址转换(Network Address Translation,缩写为NAT),也叫做网络掩蔽或者IP掩蔽(IP masquerading),是 ...
- NAT网络地址转换技术
NAT网络地址转换技术 目录 一.NAT概述 1.1.概述 1.2.NAT 的应用场景 二.NAT的类型及配置命令 2.1.静态NAT 2.2.动态NAT 2.3.Easy IP 2.4.NATP 2 ...
- NAT网络地址转换模拟过程
原理图,如图1 图1 以下为配置NAT网络地址转换的实验: eNSP模拟图,如图2 图2 Step1.给路由器的每个接口赋予一个地址,如图3,图4 图3 图4 AR1和AR2中添加路由表项,如图5,图 ...
- iptables配置——NAT地址转换
iptables nat 原理同filter表一样,nat表也有三条缺省的"链"(chains): PREROUTING:目的DNAT规则 把从外来的访问重定向到其他的机子上,比如 ...
- firewalld 防火墙 nat 网络地址转换
目的:实现以下效果 一. 准备环境 @1 三台虚拟机 @2 client 端 ip 192.168.1.2 server端 两块网卡 , ip 分别是 192.168.1.1 和 ...
- NAT网络地址转换的原理--笔试答题版
最早接触NAT是在做网络工程师的时候,NAT是做网络工程师必需会的知识点和技能,后来在面试运维的时候也经常被用到,在运维的某些知识点当中也会被引用到,如LVS当中. 为什么需要NAT(网络地址转换)? ...
- 用iptables 做NAT代理上网
背景:有一台A服务器不能上网,和B服务器通过内网来连接,B服务器可以上网,要实现A服务器也可以上网. 内网主机: A eth1:172.16.1.8 外网主机: B eth0:10.0.0.61外网主 ...
随机推荐
- 反转链表-PHP的实现
<? //节点 class Node { private $Data;//节点数据 private $Next;//下一节点 public function setData($value) { ...
- CountDownLatch/CyclicBarrier/Semaphore
CountDownLatch 概念 让一些线程阻塞直到另一些线程完成一系列操作才被唤醒 CountDownLatch主要有两个方法,当一个或多个线程调用await方法时,调用线程就会被阻塞.其它线程调 ...
- php---算法和数据结构
<?php header("content-type:text/html;charset=utf-8"); $arr = array(3,5,8,4,9,6,1,7,2); ...
- [Inno Setup] 退出安装程序的两种方式
1. 完全静默的退出 procedure ExitProcess(exitCode:integer); external 'ExitProcess@kernel32.dll stdcall'; ... ...
- Spring5参考指南:JSR 330标准注解
文章目录 @Inject 和 @Named @Named 和 @ManagedBean 之前的文章我们有讲过,从Spring3.0之后,除了Spring自带的注解,我们也可以使用JSR330的标准注解 ...
- hdu_2124 Flying to the Mars & hdu_1800 Repair the Wall 贪心水题
hdu_1800 简单排一下序,从大开始把比他小的都访问一遍,ans++: #include <iostream> #include <stdio.h> #include &l ...
- linux-网络管理(常用命令)
网络查看 ifconfig : 查看与临时配置网络 ifdown 网卡设备名 : 关闭网卡 ifup 网卡设备名 : 启用网卡 netstat 网络状态查询 -t 列出TCP协议端口 -u 列出UDP ...
- 如何在linux服务器下快速安装配置Node.js
简单粗暴,先用xshell或其他软件连接服务器 1.下载(此处版本根据官网版本自己修改) wget https://npm.taobao.org/mirrors/node/v8.9.3/node-v8 ...
- HDU Problem D [ Humble number ]——基础DP丑数序列
Problem D Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
- python(os 模块)
1.os.name 输出字符串指示正在使用的平台.如果是window 则用'nt'表示,对于Linux/Unix用户,它是'posix' import os print(os.name) #结果如下 ...