LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-03-2009, 06:22 AM   #1
TaNeK
Member
 
Registered: Dec 2004
Posts: 59

Rep: Reputation: 15
Static NAT with IPtables?


Hi there!

I just got a router with NAT running by using IPtables. Atm though it's set for the whole internal subnet (10.1.0.0 /16, and don't worry, its really not that large!) to be translated to just the external address of the router (X.X.X.66 /29). I can ping out from the inside network fine.

What I want, and which I cannot really wrap my mind around how to make happen, is to have internal servers get static NAT:ed addresses. For example, my internal DNS server (internal IP: 10.0.255.1) should be mapped to have the outside IP of X.X.X.68.

The valid external addresses I've got is the range of X.X.X.66-X.X.X.72, and so I would also like to make an address pool out of the ones not used by the router and internal servers statically and then use that pool for all client connections to the Internet.

I hope this made sense, thanks in advance.

/tanek

Posting some configuration data below.

Code:
Some addresses and gateways:
eth0 (External): IP X.X.X.66, GW X.X.X.65
eth1 (Internal): IP 10.1.255.254, GW X.X.X.66
internal DNS: IP 10.1.255.1, GW 10.1.255.254

Forwarding rules:
iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
iptables -A FORWARD -j LOG

Enabling NAT/MASQUERADING:
iptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE
 
Old 04-03-2009, 06:42 AM   #2
SonJelfn
Member
 
Registered: Aug 2003
Location: Sendai, Japan
Distribution: Slackware, Slackware64, Debian
Posts: 63

Rep: Reputation: 17
Hello,

to have your packets NAT to a specific address you will have to do a little source IP matching and then use the SNAT target in iptables. This should do what you want.

You can read about the SNAT target here:

http://iptables-tutorial.frozentux.n...tml#SNATTARGET

Hope that helps.

Good luck.
 
Old 04-03-2009, 12:52 PM   #3
TaNeK
Member
 
Registered: Dec 2004
Posts: 59

Original Poster
Rep: Reputation: 15
Thank you! This helps for using the full IP range of external addresses. However I can't see how I can map one internal address statically to one external address.

Halfway there, cheers .
 
  


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
iptables: can't initialize iptables table `NAT' linuxgentoo Linux - Kernel 3 01-17-2010 10:15 AM
Removing a NIC, DHCP, NAT and going static WorldBuilder Linux - Networking 8 07-21-2007 07:44 PM
[OpenBSD 3.9] NAT Configuration/ Static IP Slycer *BSD 4 05-16-2006 04:14 AM
Remote access via static NAT mattp Linux - Security 5 01-13-2006 07:36 AM
Static NAT / DMZ / VPN question Funky D Linux - Networking 1 10-22-2004 07:17 AM

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

All times are GMT -5. The time now is 12:14 AM.

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