LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 12-11-2005, 04:49 PM   #1
cashton2k
Member
 
Registered: May 2004
Posts: 46

Rep: Reputation: 15
port address tranlstion


ive been struggling with this for days, wondering if any one cud give me some help.

i need to apply port address translation (overloaded network address translation) to all traffic originating on my network and destined for the outside network and beyond - using iptables.

any ideas on a command?

cheers for any help
 
Old 12-11-2005, 06:55 PM   #2
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
Could you explain a bit more about what you'd like to do? Are you trying to do Port->Host mappings or load-balancing? Or did you mean NAT?
 
Old 12-12-2005, 09:36 AM   #3
cashton2k
Member
 
Registered: May 2004
Posts: 46

Original Poster
Rep: Reputation: 15
NAT i think, im really stuck - this is what i have at the moment

externalinterface="eth1"

externaladdress="`ifconfig $externalinterface | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"

iptables -t nat -A PREROUTING -p tcp -i eth0 -d $externaladdress --dport 80 --sport 1024:65535 -j DNAT --to 172.24.15.0:8080

iptables -t nat -A PREROUTING -p tcp -i eth0 -d $externaladdress --dport 443 --sport 1024:65535 -j DNAT --to 172.24.15.0:8080

to me it seems like it shud work but i dunno lol
 
Old 12-12-2005, 10:49 AM   #4
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
That looks like it should work for the DNAT part. Do you have rules to handle the outgoing traffic (like SNAT or Masquerading)? Also do you have rules in the FORWARD chain to pass packets from the external to internal interfaces (and vice versa)? Did you enable packet forwarding in the kernel (echo "1" > /proc/sys/net/ipv4/ip_forward)?
 
Old 12-12-2005, 11:01 AM   #5
cashton2k
Member
 
Registered: May 2004
Posts: 46

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Capt_Caveman
That looks like it should work for the DNAT part. Do you have rules to handle the outgoing traffic (like SNAT or Masquerading)? Also do you have rules in the FORWARD chain to pass packets from the external to internal interfaces (and vice versa)? Did you enable packet forwarding in the kernel (echo "1" > /proc/sys/net/ipv4/ip_forward)?

i havent enabled port forwarding ill try that now, i have snat rules but i think they are in the same condition as my dnat rules lol and i have the following for the FORWARD chain:

iptables -A FORWARD -p tcp -s 192.168.0.0/16 -d 172.24.15.1 --dport 443 -j ACCEPT

iptables -A FORWARD -p tcp -s 192.168.0.0/16 -d 172.24.15.1 --dport ! 80 -j DROP

cheers for the help, much appreciated
 
Old 12-12-2005, 01:19 PM   #6
Darin
Senior Member
 
Registered: Jan 2003
Location: Portland, OR USA
Distribution: Slackware, SLAX, Gentoo, RH/Fedora
Posts: 1,024

Rep: Reputation: 45
Quote:
Originally Posted by cashton2k
NAT i think, im really stuck - this is what i have at the moment

externalinterface="eth1"

externaladdress="`ifconfig $externalinterface | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"

iptables -t nat -A PREROUTING -p tcp -i eth0 -d $externaladdress --dport 80 --sport 1024:65535 -j DNAT --to 172.24.15.0:8080

iptables -t nat -A PREROUTING -p tcp -i eth0 -d $externaladdress --dport 443 --sport 1024:65535 -j DNAT --to 172.24.15.0:8080

to me it seems like it shud work but i dunno lol
So your intent is to send all web (port 80 http and 443 https) requests to a proxy server?

Two things I noticed are that the NAT rules you set up seem too specific and you are forwarding to what appears to be a network address, rather than a specific host. Try something like:
Code:
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -j DNAT --to 172.24.15.5:8080

iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 443 -j DNAT --to 172.24.15.5:8080
where 172.24.15.5 is the actual IP of the proxy server.
 
  


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
how to address serial port from c abd_bela Programming 1 06-30-2005 02:48 PM
bridge port mac address fssengg Linux - Networking 3 05-30-2005 07:41 AM
base address and port address Nodren Linux - Hardware 0 08-30-2004 02:54 PM
Firewall - Allow 1 IP address on port x Beuzekom Linux - Networking 4 01-26-2004 07:11 AM
how to forward port to another address cmardhekar Linux - General 1 08-25-2001 09:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:10 AM.

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