LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-03-2005, 06:13 AM   #1
kernelvn
Member
 
Registered: Aug 2004
Posts: 91

Rep: Reputation: 15
iptables nat


I have 2 pc and I tried to learn how to NAT on those . The fist PC ( 10.0.0.4 ) with iptables and the second (10.0.0.5 ) with apache on it. Now I would like whenerver a http request to 10.0.0.4 , it will forward to 10.0.0.5 and I used :

Quote:
[root@HomeServer sysconfig]# iptables -A FORWARD -p tcp --dport 80 -j ACCEPT
[root@HomeServer sysconfig]# iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to 10.0.0.5
Then I tried "http://10.0.0.4" on the 10.0.0.5 , hoping it will redirect back but nothing happend ( ofcause my httpd on 10.0.0.5 in turn on ) . Could you point me out the wrong in the command abouve , thank you
 
Old 05-03-2005, 06:30 AM   #2
pave
Member
 
Registered: Oct 2004
Posts: 42

Rep: Reputation: 15
You need to supply port after redirect too - look at the end of that rule. Also primary destination address as a source of redirect won't do any harm. (-d 10.0.0.4)

iptables -t nat -A PREROUTING -p tcp -d 10.0.0.4 --dport 80 -j DNAT --to 10.0.0.5:80
 
Old 05-03-2005, 06:36 AM   #3
kernelvn
Member
 
Registered: Aug 2004
Posts: 91

Original Poster
Rep: Reputation: 15
did you mean :
Quote:
# iptables -A FORWARD -p tcp --dport 80 -j ACCEPT
# iptables -t nat -A PREROUTING -p tcp -d 10.0.0.4 --dport 80 -j DNAT --to 10.0.0.5:80
I've tried it , but it does'nt work , thank for your answer

Last edited by kernelvn; 05-03-2005 at 06:37 AM.
 
Old 05-03-2005, 11:00 AM   #4
kernelvn
Member
 
Registered: Aug 2004
Posts: 91

Original Poster
Rep: Reputation: 15
any help ?
 
Old 05-03-2005, 11:38 AM   #5
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 117Reputation: 117
Because of the way tcp works, you cannot use portforwarding within a LAN.

Basically, a packet will be sent from 10.0.0.5 to 10.0.0.4, which redirects it to 10.0.0.5 again. HOWEVER, 10.0.0.5 will reply to 10.0.0.5 directly! 10.0.0.5 is expecting the reply from 10.0.0.4, so will discard this excess packet!
 
Old 05-03-2005, 11:39 AM   #6
kernelvn
Member
 
Registered: Aug 2004
Posts: 91

Original Poster
Rep: Reputation: 15
ya , thank
 
  


Reply


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
IPTables 1:1 NAT Garak Linux - Security 13 12-19-2011 05:03 PM
IPTABLES : build NAT using IPTABLES joseph Linux - Networking 4 04-23-2004 05:08 AM
iptables and NAT arrruken Linux - Networking 8 10-03-2003 04:17 AM
iptables NAT issue. onina Linux - Networking 1 02-26-2003 04:58 AM
IPtables +NAT daromer Linux - Networking 1 01-07-2002 11:15 AM


All times are GMT -5. The time now is 06:37 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