How a Machine Becomes a Router | ip_forward

Hussein Nasser January 24, 2024
Video Thumbnail
Hussein Nasser Logo

Hussein Nasser

@hnasr

About

Join me as we discuss various software engineering topics with examples and add fun elements to them. We always try to learn by example here in this educational Youtube channel which we believe is the right way to learn. I love Software engineering (especially the backend) and I strive to be a better software engineer every day. Join me on this journey and let us learn together. All opinions, suggestions, and tips I provide in all of this channel's content are my own. Information provided is for educational purposes only. Consider becoming a member to support the channel https://www.youtube.com/channel/UC_ML5xP23TOWKUcc-oAE_Eg/join Check out my courses https://courses.husseinnasser.com Stay awesome! Hussein Nasser, http://www.husseinnasser.com Feel free to shoot me an email [email protected] twitter: @hnasr

Video Description

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 https://performance.husseinnasser.com Fundamentals of Backend Engineering Design patterns udemy course (link redirects to udemy with coupon) https://backend.husseinnasser.com Fundamentals of Networking for Effective Backends udemy course (link redirects to udemy with coupon) https://network.husseinnasser.com Fundamentals of Database Engineering udemy course (link redirects to udemy with coupon) https://database.husseinnasser.com Follow me on Medium https://medium.com/@hnasr/membership Introduction to NGINX (link redirects to udemy with coupon) https://nginx.husseinnasser.com Python on the Backend (link redirects to udemy with coupon) https://python.husseinnasser.com Become a Member on YouTube https://www.youtube.com/channel/UC_ML5xP23TOWKUcc-oAE_Eg/join Buy me a coffee if you liked this https://www.buymeacoffee.com/hnasr Arabic Software Engineering Channel https://www.youtube.com/channel/UChWZsjdoRvZ0T9QWZOD6UpA 🔥 Members Only Content https://www.youtube.com/playlist?list=UUMO_ML5xP23TOWKUcc-oAE_Eg 🏭 Backend Engineering Videos in Order https://backend.husseinnasser.com 💾 Database Engineering Videos https://www.youtube.com/playlist?list=PLQnljOFTspQXjD0HOzN7P2tgzu7scWpl2 🎙️Listen to the Backend Engineering Podcast https://husseinnasser.com/podcast Gears and tools used on the Channel (affiliates) 🖼️ Slides and Thumbnail Design Canva https://partner.canva.com/c/2766475/647168/10068 Stay Awesome, Hussein

Boost Networking Skills Today

AI-recommended products based on this video

Loading...
TP-Link AC1300 USB WiFi Adapter (Archer T3U) - 2.4G/5G Dual Band Wireless Network Adapter for PC Desktop, MU-MIMO WiFi Dongle, USB 3.0, Supports Windows 11/10/8.1/8/7/XP, Mac OS 10.9-10.14

TP-Link AC1300 USB WiFi Adapter (Archer T3U) - 2.4G/5G Dual Band Wireless Network Adapter for PC Desktop, MU-MIMO WiFi Dongle, USB 3.0, Supports Windows 11/10/8.1/8/7/XP, Mac OS 10.9-10.14

(19,238)
$19.99$15.96
FREE delivery Sun, Jun 22 on your first order
500+ bought in past month
Loading...
TP-Link WiFi 6 AX3000 PCIe WiFi Card Archer TX55E - Bluetooth 5.2, 802.11AX Dual Band Wireless Adapter with MU-MIMO, OFDMA, Ultra-Low Latency, Supports Windows 11, 10 (64bit) only
Best Seller

TP-Link WiFi 6 AX3000 PCIe WiFi Card Archer TX55E - Bluetooth 5.2, 802.11AX Dual Band Wireless Adapter with MU-MIMO, OFDMA, Ultra-Low Latency, Supports Windows 11, 10 (64bit) only

(9,902)
$37.99$34.19
FREE delivery Sun, Jun 22
400+ bought in past month
Loading...
TP-Link AC1300 High Gain WiFi USB Adapter (Archer T4U)- Dual Band Wireless Network Adapter for Desktop with 2.4GHz/5GHz High Gain Antennas, MU-MIMO, Support Windows 10/8.1/8/7/XP, Mac OS

TP-Link AC1300 High Gain WiFi USB Adapter (Archer T4U)- Dual Band Wireless Network Adapter for Desktop with 2.4GHz/5GHz High Gain Antennas, MU-MIMO, Support Windows 10/8.1/8/7/XP, Mac OS

(47,080)
$24.99$21.17
FREE delivery Sun, Jun 22 on your first order
100+ bought in past month
Loading...
TP-Link Mini - AC600 USB 2.0 Wifi Adapter (Archer T2U Nano) - 2.4G/5G Dual Band Wireless Network Adapter for PC Desktop, Mini Travel Size, Supports Windows 11/10/8.1/8/7/XP, Mac OS 10.9-10.15

