Question

Hopefully simple port-forwarding solution needed, single port

Asked by: davebytes

I'm running Fedora Core 4 as my base.  I don't know offhand what's installed as optional bits and pieces, but iptables --list outputs a blank list (which I assume means it's installed. ;)).

Okay, network topology.  I'm running a standard 'home lan' behind a wifi router, IP addresses 192.168.0.x, router does dhcp, nat, etc.  I have two PCs, one XP, one FC4.  The FC4 box has a second nic, connected via crossover to an embedded development box.  The primary nic is say 192.168.0.66 on the local lan, the embedded box is 10.0.0.101 via the secondary nic (ie, secondary 'hidden' network 10.0.0.x).

So, the FC4 box can ping/telnet the embedded box, but the windows box obviously can't.  I want to make it so that I can forward packets on one port (one particular port), pointing the XP box to the FC4 box, and having the FC4 box forward stuff along (and back) I guess making a NAT connection from XP -> embedded on that port.

I don't want to set up any further firewalling, filtering, etc.  The FC4 box is a fully-working network client, and no other functions/services should be disrupted.  i.e., I don't want to turn the FC4 box into a generalized NAT router/firewall for the embedded box subnet.  Just a 'tunnel' for the XP and embedded boxes to talk over a given port.  Use port 8888 for crafting an example.

I assume this should be one or two rules in iptables or other method, plus maybe one or two other commands to actually turn on iptables (or, again, whatever method) routing.  I'm a developer, have some concept of NAT, et al, but haven't found a simple solution -- everything is making a linux box into a full firewall/router.

Set at 250 points to start, but I'll kick this up to 500 points if I got a working solution today (that is, I get a solution, and implement it and it works..). ;)

-d

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-04-18 at 08:46:36ID21817777
Tags

port

,

forward

,

linux

Topic

Linux Networking

Participating Experts
4
Points
500
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Port Forwarding on IPTABLES
    Hi, I have a linux router setup and I want to forward all requests on 3389 (terminal server) to an internal IP address. This is what i have so far, but it doesn't work, I get the "Client cound not connect to the remote computer" when I try. *****************...
  2. iptables on fedora
    Hi experts, i recently changed over from red hat to fedora. Everything was working fine on red hat but when I tried to migrate my config files over things changed. I have my iptables set up where everyone on the inside can get out but this isn't working now it seems. On the...
  3. simple iptables setup for fedora
    I'm trying to setup a simple firewall for my fedora box. I'm using vnc, so it's currently set to allow 5901:5910, but I think it's also allowing everything else. I'm very new to this and have no real understanding of iptables. In the meantime as I learn, I need a simple b...
  4. SQL Server via ssh tunnel and iptables port forwarding
    Hi, I have the following situation: From a server (<webserver>) on the internet, I want to connect to a SQL Server database on an internal windows server (call it <dbserver>), via a linux server (call it <myserver>), both of which are inside a firewall. M...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: bstrauss3Posted on 2006-04-18 at 08:51:47ID: 16479156

Actually, you probably want to use ssh to tunnel, rather than iptables.  Especially if you only need say ssh or one other service.

This article: http://www.oreillynet.com/pub/a/wireless/2001/02/23/wep.html - although ostensibly about wireless, shows you what you need to do.

-----Burton

 

by: DonConsolioPosted on 2006-04-18 at 16:14:34ID: 16482999

xinetd can do what you need

edit "/etc/xinbet.conf"

# service name /etc/services
# e.g.: myservice  8888/tcp
service myservice
{
        disable = no
        flags = reuse
        socket_type = stream
        wait = no
        user = nobody
        redirect = 10.11.12.13 9999
        only_from = 10.0.0.0/16
        log_on_failure += USERID
        log_on_success += PID HOST EXIT DURATION
}

and activate the xinetd daemon in /etc/init.d

 

by: RedimidoPosted on 2006-04-18 at 22:20:37ID: 16484601

add this in your rc.local file:

#this enables forward so packets can traverse the firewall:
echo "1" > /proc/sys/net/ipv4/ip_forward
#this rule does the DNAT thing (what you asked for assuming eth0=LAN and eth1=crossover to box):
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 8888 -j DNAT --to-destination 10.0.0.101:8888

#if this is not working because the embebbed box does not have the linux one as its default gatewaty, then
# you need to masquerade internally, so add this rule to make things "fully transparent":
iptables -t nat -A POSTROUTING -p tcp --dport 8888 -o eth1 -j MASQUERADE

1.- I assume your FC4 box already can connect to the embebbed box
2.- I assume you had no other rules in your FC4 box, so all defaults are "ACCEPT"

Happy Linuxing

 

by: davebytesPosted on 2006-04-19 at 08:50:31ID: 16489095

Thanks for the responses so far.

bstrauss3: interesting approach, tunneling via ssh.  didn't seem to immediately work for me, and it requires that the XP box be running an ssh connection (which I happen to do, but people I work likely don't...).  not counting it out yet...

DonConsolio: hmmm.  that seems like a pretty simple approach.  unforunately, I tried it and wasn't seeming to work.  starting to make me wonder if this custom app/protocol is set up properly on the embedded box (I'm looking into that...).  But certainly seems the most promising, given that the fowarding service can be encapsulated into one file, dropped into xinetd.d, and 'just work' if everything else is correct. ;)  btw, the 'modified' thing I tried was:

service myservice
{
        disable         = no
        flags           = reuse
        socket_type     = stream
        protocol        = tcp
        user            = root
        wait            = no
        port            = 7876
        redirect        = 10.0.0.101 7876
        log_on_failure  += USERID
        log_on_success  += PID HOST EXIT DURATION
}

... seemed that setting the protocol is useful (since I know it is tcp), and setting the port is required (since 'myservice' isn't in services...).  anyway, again, I need to see if my embedded box is working correctly, as I would have thought that would 'just work'...

Redimido: that was basically what I had thought I could do.  but here's my problem:
- I do that, and type iptables --list, and don't see the rules (I assume I should).  In fact, PREROUTING and POSTROUTING aren't listed as default chains (it lists FORWARD/INPUT/OUTPUT).  I tried to create them as new chains (don't think I should have to, but tried), and they show up without any rules -- I assume the rules should show up when I do a --list command.
- I found a reference on the net to forwarding port 80 external to port 8080 on an internal box.  That had some addition FORWARD commands, so I added them to my rc.local.  lo and behold, THEY show up in the --list, but the two NAT commands don't still.  weird.
- as to your questions, yes, I can ping and telnet into the embedded box, and yes, I'm not otherwise using iptables already.
- so... this method doesn't seem to be even getting initialized for me.  Though, like xinetd approach, seems it would 'just work' if everything was correct.

I'm going to go back and verify with others that the custom protocol is set up and working on my embedded box (assuming there's an easy way to do that...), and then I can at least quickly re-enable the xinetd service and see if that works.

I've upped the points to 500 so I can split if needed.

-d

 

by: bstrauss3Posted on 2006-04-19 at 09:08:23ID: 16489270

Ah

PRE and POST routing are NOT part of the filter chain, but rather part of mangle:

# iptables -t mangle -L -vn



-----Burton

 

by: bstrauss3Posted on 2006-04-19 at 09:11:55ID: 16489300

This article: http://www.linuxnetmag.com/en/issue9/m9iptables1.html has this diagram: http://www.linuxnetmag.com/share/issue9/iptables3.jpg which shows how the tables all fit together!

-----Burton

 

by: davebytesPosted on 2006-04-19 at 09:32:28ID: 16489485

actually, this article had an even better diagram... ;)
http://www.siliconvalleyccie.com/linux-hn/iptables-intro.htm

seems to indicate that PRE and POST can be rules in 'nat' or 'mangle'.  the rules you gave me were -t nat.

running "iptables -t nat -L -vn" results in:
=============================================
Chain OUTPUT (policy ACCEPT 5 packets, 502 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 7 packets, 694 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 MASQUERADE  tcp  --  *      eth1    0.0.0.0/0            0.0.0.0/0           tcp dpt:7876

Chain PREROUTING (policy ACCEPT 2 packets, 126 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DNAT       tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp dpt:7876 to:10.0.0.101:7876
==============================================

Aside from the src/dst fields being unset (which I'm guessing I could add to the commands if needed), the rest of the output looks correct for the rules given.

I'll let you know as soon as I can test/prove the embedded box is set up and working correctly (which, since it was handed to me I assume it should be, but...).

-d

 

by: bstrauss3Posted on 2006-04-19 at 13:34:34ID: 16492131

I like that diagram too!  The flow of nat and mangle is clear, it's the usages that aren't... The reason those diagrams are important is that in Linux  2.4 kernel, packets could hit TWO places in the 'filter' chain and it wasn't always clear where to put rules for what purpose.  With 2.6 there's only ONE place, but it's easy to get confused.

FWIW, (ideally) the nat table is used only for Network Address Translation and the mangle table for changing packet contents (TOS, etc.) but as you have found they're VERY useful for a lot of other purposes.

Personally?  I really like using mangle for blacklist/blackhole - it's just too nice to be able to do it fast, early and dirty...

-----Burton

 

by: davebytesPosted on 2006-04-19 at 14:12:41ID: 16492581

BTW, I've been trying netstat -l on my embedded box, and I'm not actually seeing a listening port waiting for the connection -- so there's obviously something else wrong on my system (which I've been told should be working!) that I need to fix before I can properly test the approaches.  I'll keep y'all posted. ;)

-d

 

by: RedimidoPosted on 2006-04-19 at 16:03:31ID: 16493471

if your embedded box has its system depending upon inetd or xinetd, then you will never see a port listening. it's inetd the one that will launch the program once a packet arrives on the port.

good luck

 

by: davebytesPosted on 2006-04-19 at 16:16:12ID: 16493548

right.  no, it's a custom application which should be opening a listening port, but doesn't seem to.  I'm trying to verify with a coworker that netstat does indeed show it waiting.

-d

 

by: XoFPosted on 2006-04-19 at 22:07:44ID: 16495131

> if your embedded box has its system depending upon inetd or xinetd, then you will never see a port listening.

Hmm, IMHO not correct. When a service is started by inetd, this does not mean, that this service has no listen socket. A pop3-daemon started by inetd for example needs a listen socket on port 110 anyway - it's just that this socket isn't bound by the pop3d, but by (x)inetd. This concept just centralizes the basic IP operations and makes development of network services much easier, since you do not have to care about all that IP-related stuff. Example:

#!/bin/sh
while true
do
  read line
  echo "$line"
done


Save this snippet as echo.sh. Configure it as service in inetd.conf, bind it to e.g. port 10000. Telnet on that port and - voila - you have a full functional echo service.
As you can see, the code above doesn't do any socket operations, so the listen socket has to be bound by inetd.




Back to the basic problem:

> iptables -t nat -A POSTROUTING -p tcp --dport 8888 -o eth1 -j MASQUERADE

MASQUERADE is not the best choosen target in this case, SNAT is to be preferred here, since we have static IPs.
Depending on the default policy, it furthermore might be necessary to allow the forwarded packets in the FORWARD chain.
So the complete ruleset would look like that:

echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -I PREROUTING -i eth0 -p tcp --dport 8888 -j DNAT --to-destination 10.0.0.101:8888
iptables -t nat -I POSTROUTING -p tcp --dport 8888 -o eth1 -j SNAT --to-source 10.0.0.1
iptables -I FORWARD -p tcp -i eth0 -o eth1 --dport 8888 -j ACCEPT


A completely different approach:
Assign a second IP Address out of the 10.0.0.0 network (e.g. 10.0.0.200) to the XP-box. Then enable proxy-arp:


echo "1" > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp
echo 1 > /proc/sys/net/ipv4/conf/eth1/proxy_arp
ip route del 10.0.0.0/24 dev eth0
ip route del 10.0.0.0/24 dev eth1
ip route add 10.0.0.200 dev eth0
ip route add 10.0.0.0/24 dev eth1


Cheers,

-XoF-

 

by: RedimidoPosted on 2006-04-20 at 09:14:05ID: 16499748

Hello

XoF: you're right. it's inet the one will show listening at the port =) not his program.

for the MASQUERADE thing: I didn't know wat the ip on the embedded side can be. Besides masquerade is just good when ip's are static.

proxy arp solution is good too ;-)

 

by: XoFPosted on 2006-04-20 at 21:22:25ID: 16504665

> for the MASQUERADE thing: I didn't know wat the ip on the embedded side can be

I assumed that reason for your decision to use MASQUERADE when I reached the point to insert an IP-Address in the SNAT rule...;)

 

by: davebytesPosted on 2006-05-03 at 18:36:15ID: 16602032

Hey all -

I appreciate the various approaches/inputs.  I tried to spread points around a bit, based on how close the solution was to what I was looking for.  I never did get the remote service up and running properly, so figured best to close this given the answers are all 'within bounds' of what I needed (will need...).

Thanks!

-d

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...