Skip to contentSkip to conversation

SNAT?

DISCUSSION Svavar Örn Eysteinsson 3 participants 3 messages Oct 29, 2002

lore
Share & tools
lore
#0 lore raw

Hi everyone.
I’m very new to doing the SNAT thing.

The thing is, is there any way to SNAT a individual computer on my internal network to a different public ip address?

This is my network

{ INTERNET }

    |
    |
[--------|
[ ROUTER ]
[--------]
    |
    |
    |
x.x.x.98/24
    |
|--eth0----|
| Firewall |
|          |
|          -eth1-> 10.100.0.0/24 Internal Network
|----------|

All my internal network is masqueraded as the x.x.x.98/24 ip address. I want to SNAT my internal IP address 10.100.0.200 to x.x.x.99/24 Is that possible?

Isn't that right, that I need to do the "ip" command for the x.x.x.99 address on my firewall?

I did "ip address add x.x.x.99 dev eth0

Could someone advice me on doing the SNAT thing with iptables. Any help would be appreciated.

Best regards to all,

Svavar Orn
Reykjavik - Iceland

#1 lore raw
Quoted 5 lines · Svavar Örn Eysteinsson

Hi everyone.
I?m very new to doing the SNAT thing.

The thing is, is there any way to SNAT a individual computer on my internal network to a different public ip address?

Yes, you can SNAT anything you like to anything else you like. So long as a
packet goes through netfilter, you can SNAT it.

However, depending on what source address you give it, the replies may or may not get back again, which is a separate routing problem, nothing to do with netfilter.

Remember that if you send packets out through netfilter and NAT them, they will only get reverse-NATted if the replies come back through the same netfilter machine.

Antony.

Signature · 11 lines
This email is intended for the use of the individual addressee(s) named above 
and may contain information that is confidential, privileged or unsuitable 
for overly sensitive persons with low self-esteem, no sense of humour, or 
irrational religious beliefs.

If you have received this email in error, you are required to shred it 
immediately, add some nutmeg, three egg whites and a dessertspoonful of 
caster sugar.   Whisk until soft peaks form, then place in a warm oven for 40 
minutes.   Remove promptly and let stand for 2 hours before adding some 
decorative kiwi fruit and cream.   Then notify me immediately by return email 
and eat the original message.
#2 lore raw
In reply to Svavar Örn Eysteinsson
Quoted 2 lines

The thing is, is there any way to SNAT a individual computer on my internal network to a different public ip address?

Sure.

Quoted 5 lines

All my internal network is masqueraded as the x.x.x.98/24 ip address. I
want to SNAT my internal IP address 10.100.0.200 to x.x.x.99/24 Is that
possible?

Create the rules in this order :

# iptables -t nat -A POSTROUTING -s 10.100.0.200 -j SNAT --to-source
x.x.x.99
# iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -j SNAT --to-source
x.x.x.98
# iptables -A FORWARD -s 10.100.0.200 -d x.x.x.99 -j ACCEPT
# iptables -A FORWARD -s 10.100.0.0/24 -d x.x.x.98 -j ACCEPT

When the first rule is matched, it is executed.
So your PC on 10.100.0.200 hits first its own rule so never hits the subnet rule.
The other PC's don't hit the specific rule and match the subnet rule. Of course the PC would have to have a static IP address, because otherwise another PC could be 10.100.0.200...

Rob