TP-Link Mini - AC600 USB 2.0 Wifi Adapter (Archer T2U Nano) - 2.4G/5G Dual Band Wireless Network Adapter for PC Desktop, Mini Travel Size, Supports Windows 11/10/8.1/8/7/XP, Mac OS 10.9-10.15

(19,191)
$14.99$13.52
FREE delivery Thu, Sep 4 on your first order
300+ bought in past month
Loading...
TP-Link Omada AC1750 Gigabit Wireless Access Point (EAP245 V3) - Business WiFi Solution w/Mesh Support, Seamless Roaming & MU-MIMO, PoE Powered, SDN Integrated, Cloud Access & Omada App, White

TP-Link Omada AC1750 Gigabit Wireless Access Point (EAP245 V3) - Business WiFi Solution w/Mesh Support, Seamless Roaming & MU-MIMO, PoE Powered, SDN Integrated, Cloud Access & Omada App, White

(5,094)
$79.99$72.87
FREE delivery Thu, Sep 4
100+ bought in past month
Loading...
TP-Link EAP225-Outdoor | Omada AC1200 Wireless Gigabit Outdoor Access Point | Business WiFi Solution w/ Mesh Support, Seamless Roaming & MU-MIMO | PoE Powered | SDN Integrated | Cloud Access & App White
Best Seller

TP-Link EAP225-Outdoor | Omada AC1200 Wireless Gigabit Outdoor Access Point | Business WiFi Solution w/ Mesh Support, Seamless Roaming & MU-MIMO | PoE Powered | SDN Integrated | Cloud Access & App White

(5,267)
$79.99$63.99
PrimeFREE delivery Sat, Jun 14
500+ bought in past month
Loading...
D-Link AC1300 USB WiFi Adapter | 2.4/5GHz Dual Band Wireless Internet Travel Size for Desktop PC Laptop | MU-MIMO Plug & Play | Supports Windows 10/11 Drivers | WPA3 Enhanced Security (AC13U-CA)

D-Link AC1300 USB WiFi Adapter | 2.4/5GHz Dual Band Wireless Internet Travel Size for Desktop PC Laptop | MU-MIMO Plug & Play | Supports Windows 10/11 Drivers | WPA3 Enhanced Security (AC13U-CA)

(1,357)
$22.49
FREE delivery Sun, Jun 22 on your first order
Loading...
D-Link AC1300 MU-MIMO Wi-Fi Nano USB Adapter, Ultra-Mini (20.2mm x 14.9mm) Dual Band 2.4G/5G Wireless Adapter for PC or Laptop, Plug and Play, Easy Install, Upgrade your WiFi (DWA-181)

D-Link AC1300 MU-MIMO Wi-Fi Nano USB Adapter, Ultra-Mini (20.2mm x 14.9mm) Dual Band 2.4G/5G Wireless Adapter for PC or Laptop, Plug and Play, Easy Install, Upgrade your WiFi (DWA-181)

(1,628)
$24.99
FREE delivery Sun, Jun 22 on your first order
Loading...
TP-Link 5 Port Gigabit Ethernet Network Switch (TL-SG1005D) - Plug and Play, Desktop or Wall Mount, Plastic Case, Ethernet Splitter, Fanless, Traffic Optimization, Unmanaged (TL-SG1005D)

TP-Link 5 Port Gigabit Ethernet Network Switch (TL-SG1005D) - Plug and Play, Desktop or Wall Mount, Plastic Case, Ethernet Splitter, Fanless, Traffic Optimization, Unmanaged (TL-SG1005D)

(21,445)
$14.99$13.49
FREE delivery Thu, Sep 4 on your first order
100+ bought in past month
Loading...
TP-Link USB to Ethernet Adapter (UE306) - Foldable USB 3.0 to Gigabit Ethernet LAN Laptop Network Adapter, Supports Nintendo Switch, Windows, Linux, Apple MacBook OS 10.11- OS 12, Surface

TP-Link USB to Ethernet Adapter (UE306) - Foldable USB 3.0 to Gigabit Ethernet LAN Laptop Network Adapter, Supports Nintendo Switch, Windows, Linux, Apple MacBook OS 10.11- OS 12, Surface

(11,241)
$13.97$9.43
FREE delivery Sun, Jun 22 on your first order
500+ bought in past month
Loading...
TP-Link Omada AC1750 Gigabit Wireless Access Point (EAP245 V3) - Business WiFi Solution w/Mesh Support, Seamless Roaming & MU-MIMO, PoE Powered, SDN Integrated, Cloud Access & Omada App, White

TP-Link Omada AC1750 Gigabit Wireless Access Point (EAP245 V3) - Business WiFi Solution w/Mesh Support, Seamless Roaming & MU-MIMO, PoE Powered, SDN Integrated, Cloud Access & Omada App, White

(5,094)
$79.99$72.87
FREE delivery Thu, Sep 4
100+ bought in past month
Loading...
TP-Link EAP225-Outdoor | Omada AC1200 Wireless Gigabit Outdoor Access Point | Business WiFi Solution w/ Mesh Support, Seamless Roaming & MU-MIMO | PoE Powered | SDN Integrated | Cloud Access & App White
Best Seller

TP-Link EAP225-Outdoor | Omada AC1200 Wireless Gigabit Outdoor Access Point | Business WiFi Solution w/ Mesh Support, Seamless Roaming & MU-MIMO | PoE Powered | SDN Integrated | Cloud Access & App White

(5,267)
$79.99$63.99
PrimeFREE delivery Sat, Jun 14
500+ bought in past month
Loading...
TP-Link AX1500 WiFi 6 Travel Router (TL-WR1502X) – Pocket-Sized, Dual-Band, USB-C Powered, VPN Support (OpenVPN/WireGuard), USB Tethering, Gigabit Ports, Multi-Mode, Hotel & Travel Ready

TP-Link AX1500 WiFi 6 Travel Router (TL-WR1502X) – Pocket-Sized, Dual-Band, USB-C Powered, VPN Support (OpenVPN/WireGuard), USB Tethering, Gigabit Ports, Multi-Mode, Hotel & Travel Ready

(4,882)
$44.97$35.98
FREE delivery Sun, Jun 22
300+ bought in past month
Loading...
TP-Link Dual-Band WiFi 6 AX3000 Travel Router (TL-WR3002X) – Pocket-Sized, Multi-Gig, OpenVPN, WireGuard, USB 3.0, Phone Tethering, Public WiFi Sharing, Hotel/Cruise Ready, Multi-Mode

TP-Link Dual-Band WiFi 6 AX3000 Travel Router (TL-WR3002X) – Pocket-Sized, Multi-Gig, OpenVPN, WireGuard, USB 3.0, Phone Tethering, Public WiFi Sharing, Hotel/Cruise Ready, Multi-Mode

(126)
$89.99$83.69
FREE delivery Sun, Jun 22
200+ bought in past month
Loading...
TP-Link Deco AX1800 WiFi 6 Mesh System (Deco X20) - Covers up to 5,800 Sq. Ft., Replaces Wireless Internet Routers and Extenders, 6 Ethernet Ports in Total, Supports Ethernet Backhaul, 3-Pack

TP-Link Deco AX1800 WiFi 6 Mesh System (Deco X20) - Covers up to 5,800 Sq. Ft., Replaces Wireless Internet Routers and Extenders, 6 Ethernet Ports in Total, Supports Ethernet Backhaul, 3-Pack

(16,541)
$199.99$153.53
FREE delivery Thu, Sep 4
100+ bought in past month
Loading...
10.1 Inch Touch Portable Monitor IPS Screen 1366x768P 60Hz 400 Brightness 99% sRGB HDMI USB-C Monitors Switch for Xbox PS3/4/5 Laptop Compatible with Raspberry Pi, Mini Touch Screen

10.1 Inch Touch Portable Monitor IPS Screen 1366x768P 60Hz 400 Brightness 99% sRGB HDMI USB-C Monitors Switch for Xbox PS3/4/5 Laptop Compatible with Raspberry Pi, Mini Touch Screen

(1)
$99.99
FREE delivery Mon, Aug 11
Loading...
ELECROW 8 Inch Portable Monitor, 1280x800 Mini HD Display with Built-in Speakers, USB Powered, Non-Touch LCD Screen for Raspberry Pi, PC, Laptop, Jetson Nano, Game Consoles

ELECROW 8 Inch Portable Monitor, 1280x800 Mini HD Display with Built-in Speakers, USB Powered, Non-Touch LCD Screen for Raspberry Pi, PC, Laptop, Jetson Nano, Game Consoles

(49)
$117.29$102.21
$6.86 delivery Thu, Aug 14
Loading...
7 Inch Portable Monitor Touchscreen HD 1024x600 LED Display Dual HDMI Port Small Monitor for PC Raspberry Pi Laptop Computer Xbox PS4/5 Switch Built-in Speakers

7 Inch Portable Monitor Touchscreen HD 1024x600 LED Display Dual HDMI Port Small Monitor for PC Raspberry Pi Laptop Computer Xbox PS4/5 Switch Built-in Speakers

(61)
$68.99
FREE delivery Tue, Aug 12
Loading...
BrosTrend 1800Mbps WiFi 6 Linux WiFi Adapter for PC and Raspberry Pi 2+, Long Range USB WiFi Dongle Linux for Ubuntu, Mint, Debian, Kubuntu, Lubuntu, Zorin, Windows 11/10, Dual Band Wireless Antenna

BrosTrend 1800Mbps WiFi 6 Linux WiFi Adapter for PC and Raspberry Pi 2+, Long Range USB WiFi Dongle Linux for Ubuntu, Mint, Debian, Kubuntu, Lubuntu, Zorin, Windows 11/10, Dual Band Wireless Antenna

(288)
$54.14
FREE delivery Sun, Jun 22