当前位置:网站首页>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
边栏推荐
- Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
- 相信自己,这次一把搞定JVM面试
- executescalar mysql_ ExecuteScalar()
- Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
- What is agile development process
- 社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
- 酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
- 2、 Expansion of mock platform
- 【Leetcode】13. Roman numeral to integer
- VMware install win10 image
猜你喜欢
Qwebengineview crash and alternatives
Sword finger offer 26 Substructure of tree
体验居家办公完成项目有感 | 社区征文
剑指 Offer 25. 合并两个排序的链表
A case study of college entrance examination prediction based on multivariate time series
Timing / counter of 32 and 51 single chip microcomputer
对接保时捷及3PL EDI案例
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
871. 最低加油次数
【Leetcode】13. Roman numeral to integer
随机推荐
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
Linux Installation PostgreSQL + Patroni cluster problem
2、 Expansion of mock platform
例题 非线性整数规划
Experience home office, feel the completion of the project | community essay solicitation
The impact of telecommuting on all aspects of our experience | community essay solicitation
二、mock平台的扩展
One year is worth ten years
executescalar mysql_ExecuteScalar()
What is agile development process
【Leetcode】13. Roman numeral to integer
Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
一年頂十年
Ap和F107数据来源及处理
Geoserver: publishing PostGIS data sources
What will you do after digital IC Verification?
How to quickly distinguish controlled components from uncontrolled components?
Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品
TCP拥塞控制详解 | 2. 背景
TCP congestion control details | 2 background