LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-31-2013, 10:20 AM   #1
kwstone
LQ Newbie
 
Registered: Jul 2013
Posts: 13

Rep: Reputation: Disabled
iptables redirect prerouting stopped working


I've seen posts on various forums that have similarities to the one I'm experiencing, but not quite the same.

I used the following iptables rule to preroute port 80 to port 8060:

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8060

When I first implemented this one prerouting rule a couple of weeks ago, it worked just fine. Yesterday, the server was shut down for some maintenance and brought up again. The prerouting rule was still in place, but the forwarding from port 80 to 8060 stopped functioning. I can internally reach the application on the server on port 8060 just fine, so it's the prerouting that's failing. I took the time to stop remove the rule, stop and start iptables, add the rule back and save it. It still doesn't work. /var/log/messages reflects that queries are making it to the server, but they're not being forwarded from 80 to 8060.

I've seen some forums that suggest that the ip_forward kernel value should be set to 1. But the fact that this worked initially and that another server with the same setting works (with ip_forward at the default of 0) makes me hesitant to implement the change.

Thanks in advance,
Keith

I have another server that has the same ruleset in place and is working just fine.
 
Old 07-31-2013, 11:41 AM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,334

Rep: Reputation: Disabled
Could it be that the application is bound to a specific IP? I believe REDIRECT causes packets to be redirected to loopback (127.0.0.1).

Does telnet localhost 8060 work?

Is traffic to the lo interface allowed in the iptables rule set?
 
Old 07-31-2013, 11:49 AM   #3
kwstone
LQ Newbie
 
Registered: Jul 2013
Posts: 13

Original Poster
Rep: Reputation: Disabled
Reply to Olmy

Quote:
Originally Posted by Ser Olmy View Post
Could it be that the application is bound to a specific IP? I believe REDIRECT causes packets to be redirected to loopback (127.0.0.1).

Does telnet localhost 8060 work?

Is traffic to the lo interface allowed in the iptables rule set?
telnet localhost 8060 does connect.

I only have the one rule to preroute port 80 requests to port 8060. Up until the system was rebooted yesterday, this was sufficient to make things work as desired. So there's nothing referencing lo. But your question made me check ifconfig, and I just found that my Ethernet interface says eth2, not eth0. I'm not sure if or how that changed, but it looks like the next thing for me to try is change the interface to eth2 in the iptables rule.
 
Old 07-31-2013, 12:20 PM   #4
kwstone
LQ Newbie
 
Registered: Jul 2013
Posts: 13

Original Poster
Rep: Reputation: Disabled
Ser Olmy's suggestion helped me find and solve the problem. I'm not sure how it happened, but doing an ifconfig revealed that the Ethernet interface name changed from eth0 and eth2 between the server being brought down for maintenance and brought up again. When I dropped the rule pertaining to eth0 and inserted a new one using eth2 instead, things started flying again.

Thank you!
 
Old 07-31-2013, 12:24 PM   #5
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 665

Rep: Reputation: Disabled
PLease mark the thread as Solved.
 
  


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
iptables nat prerouting redirect issue - rhel 5.5 64-bit wischad Linux - Networking 1 11-12-2010 08:29 AM
[SOLVED] IPTables port forwarding using prerouting not working blackman890 Linux - Networking 3 02-19-2010 02:33 PM
after new iptables rules proftpd stopped working arty Linux - Server 4 07-01-2009 01:18 AM
iptables PREROUTING chain not working for me illscience Linux - Security 8 01-13-2009 03:54 PM
iptables redirect stopped working hostatonce Linux - Networking 5 09-19-2008 07:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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