[SOLVED] Trying to Port Forward with iptables to hardware router
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.