LinuxQuestions.org
Register a domain and help support LQ
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 04-11-2008, 09:23 AM   #1
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Rep: Reputation: 0
Simple IPTables Question.


Take a look at this rule:
Code:
iptables -t nat -A PREROUTING -p tcp -i eth0 -d 123.123.123.187 --dport 23 -j DNAT --to 192.168.1.202:23
Should that not forward any telnet request to 123.123.123.187 to 192.168.1.202?
It wont work for me.
 
Old 04-11-2008, 12:28 PM   #2
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Original Poster
Rep: Reputation: 0
Really i just need my syntax checked.
because based on what i know about iptables that should work.
 
Old 04-11-2008, 02:21 PM   #3
bzyk
Member
 
Registered: Jun 2007
Location: Poland
Distribution: Debian, Slackware
Posts: 42

Rep: Reputation: 15
Maybe you have another rule before this one? And of course, you must hava SNAT rule... Maybe you have FORWARD closed? show us iptables -L and iptables -L -t nat
 
Old 04-14-2008, 11:24 AM   #4
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Original Poster
Rep: Reputation: 0
I found some garbage in my tables.
As you can see I am trying to do a simple port forward.
I flushed all my other junk rules and have forward set to accept.
So is this correct.
Code:
iptables -t nat -A PREROUTING -p tcp -i eth0 -d 123.123.123.187 --dport 23 -j DNAT --to 192.168.1.202:23
Could it be simplified even more.
I just want all port 23 requests that come to 123.123.123.187 to forward to the internal 192.168.1.202 port 23.
 
Old 04-15-2008, 02:20 AM   #5
bzyk
Member
 
Registered: Jun 2007
Location: Poland
Distribution: Debian, Slackware
Posts: 42

Rep: Reputation: 15
Yes, this is correct, but remember about FORWARD chain (you must allow for this traffic there if you have DROP policy on it), and of course you must have SNAT rule in order to make any usefull efect. something like this;
iptables -A POSTROUTING -t nat -o eth0 -j SNAT --to-source 123.123.123.123 -s 192.168.1.202
 
Old 04-15-2008, 08:13 AM   #6
mtimbro
Member
 
Registered: Feb 2008
Location: Montreal, Canada
Distribution: RedHat 3/4, Ubuntu 7.10
Posts: 86

Rep: Reputation: 15
Lightbulb

Quote:
Originally Posted by Curtix View Post
I found some garbage in my tables.
As you can see I am trying to do a simple port forward.
I flushed all my other junk rules and have forward set to accept.
So is this correct.
Code:
iptables -t nat -A PREROUTING -p tcp -i eth0 -d 123.123.123.187 --dport 23 -j DNAT --to 192.168.1.202:23
Could it be simplified even more.
I just want all port 23 requests that come to 123.123.123.187 to forward to the internal 192.168.1.202 port 23.
You'll need another rule as follows:

/sbin/iptables -A FORWARD -p tcp -i eth0 -d 192.168.1.202 --dport 23 -j ACCEPT

Hope this helps.
 
Old 04-15-2008, 09:00 AM   #7
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Original Poster
Rep: Reputation: 0
Do I not need to state to state a source IP because this system may host multiple IPs on one nic (eth0), Rather can I add -i eth0 to the table.
 
Old 04-15-2008, 09:49 AM   #8
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Original Poster
Rep: Reputation: 0
This just wont work.
Here is my nat table ATM:
Code:
[root@gabriel ~]# iptables -L -t nat
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
SNAT       all  --  192.168.0.0/16       anywhere            to:123.123.123.187

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  --  anywhere             123-123-123-187.isp.net tcp multiport ports telnet to:192.168.1.202:23
[root@gabriel ~]#
Code:
[root@gabriel ~]# iptables -L
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:telnet

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
What am I missing?
 
Old 04-16-2008, 01:44 AM   #9
bzyk
Member
 
Registered: Jun 2007
Location: Poland
Distribution: Debian, Slackware
Posts: 42

Rep: Reputation: 15
Of course you have 123.123.123.187 ip addres on eth0, right?
This rules should work. Hmm... Try to iptables -L -t nat -v to look if any packets coming in this dnat chain. Try to use tcpdump on your LAN card (eth1?), to watch if any packets to telnet service on that lan host coming. something like;
tcpump -i eth1 port 23 and host 192.168.1.202 -n
And watching on tcpdump try to login on telnet (from any remote machine out of your network). Tell us if any packets going out through your router to that telnet machine (tcpudmp show it to you).
 
Old 04-16-2008, 07:33 AM   #10
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Original Poster
Rep: Reputation: 0
Code:
[root@gabriel ~]# iptables -L -t nat -v
Chain OUTPUT (policy ACCEPT 7 packets, 545 bytes)
 pkts bytes target     prot opt in     out     source               destination                       

