<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 7, 2015 at 11:41 AM, shimi <span dir="ltr"><<a href="mailto:linux-il@shimi.net" target="_blank">linux-il@shimi.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Wed, Jan 7, 2015 at 11:35 AM, shimi <span dir="ltr"><<a href="mailto:linux-il@shimi.net" target="_blank">linux-il@shimi.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Wed, Jan 7, 2015 at 10:16 AM, Erez D <span dir="ltr"><<a href="mailto:erez0001@gmail.com" target="_blank">erez0001@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>hello.<br><br></div>I have an iptables question<br><br></div>i have the following<br><br></div>ext_ip -> NAT1 -> linux firewall-> network -> computer1:eth0 .. computer99<br></div><div><br></div><div></div>i have no control over NAT1.<br>computer1 also can reach the internet via eth1.<br><br></div>linux firewall redirects incoming port 7777 from ext_ip to computer1<br></div>however i need coputer2 .. computer99 to connect to ext_ip:7777 and also reach computer1<br><br></div>so first i did a NAT rule in linux firewall to redirect all packets from internal to ext_ip:7777 to computer1. and did an 'ifconfig eth0:1 $ext_ip up' on computer1.<br></div>this works. however it causes computer1 not to be able to access real ext_ip via eth1 which is connected to the internet as well<br><br></div>so i though of both doing DNAT and MASQ, which will do the same but will not require assiging ext_ip to computer1. <br></div>howerver i do not know how to do that<br><br></div></div></blockquote><div><br></div></div></div><div>If computer1 can access ext_ip:7777, all you need is to allow ip_forward (/etc/sysctl.conf for permanent, and echo 1 > /proc/sys/net/ipv4/ip_forward) on computer1, and have all other computers have a static route to ext_ip via computer1<br><br></div><div>Then, in computer1,<br><br></div><div>iptables -t nat -I POSTROUTING -o <interface going towards ext_ip> [ -i <interface subnet of computers come from> ] -s <subnet of computers/netmask> -p tcp --dport 7777 -j MASQUERADE<br><br>should do...<br><br></div><div>(of course, assuming the iptables FORWARD chain is not dropping those packets; otherwise you'ld need an ACCEPT rule there, too...)<br><br></div><div>HTH,<br><br></div><div>-- Shimi<br></div></div><br></div></div></blockquote><div><br></div></div></div><div>And on a second read, I think I got you wrong and the purpose was to access computer1 port 7777 (hopefully listening on 0.0.0.0) from computersN by using the external IP from the inside?<br></div></div></div></div></blockquote><div>yes <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>If so, did:<br><br></div></div></div></div></blockquote><div>couputerN default route is the linux firewall. without any rules on linux firewall, it will forward packets from computer1 destined to ext_ip to NAT1. and they will not reach computer1 att all, so rules on computer 1 are useless.<br></div><div>Doing a DNAT on linux firewall will direct the packets to computer1, however computer 1 will know comuterN and will reply directly without going through linux firewall, and computer1 will not match the packets to the original connection.<br></div><div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>iptables -I PREROUTING -i <interface of computersN subnet> -s <subnet of computers/netmask> -p tcp --dport -j REDIRECT --to-port 7777<br></div></div><br></div><div class="gmail_extra">not work?<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div class="gmail_extra">-- Shimi<br></div></font></span></div>
</blockquote></div><br></div></div>