iptables verschil target SNAT en MASQUERADE

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

Anoniem: 8731

Topicstarter
Wie weet wat het verschil is tussen de targets SNAT en MASQUERADE zie vooorbeeld

iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to $ip

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE --to $ip


werkt volgens mij alle twee hetzelfde maar weet het niet zeker !?!?

Acties:
  • 0 Henk 'm!

Anoniem: 7128

Goeie vraag.

Wat ik uit de manpage haal, id dat je SNAT gebruikt bij een statische verbinding, en MASQUERADE bij een dial-up verbinding.
De reden is dat bij MASQUERADE, wanneer het netwerk (tijdelijk) plat gaat, de verbindingen vergeten worden. Dit is handig omdat je bij opnieuw inbellen een ander ip adres zal krijgen.
Bij een statische verbinding zal de open verbinding ook open blijven staan. een ftp-download zal bij een ifconfig down en ifconfig up dus weer door moeten lopen.

Aha, hier dus maar even veranderen :)

Acties:
  • 0 Henk 'm!

Anoniem: 13874

Yups :)
Bovenstaande geldt uiteraard niet alleen voor ppp verbindingen, maar ook voor kabelaars die elke keer een ander IP toegewezen krijgen.
Als je IP redelijk statisch is, dan kan je beter SNAT gebruiken.
6.1 Source NAT

You want to do Source NAT; change the source address of connections to something different. This is done in the POSTROUTING chain, just before it is finally sent out; this is an important detail, since it means that anything else on the Linux
box itself (routing, packet filtering) will see the packet unchanged. It also means that the `-o' (outgoing interface) option can be used.

Source NAT is specified using `-j SNAT', and the `--to-source' option specifies an IP address, a range of IP addresses, and an optional port or range of ports (for UDP and TCP protocols only).

## 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

There is a specialized case of Source NAT called masquerading: it should only be used for dynamically-assigned IP addresses, such as standard dialups (for static IP addresses, use SNAT above).

You don't need to put in the source address explicitly with masquerading: it will use the source address of the interface the packet is going out from. 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
toon volledige bericht