Chain POSTROUTING (policy ACCEPT 116 packets, 31996 bytes)
 pkts bytes target     prot opt in     out     source               destination                       
67788 3446K SNAT       all  --  any    eth0    192.168.0.0/16       anywhere                                  to:123.123.123.187

Chain PREROUTING (policy ACCEPT 82987 packets, 5701K bytes)
 pkts bytes target     prot opt in     out     source               destination                       
    2   100 DNAT       tcp  --  eth0   any     anywhere             123-123-123-187.i                      sp.net tcp multiport ports telnet to:192.168.1.202:23
[root@gabriel ~]#
See anything thing?
and when I try to telnet to the 123.123.123.187 I just get:
Code:
Trying 123.123.123.187...
Forever.
 
Old 04-16-2008, 08:27 AM   #11
trryhend
LQ Newbie
 
Registered: Oct 2007
Posts: 26

Rep: Reputation: 15
Quote:
Originally Posted by Curtix View Post
Take a look at this rule:
Code:
iptables -t nat -A PREROUTING -p tcp -i eth0 -d 123.123.123.187 --dport 23 -j DNAT --to 192.168.1.202:23
Should that not forward any telnet request to 123.123.123.187 to 192.168.1.202?
It wont work for me.
Not really an iptables expert but...

If it's ok to just redirect all port 23 connections:
Code:
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 23 -j DNAT --to 192.168.1.202
You may need to try it, get someone to initiate a telnet session while looking at tcpdump to see what's happening, and what port is actually being used, (because what you have looks ok to me, but wouldn't know for sure unless tested).

You might also need tell the client to specify port 23
 
Old 04-16-2008, 04:39 PM   #12
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Original Poster
Rep: Reputation: 0
Seeing as how i was LOST. I opted to strip out any garbage and start from scratch.
My Firewall is set to simple NAT outbound connections to share the internet.
All default chains are set to allow.
________________

So NOW I want to just forward inbound ( from the internet ) telnet ( port 23) connections to the WAN ip of 123.123.123.187 (eth0) through 192.168.1.1 (eth1) to to host server 192.168.1.202 on port 23.
Please advise accordingly.
Thanks a lot.
 
Old 04-17-2008, 02:04 AM   #13
bzyk
Member
 
Registered: Jun 2007
Location: Poland
Distribution: Debian, Slackware
Posts: 42

Rep: Reputation: 15
Code:
Chain PREROUTING (policy ACCEPT 82987 packets, 5701K bytes)
 pkts bytes target     prot opt in     out     source               destination                       
    2   100 DNAT       tcp  --  eth0   any     anywhere             123-123-123-187.i                      sp.net tcp multiport ports telnet to:192.168.1.202:23
It looks like packets to telnet machine going out from router (2 pkts). The question is; is 192.168.1.203 answering fot this packets? Is there a telnet service? check it by running tcpdump with option; tcpdump -i eth1 host 192.168.1.203 and port 23 -n
And watch if telnet machine answering for syn packet (try to login from "somewhere in world" to telnet, and in this time look on tcpdump screen)
If you can, show here some log of this tcpdump session.
 
Old 04-17-2008, 07:16 AM   #14
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Original Poster
Rep: Reputation: 0
I can telnet on port 23 to the internal machine from my firewall so I know that much works. As well as a ton of other hosts. Its an application server and everyone telnets into it. Could you suggest some rules again; just the simplest port forward rule, minimal stuff needed to get the port forwarded.
 
Old 04-17-2008, 07:42 AM   #15
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Original Poster
Rep: Reputation: 0
This is what I have ATM and it does not work.
could there be something besides the firewall that would block all inbound telnet connections on the firewall computer?
Code:
[root@gabriel sysconfig]# iptables -L
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:telnet dpt:telnet

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
[root@gabriel sysconfig]#
Code:
[root@gabriel sysconfig]# iptables -L -t nat
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
SNAT       all  --  192.168.0.0/16       anywhere            to:123.123.123.187

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  --  anywhere             anywhere            tcp dpt:telnet to:192.168.1.202:23
[root@gabriel sysconfig]#

Last edited by Curtix; 04-17-2008 at 07:48 AM.
 
  


Reply

Tags
forward, iptables, port, telnet


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
(Un)simple iptables question branden_burger Linux - Security 3 11-19-2006 03:25 PM
Simple iptables question deleted/ Linux - Security 4 05-11-2006 11:31 AM
Problem with iptables, and a simple question about a NTFS part. Jorek Linux - Newbie 2 12-30-2005 02:05 PM
Iptables newbie / simple question wr3ck3d Linux - Networking 2 03-06-2003 08:08 AM
Simple iptables DNAT question taylor Linux - General 0 10-02-2001 06:22 PM


All times are GMT -5. The time now is 09:22 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration