How a Machine Becomes a Router | ip_forward

  Рет қаралды 6,708

Hussein Nasser

Hussein Nasser

Күн бұрын

Recently I learned how the Linux option net.ipv4.ip_forward can turn your machine into a router. I have been using this option in past when working with iptables but never paid attention to how it works. I explore this here.
You see, when your NIC receives a frame from the network with a MAC address the frame is copied to the kernel if the MAC address matches the NIC’s. If doesn’t match the NIC’s MAC address that frame is often dropped by the NIC.
Putting the NIC into promiscuous mode allows all frames in to the OS and the kernel does the filtering instead. This is useful if you have many virtual machines/containers with different MAC addresses exposed under the same physical NIC.
So similarly if the MAC address matches the NIC’s but the IP address in the IP packet doesn’t match machine’s IP, the packet is often dropped by the OS, unless the ip_forward option is enabled.
This essentially tells the OS, hey, you might receive packets that are not for you, please just forward them back through the network and apply any routing rules you might have. Here
This is exactly how a router works, it received tons of packets where the MAC matches it, but almost none of them are destined to the router (except if you want to go to the admin page on your router that is).
Coincidentally, this is also how a firewall works. You configure your hosts to forward all packets to machine F, such that the destinations remain as is but the frame becomes F, the firewall machine receives all packets, apply the filtering rules if those pass it forward the packet back to the network (thanks to the ip_forward) else if the firewall rules didn’t match, it swallows the packet.
This feels like a puzzle piece I have been holding on for a long time and finally fits perfectly.
0:00 Intro
2:00 Layer 2 and Layer 3 Address match
4:00 Layer 2 MAC doesn’t match
5:30 Promiscuous Mode
6:30 Layer 2 Match Layer 3 Address doesn’t
9:00 Acting Like a Router
11:30 Acting Like a Firewall
Discovering Backend Bottlenecks: Unlocking Peak Performance
performance.husseinnasser.com
Fundamentals of Backend Engineering Design patterns udemy course (link redirects to udemy with coupon)
backend.husseinnasser.com
Fundamentals of Networking for Effective Backends udemy course (link redirects to udemy with coupon)
network.husseinnasser.com
Fundamentals of Database Engineering udemy course (link redirects to udemy with coupon)
database.husseinnasser.com
Follow me on Medium
/ membership
Introduction to NGINX (link redirects to udemy with coupon)
nginx.husseinnasser.com
Python on the Backend (link redirects to udemy with coupon)
python.husseinnasser.com
Become a Member on KZfaq
/ @hnasr
Buy me a coffee if you liked this
www.buymeacoffee.com/hnasr
Arabic Software Engineering Channel
/ @husseinnasser
🔥 Members Only Content
• Members-only videos
🏭 Backend Engineering Videos in Order
backend.husseinnasser.com
💾 Database Engineering Videos
• Database Engineering
🎙️Listen to the Backend Engineering Podcast
husseinnasser.com/podcast
Gears and tools used on the Channel (affiliates)
🖼️ Slides and Thumbnail Design
Canva
partner.canva.com/c/2766475/6...
Stay Awesome,
Hussein

Пікірлер: 19
@hnasr
@hnasr 6 ай бұрын
Check out my fundamentals of network engineering network.husseinnasser.com
@rafaelmatsumoto
@rafaelmatsumoto 8 күн бұрын
I don't think I have ever used this parameter before, but it's always nice to learn new things in case one day you need it :)
@VishalSharma-jy7yw
@VishalSharma-jy7yw 6 ай бұрын
Watched your all courses and still wait for your new videos, so I can learn from you. Not because I have hunger to learn, because you know how to feed knowledge even to a not hungry person.❤
@reedzaman6075
@reedzaman6075 6 ай бұрын
I'm currently working with aviation router technologies in my job. This video popping up really made me happy. 🙂
@ayush612
@ayush612 6 ай бұрын
Wow Hussein, you are doing an amazing work sir, These concepts are insightful for someone who always uses these and never understand whats going under the hood. Thanks a ton!
@gillfromamritsar
@gillfromamritsar 6 ай бұрын
no need to appologies, life is not always same :) , good to see you!, really missing those crash courses and deep analysis videos!
@charliesta.abc123
@charliesta.abc123 6 ай бұрын
Good to see you man!
@nagendradevara1
@nagendradevara1 6 ай бұрын
you are a software craftsman 👨‍💻
@johnpulawski35
@johnpulawski35 Ай бұрын
nice to see you
@krishnachaitanya4822
@krishnachaitanya4822 4 ай бұрын
Yup. Had to enable this one to let my LXD containers and VMs have internet access.
@robertstewart9325
@robertstewart9325 6 ай бұрын
Maybe I misunderstand your statement that a frame is only copied to the kernel if it matches the NIC address, or maybe I misunderstand Linux bridging. Wouldn't all frames enter the kernel on a Linux bridge? My Linux bridges aren't promisc either.
@franciscopena7859
@franciscopena7859 6 ай бұрын
2:58 AFAIK this shouldn't be true today with switches, they send the the package only for the intended destination. Which wasn't the case in ethernet hubs (never seen one lmao). But the issue is you can spoof the destination if you answer the ARP broadcasts. Wifi it still applies. Need to test this later with promiscuous mode. My lab is offline rn so kinda hard to do
@mohammedabdulbary1577
@mohammedabdulbary1577 6 ай бұрын
If we are on the same network, sending a packet will get to the firewall machine, and the firewall machine will forward it back to the network if it passes some criteria, my questions is, you said that when we send a packet to the network everyone will receive the packet, in this case the other device(the real destination ) will receive this packet in the same time the firewall does, so does that makes the firewall useless?
@robertstewart9325
@robertstewart9325 6 ай бұрын
Depends on what you mean by worthless. Assuming you meant the firewall is a NAT router or similar then it's not used or needed. If two devices are on the same LAN then ARP will take care of it and the router isn't doing anything.
@mrstatler
@mrstatler Ай бұрын
It's confusing... has the firewall only one network interface or it's just to explain the idea?
@panosangel2883
@panosangel2883 28 күн бұрын
Is there any drawback when this flag is enabled?
@quickmemebyte
@quickmemebyte 6 ай бұрын
routers aren't machines?
@savingday
@savingday 6 ай бұрын
We are hijabis, the men and boys in our house would notify us when someone's at the door so that we get something to throw on our head or we just go to our room
@comoyun
@comoyun 6 ай бұрын
yes
Is there a Limit to Number of Connections a Backend can handle?
18:43
Hussein Nasser
Рет қаралды 32 М.
How DNS and DHCP Servers Communicate (With wireshark)
29:40
Hussein Nasser
Рет қаралды 14 М.
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 29 МЛН
WORLD'S SHORTEST WOMAN
00:58
Stokes Twins
Рет қаралды 127 МЛН
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 91 МЛН
ПРОВЕРИЛ АРБУЗЫ #shorts
00:34
Паша Осадчий
Рет қаралды 7 МЛН
The effect of Random UUID on database performance
18:51
Hussein Nasser
Рет қаралды 69 М.
The Cost of Memory Fragmentation
38:19
Hussein Nasser
Рет қаралды 7 М.
How Computers Talk
2:48
existnchill
Рет қаралды 91
Network Address Translation - NAT Explained
21:28
Hussein Nasser
Рет қаралды 60 М.
They Enabled Postgres Partitioning and their Backend fell apart
31:52
Hussein Nasser
Рет қаралды 39 М.
Mind-Blowing Electroplating on Huge 3D Prints
10:41
HEN3DRIK - Electroplating 3D Prints
Рет қаралды 31 М.
Why The Windows Phone Failed
24:08
Apple Explained
Рет қаралды 243 М.
Address Resolution Protocol - ARP
14:22
Hussein Nasser
Рет қаралды 10 М.
WebTransport is a Game Changer Protocol
14:23
Hussein Nasser
Рет қаралды 53 М.
Looks very comfortable. #leddisplay #ledscreen #ledwall #eagerled
0:19
LED Screen Factory-EagerLED
Рет қаралды 12 МЛН
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 29 МЛН
Ba Travel Smart Phone Charger
0:42
Tech Official
Рет қаралды 1,2 МЛН
Vision Pro наконец-то доработали! Но не Apple!
0:40
ÉЖИ АКСЁНОВ
Рет қаралды 453 М.