LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-14-2007, 02:28 AM   #1
fj8283888
LQ Newbie
 
Registered: Mar 2007
Posts: 15

Rep: Reputation: 0
iptables forwarding setting


Hi,

how to do the forwarding in iptables

I would like to forward xxx.xxx.xxx.xxx:1234 to www.abc.net:1234

is it possible to use domain instead. I can set it, if I use ip address of www.abc.net the thing is the website is not a fixed ip

thank you heaps
 
Old 03-14-2007, 03:43 AM   #2
mether
Member
 
Registered: Mar 2007
Distribution: RHEL, Fedora, Open Suse
Posts: 151

Rep: Reputation: 31
As far as i know fowarding ( iptables ) work with IP only. What you need is possible with IP's using SNAT. Below doc can be helpful :

http://www.redhat.com/docs/manuals/e...l-ipt-fwd.html
 
Old 03-14-2007, 04:29 AM   #3
fj8283888
LQ Newbie
 
Registered: Mar 2007
Posts: 15

Original Poster
Rep: Reputation: 0
so, how to change it??
 
Old 03-14-2007, 06:22 AM   #4
mehdi.sadighian
LQ Newbie
 
Registered: Mar 2007
Posts: 10

Rep: Reputation: 1
forwarding

IT SEEMS THAT YOU WANT TO HAVE A DESTINATION NAT.
YOU WANT TO FORWARD THE PACKETS THAT ARE GOING TO xxx.xxx.xxx.xxx:1234 TO www.abc.net:1234.

IT REQUIRE A DENSTINATION NAT THAT MEANS IT.
IF IT'S TRUE YOU SHOULD WRITE SOME COMMANDS LIKE THIS, BUT NOT EXACTLY THIS BECAUSE IM NOT HAVE A LINUX BOX NOW TO TRY UT FIRST:

iptables -t nat -A PREROUTING -d xxx.xxx.xxx.xxx -p tcp --dport 1234 -j DNAT --to-destination www.abc.net:1234

echo 1 > /proc/sys/net/ipv4/ip_forward

IT WILL WORK WITH THE DOMAIN NAMES IF THE DNS SERVER IS VALID AND CAN RESOLVE THE DOMAIN NAMES(CHECK THE /etc/resolve.conf).

EXAMPLE:

iptables -t nat -A PREROUTING -d www.yahoo.com -p tcp --dport 80 -j DNAT --to-destination www.google.com

GOOD LUCK.
 
Old 03-14-2007, 06:36 AM   #5
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
AFAICT, domain names won't work in the PREROUTING chain like they do with other chains (please correct me if i'm wrong)... either way, you'd need to keep your iptables box informed about what dynamic IP is assigned to the domain name at the time (smells like a cron job maybe)... the rule would then need to be changed whenever the IP changes... an illustration of a possible cron job:
Code:
ABC_IP=`ping -c1 -n abc.net | head -n 2 | grep icmp_seq | \
awk '{print $4}' | awk -F ':' '{print $1}'`

iptables -t nat -A PREROUTING -p TCP -d xxx.xxx.xxx.xxx --dport 1234 \
-j DNAT --to-destination $ABC_IP
NOTE: yes, i know this illustration is quite ugly... the method i used to get the IP kinda sucks, plus this also lacks a way to get rid of the old rule, etc, etc, etc... =/

Last edited by win32sux; 03-14-2007 at 02:34 PM.
 
Old 03-14-2007, 08:02 PM   #6
fj8283888
LQ Newbie
 
Registered: Mar 2007
Posts: 15

Original Poster
Rep: Reputation: 0
It's working thx


Quote:
Originally Posted by win32sux
AFAICT, domain names won't work in the PREROUTING chain like they do with other chains (please correct me if i'm wrong)... either way, you'd need to keep your iptables box informed about what dynamic IP is assigned to the domain name at the time (smells like a cron job maybe)... the rule would then need to be changed whenever the IP changes... an illustration of a possible cron job:
Code:
ABC_IP=`ping -c1 -n abc.net | head -n 2 | grep icmp_seq | \
awk '{print $4}' | awk -F ':' '{print $1}'`

iptables -t nat -A PREROUTING -p TCP -d xxx.xxx.xxx.xxx --dport 1234 \
-j DNAT --to-destination $ABC_IP
NOTE: yes, i know this illustration is quite ugly... the method i used to get the IP kinda sucks, plus this also lacks a way to get rid of the old rule, etc, etc, etc... =/
 
  


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
IPCHAINS port forwarding and IPTABLES port forwarding ediestajr Linux - Networking 26 01-14-2007 07:35 PM
Forwarding using IPTables depam Linux - Networking 1 01-19-2006 04:30 PM
iptables forwarding... AnalyticaL Linux - Networking 5 09-28-2004 08:55 AM
iptables and forwarding rincewind Linux - Networking 2 03-30-2004 11:23 AM
Iptables Forwarding Help!! jglazner Linux - Networking 2 10-20-2003 05:04 PM

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

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