LinuxQuestions.org
Help answer threads with 0 replies.
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 01-30-2024, 04:52 AM   #1
ario
Member
 
Registered: Nov 2010
Posts: 65

Rep: Reputation: 2
IPTables redirect rule works on amazon linux, not on debian


Hi Folks,
I have a server that listens on port 20001.
I want port 80 to be redirected to port 20001.
I have an amazon linux 2 on an instance and set a redirect rule on it using command:
Code:
    sudo iptables \
        -t nat \
        -A PREROUTING \
        -p tcp \
        --dport 80 \
        -j REDIRECT \
        --to-ports 20001
And it works. I can curl both port 80 and port 20001. I can also see it as:
Code:
13     121  5868 REDIRECT   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 redir ports 20001

Now on another instance with is debian 12 I run the same command and I have:
Code:
12       0     0 REDIRECT   6    --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 redir ports 20001
Notice that protocol tcp is now shown as number 6!
The rule does not work. I can curl port 20001, but I cannot curl port 80.
On the amazon linux instance (the one which works), I also have docker installed and thus:
Code:
1    3868K  229M DOCKER     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL
Can that be related?
Please help. Thanks in advance.

Last edited by ario; 01-30-2024 at 04:54 AM.
 
Old 01-30-2024, 06:02 AM   #2
ario
Member
 
Registered: Nov 2010
Posts: 65

Original Poster
Rep: Reputation: 2
While deleting old rules and making sure IPtable is clean, tried also:
Code:
iptables -t nat -I PREROUTING --src 0/0 --dst 127.0.0.1 -p tcp --dport 80 -j REDIRECT --to-ports 8080
Didn't work. Any ideas?
 
Old 01-31-2024, 03:54 AM   #3
ario
Member
 
Registered: Nov 2010
Posts: 65

Original Poster
Rep: Reputation: 2
None of the solutions on the internet worked for iptables. I have tried various combinations of chains, targets, etc. etc. Even tried tampering with systemctl:
Code:
sysctl net.ipv4.conf.all.route_localnet=1
None worked.

The only solution was this one line command:
Code:
sudo socat TCP-LISTEN:80,fork TCP:127.0.0.1:23012
 
  


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
[SOLVED] why iptables redirect rule jumps to 127.0.0.1? huria_heep Slackware 4 08-25-2020 11:47 AM
Amazon releases it version of Linux: Amazon Linux 2 JockVSJock General 6 01-08-2018 08:29 PM
Amazon Linux AMI(Amazon Machine Image) - ec2 server - query about pem file unclesamcrazy Linux - Newbie 11 11-27-2014 04:31 PM
iptables: rule with RETURN target just after a rule with ACCEPT target Nerox Linux - Networking 6 09-04-2011 03:33 PM
[SOLVED] Snort - DynamicPlugin: Rule [##] not enabled in configuration, rule will not be used mhollis Linux - Software 3 08-29-2011 06:06 PM

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

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