Port forwarding with NAT and iptables (transparent proxying) - “Run” your webapp on port 80

Sdílet
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

Komentáře • 43

  • @hnasr
    @hnasr  Před 3 lety

    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

  • @DrSTAHP
    @DrSTAHP Před 3 lety +1

    Very nice explanation! It was actually easier than I expected it to be.

  • @nerdion1911
    @nerdion1911 Před 3 lety

    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

  • @jedi_v
    @jedi_v Před 3 lety +1

    Thank you Hussein, really nice way of explaining you've got. Keep going !

  • @blazed-space
    @blazed-space Před rokem

    Dude, these videos are amazing! Thank you 🙏 for this great content!

  • @AnasHmamouch
    @AnasHmamouch Před 3 lety

    this channel is a gem thank you so much!

  • @debasismandal1924
    @debasismandal1924 Před 4 lety +6

    This channel is like a hidden gem! I'm glad I found this.

  • @nafasm
    @nafasm Před 4 lety +1

    Thank you for your tutorial Hussein

  • @nicozica
    @nicozica Před 4 lety +1

    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.

    • @hnasr
      @hnasr  Před 4 lety +1

      nicozica so awesome! Thanks for sharing glad it works

  • @risardirisardi4556
    @risardirisardi4556 Před 4 lety +2

    Amazing Hussein!, thank your for the tutorial

    • @hnasr
      @hnasr  Před 4 lety

      Your welcome Risardi!! Glad you enjoyed this video :) cheers

  • @synchronizingsynchronize3066

    well explained thank you !

  • @Timska
    @Timska Před 4 lety

    Good videos! informative and easy to follow

    • @hnasr
      @hnasr  Před 4 lety

      timska thank you 🙏

  • @rne1223
    @rne1223 Před 2 lety

    That worked...thanks.

  • @rezzpa
    @rezzpa Před 5 lety

    works like a charm, thanks man

    • @hnasr
      @hnasr  Před 5 lety

      Glad I could help!! Thanks for commenting

  • @davidjdailey
    @davidjdailey Před 4 lety +2

    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.

    • @hnasr
      @hnasr  Před 4 lety

      Glad it worked Dave!

  • @KrizyzZ00
    @KrizyzZ00 Před 4 lety

    Thank you for your awesome content i enjoy each video of yours love your accent and the way you explain things
    love from israel

    • @hnasr
      @hnasr  Před 4 lety +1

      Thanks for your comment! Your the first who likes my accent haha cheers and have a great weekend

  • @keshavbadhekar
    @keshavbadhekar Před 3 lety

    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

  • @ahangk
    @ahangk Před 3 lety

    can we use this method to redirect port 443 to another port? I tried but it didn't work.

  • @ViperrKsa
    @ViperrKsa Před 3 lety

    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.

  • @lopo8000
    @lopo8000 Před 3 lety

    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

  • @Yours--Truly
    @Yours--Truly Před 4 lety

    With this iptables setup, your server would be online too?

  • @MrZerged
    @MrZerged Před 4 lety

    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?

    • @hnasr
      @hnasr  Před 4 lety

      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

  • @Aemilindore
    @Aemilindore Před 3 lety

    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.

  • @TheDEMMX
    @TheDEMMX Před 2 lety

    Hussein, why do we need to do this in the first place? Why not let users access our app on port 8080? Why 80?

  • @jordybayo9374
    @jordybayo9374 Před rokem

    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

  • @ArjayShortClip
    @ArjayShortClip Před 4 lety

    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

    • @hnasr
      @hnasr  Před 4 lety

      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

  • @vikasc325
    @vikasc325 Před 4 lety

    With this command can I run app on 443 port

    • @hnasr
      @hnasr  Před 4 lety

      Yes you can and redirect it to anyport you want

  • @arunteltia7888
    @arunteltia7888 Před 4 lety +1

    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

    • @hnasr
      @hnasr  Před 4 lety +1

      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

    • @arunteltia7888
      @arunteltia7888 Před 4 lety

      @@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🤗🤩

    • @ahmedboutaraa8771
      @ahmedboutaraa8771 Před 3 lety +2

      @@arunteltia7888 sorry if this will not help you but this is the best place to learn about all the nitty-gritty of backend engineering,

    • @arunteltia7888
      @arunteltia7888 Před 3 lety

      @@ahmedboutaraa8771 yes I completely agree with you I learned so much from this channel in 3 months
      I am glad I found this channel