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 04-10-2021, 01:03 PM   #1
PROBLEMCHYLD
Senior Member
 
Registered: Apr 2015
Posts: 1,201

Rep: Reputation: Disabled
Trying to Port Forward with iptables to hardware router


I have tried forward chains prerouting and postrouting chains.

I don't want to open up port forwarding on my hardware router because the ports are always open. I want iptables to forward the necessary port 29000 to the hardware router when needed.

How do I allow this?

iptables -t nat -A PREROUTING -d Public IP -p tcp -m tcp --dport 29000 -j DNAT --to-destination 192.168.0.12:29000
iptables -t nat -A PREROUTING -d Public IP -p udp -m udp --dport 29000 -j DNAT --to-destination 192.168.0.12:29000
iptables -A FORWARD -d 192.168.0.12/32 -p tcp -m tcp --dport 29000 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -d 192.168.0.12/32 -p udp -m udp --dport 29000 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.0.12/32 -p tcp -m tcp --sport 29000 -j SNAT --to-source Public IP
iptables -t nat -A POSTROUTING -s 192.168.0.12/32 -p udp -m udp --sport 29000 -j SNAT --to-source Public IP

Last edited by PROBLEMCHYLD; 04-10-2021 at 01:13 PM.
 
Old 04-10-2021, 05:15 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,339

Rep: Reputation: Disabled
Quote:
Originally Posted by PROBLEMCHYLD View Post
I don't want to open up port forwarding on my hardware router because the ports are always open.
I'm sorry, but this doesn't make sense. Is your hardware router not the device with the public IP address?
 
Old 04-10-2021, 05:30 PM   #3
PROBLEMCHYLD
Senior Member
 
Registered: Apr 2015
Posts: 1,201

Original Poster
Rep: Reputation: Disabled
Yes, but if I forward the ports they are always open even when my linux machine is off. I don't want to port forward like this from the router.

Example, if I launch bittorent the ports are forwarded to the router automatically but are closed when the client is closed. I want iptables to do the same thing but with a specific port.
 
Old 04-10-2021, 05:50 PM   #4
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,339

Rep: Reputation: Disabled
Quote:
Originally Posted by PROBLEMCHYLD View Post
Yes, but if I forward the ports they are always open even when my linux machine is off. I don't want to port forward like this from the router.
If your machine is off, nothing is responding to incoming packets for that IP address. That means the router won't be able to forward the packets at all and is forced to drop them, which from the outside looks exactly like a closed or a firewalled port.
Quote:
Originally Posted by PROBLEMCHYLD View Post
Example, if I launch bittorent the ports are forwarded to the router automatically but are closed when the client is closed.
That means both your router and the bittorrent client support the UPNP protocol. And the port is forwarded FROM the router to the PC, not TO the router.
Quote:
Originally Posted by PROBLEMCHYLD View Post
I want iptables to do the same thing but with a specific port.
iptables controls the in-built firewall of the Linux kernel. It knows nothing of UPNP.
 
Old 04-10-2021, 07:27 PM   #5
PROBLEMCHYLD
Senior Member
 
Registered: Apr 2015
Posts: 1,201

Original Poster
Rep: Reputation: Disabled
Thanks, learned something new.
 
  


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] iptables port forward not working for port range mapping to anohter Port range in Linux 2.6.39 kinghong66 Linux - Networking 2 06-17-2015 07:17 PM
Iptables can't port forward (PAT Port address translation) sfrederiksen Linux - Networking 7 12-20-2011 10:47 AM
[SOLVED] Trying to forward RDP Port with in iptables Qiuness Slackware 3 12-20-2011 10:37 AM
If I forward a port in iptables, does the port have to be open on the firewall? qwertyjjj Linux - Server 4 08-06-2009 09:22 AM

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

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