LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-11-2005, 10:05 AM   #1
Palula
Member
 
Registered: May 2005
Location: Brazil
Distribution: Fedore Core 3
Posts: 138

Rep: Reputation: 15
MASQUERADE vs. DNAT/SNAT


Hey there!!

Iīd like some help regarding this issue. I have a book that doesnt cover anything related to MASQUERADE. It only covers DNAT and SNAT. At the office the system admin uses MASQUERADE and Iīd like to know what is the difference. In wich cases should I use MASQUERADE, and in wich cases should I use DNAT/SNAT.

Thanks!!!
 
Old 08-11-2005, 10:24 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
MASQUERADE is usually used for dynamic IPs, while SNAT is used for static ips (with SNAT you specify the IP you're natting FROM). DNAT is more used for port forwarding. Check out this page: http://www.baraka.ca/barbwire_tables.asp
 
Old 08-11-2005, 11:41 AM   #3
Palula
Member
 
Registered: May 2005
Location: Brazil
Distribution: Fedore Core 3
Posts: 138

Original Poster
Rep: Reputation: 15
Thanks a lot.
Nice link. But I already have another question...

Letīs suppose I have a LAN with 99 computers (192.168.100.1-192.168.100.100).
Quote:
(with SNAT you specify the IP you're natting FROM)
In this case I would have to specify a line for each one of the computers of my LAN? That seems like a lot of work to me...
 
Old 08-11-2005, 05:03 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
no, sorry. You only need one, it just has your static ip in it. I *THINK* (though I've never done SNAT) it would be:
Code:
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -j SNAT --from 99.99.99.99
Where 99.99.99.99 is your STATIC IP for the outside.
 
Old 08-11-2005, 05:34 PM   #5
demian
Member
 
Registered: Apr 2001
Location: Bremen, Germany
Distribution: Debian
Posts: 303

Rep: Reputation: 30
Quote:
Originally posted by Matir
You only need one, it just has your static ip in it. I *THINK* (though I've never done SNAT)
Yup, that's correct. The syntax, however, is -j SNAT --to-source 99.99.99.99
 
Old 08-11-2005, 06:37 PM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Oops, sorry. Like I said, never used it before. My ISP gives me DHCP, so I'm forced to use MASQUERADE. Though I honestly wonder if SNAT has many advantages, if any?
 
Old 08-11-2005, 06:59 PM   #7
demian
Member
 
Registered: Apr 2001
Location: Bremen, Germany
Distribution: Debian
Posts: 303

Rep: Reputation: 30
The main difference I can think of is that when the link goes down the nat table is deleted when using MASQUERADE since chances are that the IP will change once the link comes back up. This is not true for SNAT. Here the NAT table stays even when the link goes down so that when it comes back up the connection can continues without a new handshake (provided it didn't time out on either side). Also SNAT performs a little better since it doesn't need to figure out the IP that belongs to the interface the NATing is done for. (This, however, doesn't really have any noticable effect now that most routers have an abundance of cpu cycles to burn.)
 
Old 08-11-2005, 07:04 PM   #8
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Yeah, my router is a PII/333. It's load averages are in the .05 range

The conntrack table being flushed, however, is an excellent point that I had not thought of.
 
Old 08-12-2005, 07:01 AM   #9
Palula
Member
 
Registered: May 2005
Location: Brazil
Distribution: Fedore Core 3
Posts: 138

Original Poster
Rep: Reputation: 15
Ahhhhhhhhhhh!!!
Thanks! I can now see the light.

Letīs create two scenarios:

Network 1: 192.168.100.0/24 - eth0 IP provided by DHCP
Netowrk 2: 192.168.100.0/24 - eth0 IP is static - 200.119.78.110 (tottaly random number)

Network 1 nat rule: iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -j MASQUERADE
Network 2 nat rule: iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -j SNAT --to-source 200.119.78.110

Are these rules Ok? And second: Would the security of my network be compromised in any way? (Thinking right, security has nothing to do with nat. Security is about the filter table isnīt it? But Iīd like to read that it doesnīt from someone more experienced.)

I use DHCP too but knowing a bit more wouldnīt hurt anyone. Plus! On a big network, that uses a static valid IP, probably that line using the SNAT rule would bring, if not much, probably a little more productivity to that network wouldnīt it?
 
Old 08-12-2005, 10:23 AM   #10
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
With realistically modern routing equipment (read: old p2 pcs) you can pretty much NAT most connections with no problem.

NAT is generally considered GOOD for security because it makes it impossible for the outside world to connect to the NATted computers without your permission. For example, to run a server behind NAT, you need to enable portforwarding and forward the proper port in.

Of course, the filter table is also important in locking it down more.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SNAT help cranium2004 Linux - Networking 0 05-09-2005 03:38 AM
IPTables: DNAT, SNAT and Masquerading tarballed Linux - Security 3 12-10-2004 03:45 PM
Masquerade or SNAT nesbituk Linux - Networking 5 09-08-2004 04:11 PM
[MS Direct Play DNAT SNAT] MrGreg Linux - Networking 2 06-09-2002 06:58 PM
IPTables - DNAT, SNAT, port forwarding FunkFlex Linux - Security 2 01-15-2002 07:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration