LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-11-2012, 01:55 PM   #1
appleluo
LQ Newbie
 
Registered: Sep 2012
Posts: 2

Rep: Reputation: Disabled
How to config iptables to allow access an internal server


I am trying to configure the iptable to do port forwarding for certain request. The scenario is like this:

Login node A can be accessed from outside. Compute node B running the service can be accessed from A but not from outside. I want to set up iptables so that a request for the service on B from outside can be accessed through A.

A has two ethernet ports: Internal eth0, with ip internal_A and External eth1, with ip external_A.

B has 1 ethernet port, internal eth0. let's say its ip is internal_B

The service listens to internal_B:5900. We open external_A:10000 for user access.

I configure my iptables with the following commands which was copied from some existing system:

1. echo 1> /proc/sys/net/ipv4/ip_forward
2. /sbin/iptables -P FORWARD ACCEPT
3. /sbin/iptables -t nat -A POSTROUTING -j MASQUERADE
4. /sbin/iptables -A PREROUTING -p tcp -t nat --dport 10000 -j DNAT --to-destination interal_B:5900
5. /sbin/iptables -A OUTPUT -p tcp -t nat -d external_A --dport 10000 -j DNAT --to-destination internal_B:5900

But it didn't work. The client always receive the following error message:

Network error: could not connect to server: Hostname_A:10000

Can anybody please help.

Thanks in advance.
 
Old 09-11-2012, 02:59 PM   #2
TheMadIndian
Member
 
Registered: Dec 2007
Distribution: Fedora Slackware CentOS slax RHEL
Posts: 117

Rep: Reputation: 23
Quote:
Originally Posted by appleluo View Post
I am trying to configure the iptable to do port forwarding for certain request. The scenario is like this:

Login node A can be accessed from outside. Compute node B running the service can be accessed from A but not from outside. I want to set up iptables so that a request for the service on B from outside can be accessed through A.

A has two ethernet ports: Internal eth0, with ip internal_A and External eth1, with ip external_A.

B has 1 ethernet port, internal eth0. let's say its ip is internal_B

The service listens to internal_B:5900. We open external_A:10000 for user access.

I configure my iptables with the following commands which was copied from some existing system:

1. echo 1> /proc/sys/net/ipv4/ip_forward
2. /sbin/iptables -P FORWARD ACCEPT
3. /sbin/iptables -t nat -A POSTROUTING -j MASQUERADE
4. /sbin/iptables -A PREROUTING -p tcp -t nat --dport 10000 -j DNAT --to-destination interal_B:5900
5. /sbin/iptables -A OUTPUT -p tcp -t nat -d external_A --dport 10000 -j DNAT --to-destination internal_B:5900

But it didn't work. The client always receive the following error message:

Network error: could not connect to server: Hostname_A:10000

Can anybody please help.

Thanks in advance.
Do you have a rule to allow RELATED,ESTABLISHED traffic?
You should have an output specified for your MASQUERADE rule
Does the server your natting to have the firewall as its gateway?
 
Old 09-12-2012, 10:08 AM   #3
appleluo
LQ Newbie
 
Registered: Sep 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Just solved

Just solved by specifing the input interface "-i eth1 " to command 4:

4. /sbin/iptables -A PREROUTING -p tcp -t nat -i eth1 --dport 10000 -j DNAT --to-destination interal_B:5900

although I don't know why this works.
 
  


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
[SOLVED] IPTables config to allow external clients to connect to internal MS SQL server Smuff Linux - Newbie 4 05-15-2012 04:21 AM
IPtables - cannot access internal webserver tantric Linux - Security 3 03-17-2004 02:20 AM
iptables blocking internal access? complus Linux - Networking 17 03-08-2004 11:14 PM
iptables does not allow me to access internal web server. JawjLindo Linux - Security 2 11-10-2003 02:23 PM
iptables; confusing internal access error sedulous Linux - Newbie 6 10-09-2003 11:52 PM

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

All times are GMT -5. The time now is 02:15 PM.

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