Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Servers & Networking
FedoraForum Search

Forgot Password? Join Us!

Servers & Networking Discuss any Fedora server problems and Networking issues such as dhcp, IP numbers, wlan, modems, etc.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 7th February 2012, 11:03 PM
ole_ersoy Offline
Registered User
 
Join Date: Oct 2006
Posts: 40
linuxfedorafirefox
IPTABLES: NAT from 8080 to 80 not working

Hi,

I'm attempting to redirect requests on port 80 to port 8080. My iptables configuration looks like this:

[root@ole ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.9 on Tue Feb 7 13:11:41 2012
*nat
:PREROUTING ACCEPT [1:272]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
COMMIT
# Completed on Tue Feb 7 13:11:41 2012
# Generated by iptables-save v1.4.9 on Tue Feb 7 13:11:41 2012
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1055:953017]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Tue Feb 7 13:11:41 2012

If I understand correctly the prerouting rule should do the trick. However requests are not getting rerouted. For example this still works:

http://localhost:8080/context/test.jsp

But this does not:
http://localhost/context/test.jsp

Any ideas?

TIA,
- Ole
Reply With Quote
  #2  
Old 8th February 2012, 03:21 AM
07CobaltGirl Offline
Registered User
 
Join Date: Dec 2008
Posts: 55
linuxfirefox
Re: IPTABLES: NAT from 8080 to 80 not working

Quote:
Originally Posted by ole_ersoy View Post
Hi,

I'm attempting to redirect requests on port 80 to port 8080. My iptables configuration looks like this:

[root@ole ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.9 on Tue Feb 7 13:11:41 2012
*nat
:PREROUTING ACCEPT [1:272]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
COMMIT
# Completed on Tue Feb 7 13:11:41 2012
# Generated by iptables-save v1.4.9 on Tue Feb 7 13:11:41 2012
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1055:953017]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Tue Feb 7 13:11:41 2012

If I understand correctly the prerouting rule should do the trick. However requests are not getting rerouted. For example this still works:

http://localhost:8080/context/test.jsp

But this does not:
http://localhost/context/test.jsp

Any ideas?

TIA,
- Ole
Is an "s" allowed? I've always just seen port.

Code:
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-port 8080
Reply With Quote
  #3  
Old 8th February 2012, 03:31 AM
beaker_'s Avatar
beaker_ Offline
Registered User
 
Join Date: Nov 2008
Location: Canada
Posts: 2,062
linuxfedorakonqueror
Re: IPTABLES: NAT from 8080 to 80 not working

And you need to accept input on both ports, I see only port 80 being accepted.
Reply With Quote
  #4  
Old 8th February 2012, 03:32 AM
07CobaltGirl Offline
Registered User
 
Join Date: Dec 2008
Posts: 55
linuxfirefox
Re: IPTABLES: NAT from 8080 to 80 not working

ahhhh, yep. I missed that too. Good catch!
Reply With Quote
  #5  
Old 8th February 2012, 04:49 PM
ole_ersoy Offline
Registered User
 
Join Date: Oct 2006
Posts: 40
linuxfedorafirefox
Re: IPTABLES: NAT from 8080 to 80 not working

Hi,

Thanks for the feedback. The "s" at the end of "ports" is ok. It seems the only thing necessary (At least to get it working for localhost / workstation development) is to add the "-d" flag set to localhost like this:

Code:
iptables -t nat -A OUTPUT -d localhost -p tcp --dport 80 -j REDIRECT --to-ports 8080
Now my configuration looks like this (Note that iptables translated localhost into the localhost ip address):
Code:
# Generated by iptables-save v1.4.9 on Wed Feb  8 10:31:05 2012
*nat
:PREROUTING ACCEPT [74:12295]
:OUTPUT ACCEPT [16:976]
:POSTROUTING ACCEPT [16:976]
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
-A OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
COMMIT
# Completed on Wed Feb  8 10:31:05 2012
# Generated by iptables-save v1.4.9 on Wed Feb  8 10:31:05 2012
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [2516:302400]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Wed Feb  8 10:31:05 2012
Cheers,
- Ole
Reply With Quote
Reply

Tags
8080, iptables, nat, working

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
yum install tomcat5...http://myip:8080? edderd Servers & Networking 0 23rd September 2008 06:34 AM
IPTABLES seems to be not working well wshamroukh Servers & Networking 1 2nd March 2007 09:54 AM
Masking port 8080 Darmo Servers & Networking 10 10th June 2005 04:51 PM
Can't connect to apache port 8080 rjbarbour69 Servers & Networking 8 6th April 2005 11:28 PM


Current GMT-time: 03:12 (Wednesday, 19-06-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat