Port forwarding with NAT and iptables (transparent proxying) - “Run” your webapp on port 80
Vložit
- čas přidán 9. 07. 2024
- 💻 More software engineering videos • Software Engineering b...
We have written countless web apps on this channel, but most of them pretty much always run port 8080 or 3000 or some ugly ports. In this video we will learn how to make our app run on port 80 or at least seem to be running on port 80.
Running your web app whether nodejs or python on port 80 require root access which is always a bad idea. So better way is to use a reverse proxy like nginx or do DNAT like what we will do in this video.
*** Forward packet from one port to another
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.254.47:8080
*** To clean the NAT table
sudo iptables -t nat -F
*** To Masquerade in case you want to forward to another ip address
sudo iptables -t nat -A POSTROUTING -p tcp --dport 80 -j MASQUERADE
0:00 Intro
2:00 Port forward routing
2:20 nginx
3:00 NAT
Stay Awesome!
Hussein - Věda a technologie
If you want to learn more about the power of iptables checkout this video here iptables Demystified - Port Redirection and Forwarding HTTP Traffic to another machine (part 1)
czcams.com/video/NAdJojxENEU/video.html
Very nice explanation! It was actually easier than I expected it to be.
You are a saviour! No one explained me this shit on the fucking internet, people running on sudo n shit
Thanks man 😅 You saved my brain
Thank you Hussein, really nice way of explaining you've got. Keep going !
Dude, these videos are amazing! Thank you 🙏 for this great content!
this channel is a gem thank you so much!
This channel is like a hidden gem! I'm glad I found this.
Thank you for your tutorial Hussein
Thanks for the magical forwarding command!! I've been reading a lot to launch my home server behind a CG-NAT connection. I finally made it with that command! Using a Lightsail instance with OpenVPN and a virtual machine I can now run my home serving for testing my web apps.
nicozica so awesome! Thanks for sharing glad it works
Amazing Hussein!, thank your for the tutorial
Your welcome Risardi!! Glad you enjoyed this video :) cheers
well explained thank you !
Good videos! informative and easy to follow
timska thank you 🙏
That worked...thanks.
works like a charm, thanks man
Glad I could help!! Thanks for commenting
Thank you. After searching about 15 written tutorials, I found your video. The written tutorials don't seem to address something simple like this. I wanted to use non-standard ports that are exposed to the public, and then forward to default ports in my server.
Glad it worked Dave!
Thank you for your awesome content i enjoy each video of yours love your accent and the way you explain things
love from israel
Thanks for your comment! Your the first who likes my accent haha cheers and have a great weekend
Hi Hussein.. I have follow all this steps you have mentioned in the video on my EC2 instance on AWS... I already ensured that port forwarding is enabled.....but still request is not forwarding to port 8080 from 80....please help
can we use this method to redirect port 443 to another port? I tried but it didn't work.
if my university blocks range of ports does this actually help? I am not a software engineer but I am trying to setup my pivpn the best way for me.
can u help me i'm building my own infrastructure pointing to my own home server, does anyone know how to
open ports to the internet on a 02 router?, i only get http port 80 from my server when i open port to the internet but no connection through https por 443 ? , i need to open my ubuntu server from proxmox to the internet and https need to work but i run into problems
With this iptables setup, your server would be online too?
Hey, sorry maybe I misunderstood, but this example only works if you can send your request directly to the machine. How is it configured if the router is port forwarding back? Or rather how does it work on 80 from a public side request?
Hey! if you want to port forwards the router to an internal host than you can simply provide do that like here czcams.com/video/92b-jjBURkw/video.html
With this simply we can get a cheap digital ocean instance and fwd the Nextcloud traffic via WireGuard to our powerful home server. It’s amazing.
Hussein, why do we need to do this in the first place? Why not let users access our app on port 8080? Why 80?
if you don't know the ip addr of the machine, just do this > sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080 # 8080 -> 8080
Hi Thanks for this awesome tutorial
I was wondering if you can help me how to display my raspberry pi iptables in my nodejs api?
thanks in advance
Sure! The idea is to execute a command on linux from nodejs and get the output and iptables is just a command.
Check the answer here hope that helps. Careful im not sure if iptables required root, if it does than nodejs will need to be root as well which is not a good idea
stackoverflow.com/questions/12941083/execute-and-get-the-output-of-a-shell-command-in-node-js
With this command can I run app on 443 port
Yes you can and redirect it to anyport you want
sir i dont get the need of this why are we doing this cant we just use reverse proxy that will redirect us to port 80
and if you see my question can you tell me are we exposing our 8080 port to 80 port
I am getting confuse
It will mean a lot if you tell me the doubt
New to networking kid
You don't have to use it, its just in cases where it is not possible to listen on port 80 for security reason (any thing less than 1024 must run with high permissions) .. so you use iptables instaed
@@hnasr sir i was not expecting your answer that fast
Thank you very much
Any thing you will suggest me other that your network engineeriing video for network
Thank uou once again
Heheheh i am being selfish🤗🤩
@@arunteltia7888 sorry if this will not help you but this is the best place to learn about all the nitty-gritty of backend engineering,
@@ahmedboutaraa8771 yes I completely agree with you I learned so much from this channel in 3 months
I am glad I found this channel