Fedora Linux Support Community & Resources Center
  #1  
Old 21st March 2007, 08:29 PM
lnorris Offline
Registered User
 
Join Date: Feb 2005
Posts: 3
IPTables and forwarding

I have a machine that I want to bridge two networks. We'll say that one is on a 10.10.0.0 network and another on a 192.168.0.0 network.

eth0= internal or 10.10.0.0/24 network (ip 10.10.0.40)
eth1 = external or 192.168.0.0/24 network (ip 192.168.0.112)

I want eth1 to forward ssh and http traffic to specific servers on the 10.10.0.0 network.

So a HTTP or SSH request to 192.168.0.112 would get proxied to a machine on the 10.10.0.0 network.

For the life of me, I can't get this working. I've tried several samples scripts and different ways of doing it but no luck. I'll post one of the ways (simplest one). If someone could please tell me what I'm missing it would save the wall and my head a lot of grief. Thanks.

--------------------------------------------------

#!/bin/sh

INTERNAL="eth0"
EXTERNAL="eth1"

INTERNAL_IP="10.10.0.40"
EXTERNAL_IP="192.168.0.112"

SSH_IN_PORT="22"
SSH_OUT_PORT="22"
SSH_IP="192.168.0.110"

iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

#CROSS YOUR FINGERS!!!
#iptables -t nat -A PREROUTING -p tcp -i $EXTERNAL -d $EXTERNAL_IP --dport $SSH_IN_PORT -j DNAT --to $SSH_IP:$SSH_OUT_PORT
#iptables -A FORWARD -p tcp -i $EXTERNAL -d $SSH_IP --dport $SSH_OUT_PORT -j ACCEPT

#Try with Masquerading..
iptables -t nat -A PREROUTING -d $EXTERNAL_IP -p tcp --dport $SSH_IN_PORT -j DNAT --to $SSH_IP
iptables -A FORWARD -p tcp --dport $SSH_OUT_PORT -d $SSH_IP -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -p tcp --dport $SSH_OUT_PORT -d $SSH_IP -j MASQUERADE

echo 1 > /proc/sys/net/ipv4/ip_forward
Reply With Quote
  #2  
Old 22nd March 2007, 11:46 PM
EdmunTimberlane Offline
Registered User
 
Join Date: Apr 2005
Posts: 92
This should do it:

iptables -t nat -A PREROUTING -i $EXTERNAL -p tcp --dport $SSH_IN_PORT -j REDIRECT --to $INTERNAL_IP
Reply With Quote
  #3  
Old 26th March 2007, 02:16 PM
lnorris Offline
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks for your help, but it's still not working. I tried using that line in place of the one that had the "-j DNAT". I tried using it all by it's self. Nothing worked.

I did notice however that the SSH_IP was wrong in my example. It should have been a 10.10.0.0/24 IP. We'll say it's 10.10.0.70... So I also changed the --to line to read SSH_IP but did try it with internal INTERNAL_IP to with no success either.

I know it's something simple as this is really just a basic firewall with IP forwarding. I'm missing something...

So, modified with REDIRECT instead of DNAT it's:

#!/bin/sh

INTERNAL="eth0"
EXTERNAL="eth1"

INTERNAL_IP="10.10.0.40"
EXTERNAL_IP="192.168.0.112"

SSH_IN_PORT="22"
SSH_OUT_PORT="22"
SSH_IP="10.10.0.70"

iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

#Forward SSH to an internal server.
#iptables -t nat -A PREROUTING -d $EXTERNAL_IP -p tcp --dport $SSH_IN_PORT -j DNAT --to $SSH_IP
iptables -t nat -A PREROUTING -i $EXTERNAL -p tcp --dport $SSH_IN_PORT -j REDIRECT --to $SSH_IP
iptables -A FORWARD -p tcp --dport $SSH_OUT_PORT -d $SSH_IP -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -p tcp --dport $SSH_OUT_PORT -d $SSH_IP -j MASQUERADE

echo 1 > /proc/sys/net/ipv4/ip_forward
Reply With Quote
Reply

Tags
forwarding, iptables

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables forwarding flapping AIM Systems Servers & Networking 0 14th October 2009 09:43 PM
iptables and X11 forwarding bowens44 Security and Privacy 0 14th October 2007 02:14 PM
port forwarding IPTABLES best_112 Security and Privacy 1 18th February 2007 12:32 AM
Port forwarding (iptables?) nathanW Servers & Networking 23 6th October 2006 04:31 PM
forwarding SSH with iptables? madnachos Servers & Networking 4 12th September 2006 03:21 AM


Current GMT-time: 03:06 (Thursday, 23-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat