Program for IP Forwarding Table Lookup
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
There exists a routing table in the Unix operating system consisting of several tuples that contain the I.P. (Internet Protocol) address of the network, the subnet mask, the IP address of the gateway, and the name of the interface.
This information is required for forwarding packets to the exterior of the network for connecting to the internet. In this article, we shall have a look at how a computer system takes a sequence of decisions when packets need to be forwarded.
Introduction
There exist the following two different methods of delivering IP datagrams:
Routing
Involves finding and setting up routing tables.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Forwarding
Involves passing a packet from an input interface to an output interface.
The process of forwarding must be executed as quickly as possible. On routers, forwarding is done often with hardware support. On personal computer systems, it is performed in the kernel of the machine’s operating system.
Example of IP Forwarding Lookup Table
Let us have a look at a sample IP forwarding lookup table for a clearer understanding. Assume there exists a packet having source IP address “20.129.0.1”. Its routing table may look something like the following:
| Network IP address | Subnet mask | Gateway IP address | Interface name |
|---|---|---|---|
| 200.200.16.0 | 255.255.248.0 | 192.13.2.55 | eth4 |
| 20.128.0.0 | 255.128.0.0 | 12.1.1.1 | eth1 |
| 200.200.200.0 | 255.255.248.0 | 192.13.2.55 | eth4 |
| 0.0.0.0 | 0.0.0.0 | 12.23.44.1 | eth9 |
We shall refer to this system as well as the table above in the article later.
Turn Learning into Career Growth
Working of IP Forwarding Lookup Table
When a packet is sent to the kernel of the operating system in order to find the interface and gateway, the first thing that is done is a bitwise AND operation individually with each subnet mask entry in the table for finding the longest prefix match. After obtaining the desired bitwise AND operation result, it’s then compared with the IP addresses of the network.
The result now produced is the IP address corresponding to the gateway, as well as the name of the interface via which the packet may now go out. “00010100.10000001.00000000.00000001” is the binary representation of “20.129.0.1”. A bitwise AND operation is performed upon this value with the subnet mask of each entry in our table.
The subnet mask from entry 2 (20.128.0.0, 255.128.0.0, 12.1.1.1, eth1) yields the longest matching prefix for our packet. Therefore, our packet goes out from the interface eth1 and selects the gateway 12.1.1.1 for forwarding.
Implementation of IP Forwarding Lookup Table
Following is a C program that implements an IP forwarding lookup table
Conclusion
- There exists a routing table In the Unix operating system consisting of several tuples that contain the I.P. (Internet Protocol) address of the network, the subnet mask, the IP address of the gateway, and the name of the interface.
- There exist two different methods of delivering IP datagrams: Routing and Forwarding.
- When a packet is sent to the kernel of the operating system in order to find the interface and gateway, the first thing that is done is a bitwise AND operation individually with each subnet mask entry in the table for finding the longest prefix match.