当前位置:网站首页>Meanings of SNAT, DNAT and masquerade in iptables
Meanings of SNAT, DNAT and masquerade in iptables
2022-07-02 17:20:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
IPtables Can be flexible to do a variety of network address conversion (NAT), There are two main types of network address conversion :SNAT and DNAT.
SNAT yes source networkaddress translation Abbreviation , That is, source address target conversion . such as , Multiple PC Machine use ADSL Routers share the Internet , Every PC The machines are all equipped with an intranet IP,PC When the computer accesses the external network , The router replaces the source address in the packet header with the router's ip, When external network servers such as websites web When the server receives an access request , His log records the router's ip Address , instead of pc The intranet of the machine ip, This is because , In the header of the packet received by this server “ source address ”, It has been replaced , So it's called SNAT, Address translation based on source address .
DNAT yes destination networkaddress translation Abbreviation , That is, target network address translation , The typical application is , There is one web The server is placed in the intranet, and the intranet is configured ip, The front end has a firewall to configure the public network ip, Visitors on the Internet use the public network ip To visit this website , When visiting , The client sends out a packet , In the header of this packet , The target address is the public network of the firewall ip, The firewall will rewrite the header of this packet once , Rewrite the destination address to web The intranet of the server ip, Then send the packet to the intranet web Server , such , The packet goes through the firewall , And from the public network ip It becomes an access to the intranet address , namely DNAT, Target based network address translation .
MASQUERADE, Address camouflage , Count as snat A special case of , Can be automated snat.
stay iptables There are and SNAT Similar effect , But there are some differences , But use SNAT When , exit ip The address range of can be a , It can be multiple , for example :
The following command means to put all 10.8.0.0 Packet of network segment SNAT become 192.168.5.3 Of ip Then send it out ,
iptables-t nat -A POSTROUTING -s 10.8.0.0/255.255.255.0 -o eth0 -j SNAT –to-source192.168.5.3
The following command means to put all 10.8.0.0 Packet of network segment SNAT become 192.168.5.3/192.168.5.4/192.168.5.5 Wait a few ip Then send it out
iptables-t nat -A POSTROUTING -s 10.8.0.0/255.255.255.0 -o eth0 -j SNAT –to-source192.168.5.3-192.168.5.5
This is it. SNAT How to use , That is to say NAT Make an address , It's fine too NAT To multiple addresses , however , about SNAT, No matter how many addresses , It must be specified that SNAT Of ip, If the current system uses ADSL Dynamic dialing , So every time you dial , exit ip192.168.5.3 Will change , And there's a lot of change , Is not necessarily 192.168.5.3 To 192.168.5.5 Address in range , At this time, if you configure it in the current way iptables There will be problems , Because after every dial , The server address will change , and iptables Within the rules ip It doesn't change automatically , Every time the address changes, you have to modify it manually iptables, Fix the rules inside ip Change to a new one ip, This is very difficult to use .
MASQUERADE It's designed for this kind of scene , His function is , From the network card of the server , Automatically get the current ip Address to do NAT.
For example, the command below :
iptables-t nat -A POSTROUTING -s 10.8.0.0/255.255.255.0 -o eth0 -j MASQUERADE
In this configuration , Don't have to specify SNAT The goal of ip 了 , No matter now eth0 What's the dynamic of the export of ip,MASQUERADE Will automatically read eth0 current ip Address and do SNAT get out , In this way, a good dynamic SNAT address translation .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/148098.html Link to the original text :https://javaforall.cn
边栏推荐
- traceroute命令讲解
- 酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
- Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia
- 2022 interview questions
- 深度之眼(三)——矩阵的行列式
- Eye of depth (II) -- matrix and its basic operations
- Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion
- Visibilitychange – refresh the page data when the specified tab is visible
- GeoServer:发布PostGIS数据源
- 几行代码搞定RPC服务注册和发现
猜你喜欢

Geoserver: publishing PostGIS data sources

Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era

剑指 Offer 21. 调整数组顺序使奇数位于偶数前面

13、Darknet YOLO3

Use of openpose

How to transfer business data with BorgWarner through EDI?

对接保时捷及3PL EDI案例

社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东

福元医药上交所上市:市值105亿 胡柏藩身价超40亿

Experience home office, feel the completion of the project | community essay solicitation
随机推荐
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
LSF basic command
Briefly introduce the use of base64encoder
A case study of college entrance examination prediction based on multivariate time series
OpenPose的使用
Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
智能垃圾桶(五)——点亮OLED
Experience home office, feel the completion of the project | community essay solicitation
Qstype implementation of self drawing interface project practice (II)
Connect Porsche and 3PL EDI cases
13、Darknet YOLO3
2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
In MySQL and Oracle, the boundary and range of between and precautions when querying the date
VMware install win10 image
Eye of depth (III) -- determinant of matrix
Qwebengineview crash and alternatives
Baobab's gem IPO was terminated: Tang Guangyu once planned to raise 1.8 billion to control 47% of the equity
PhD battle-11 preview | review and prospect backdoor attack and defense of neural network
【Leetcode】14. Longest Common Prefix
Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia