besides shorewall, firehol is another helping tool and really easy to understand<br><br><div><span class="gmail_quote">On 4/25/07, <b class="gmail_sendername">Lennart Sorensen</b> <<a href="mailto:lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys@public.gmane.org">
lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys@public.gmane.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Wed, Apr 25, 2007 at 06:40:43PM +0300, Kihara Muriithi wrote:
<br>> Hi all,<br>> I have been attempting to use iptables to NAT internal IPs to an external<br>> IP without success. I have experience with iptables, but mainly on how to<br>> close or open specific ports. Nat has proved a little challenging and thats
<br>> why i am seeking assistance.<br>> Lets say I have an internal IPs as <a href="http://10.0.0.0/24">10.0.0.0/24</a> and need all those IP natted<br>> to an external IP <a href="http://192.168.2.1">192.168.2.1
</a>. This is what I have attempted in my quest to<br>> find a solution.<br>> /sbin/iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to <a href="http://192.168.2.1">192.168.2.1</a><br>><br>> when I check the firewall status, I notice this table insertion
<br>> Chain POSTROUTING (policy ACCEPT)<br>> target     prot opt source               destination<br>> SNAT       all  --  <a href="http://0.0.0.0/0">0.0.0.0/0</a>            <a href="http://0.0.0.0/0">0.0.0.0/0</a>
           to:<a href="http://192.168.2.1">192.168.2.1</a><br><br>I prefer the output of iptables with -v added to show which interface<br>the rule applies to.<br><br>You might also want to make it only apply to the 10.x network, rather
<br>than everything.  So try adding -s <a href="http://10.0.0.0/24">10.0.0.0/24</a> to that rule above.<br><br>> To be frank, I expected <a href="http://192.168.2.1">192.168.2.1</a> to be the destination. The way the<br>
> details are presented is confusing, IMO. Whats however puzzling is this<br>> command is rejected when I attempt to make it persistant as seen below.<br>> vi /etec/sysconfig/iptables<br>> Just before the line below, I inserted the second command
<br>> REJECT     all  --  <a href="http://0.0.0.0/0">0.0.0.0/0</a>            <a href="http://0.0.0.0/0">0.0.0.0/0</a>           reject-with<br>> icmp-host-prohibited<br>> -A POSTROUTING -o eth0 -j SNAT --to <a href="http://192.168.2.1">
192.168.2.1</a><br><br>The destination is any address that is outside through eth0.  <a href="http://0.0.0.0/0">0.0.0.0/0</a><br>means any.  The source you didn't specify in your case so that too<br>was any.  The only requirement you supplied was that it be stuff going
<br>out eth0.<br><br>> This however don't work as iptable throws an error message and fails to come<br>> up.<br>> Now the question is, what is the proper way of doing a nat throw a linux<br>> box? I have enabled IP forwarding by the way.
<br><br>I personally tend to use shorewall to manage the specific iptables rules<br>since it adds a more comprehensible and manageable abstraction on top of<br>iptables.<br><br>With shorewall you could do something as simple as this in your
<br>/etc/shorewall/masq file:<br><br>#INTERFACE              SUBNET          ADDRESS         PROTO   PORT(S) IPSEC<br>eth0                    eth1            <a href="http://192.168.2.1">192.168.2.1</a><br><br>--<br>Len Sorensen
<br>--<br>The Toronto Linux Users Group.      Meetings: <a href="http://gtalug.org/">http://gtalug.org/</a><br>TLUG requests: Linux topics, No HTML, wrap text below 80 columns<br>How to UNSUBSCRIBE: <a href="http://gtalug.org/wiki/Mailing_lists">
http://gtalug.org/wiki/Mailing_lists</a><br></blockquote></div><br>