Skip to main content
In this article, we explore essential networking concepts from a Linux perspective that are fundamental for configuring Kubernetes environments. We will cover topics such as switching, routing, gateways, DNS, network namespaces, and Docker networking. This guide targets both system administrators and application developers. If you are already confident with Linux networking, feel free to jump ahead to the Kubernetes-focused sections.
The image lists networking prerequisites, including switching, routing, DNS configurations, network namespaces, and Docker networking.

Basic Networking Concepts

Network Interfaces and Switching

Consider two systems—labeled A and B—that could be laptops, desktops, or virtual machines. To enable communication between them, each system must be connected to a switch with its respective network interface (either physical or virtual). To list available interfaces on a Linux host, execute:
A sample output might be:
Assuming these systems belong to the network 192.168.1.0, you can assign IP addresses using the following command:
After configuration, test connectivity by pinging another host within the same network:
A successful ping might look like:

Routing Between Subnets

Now, consider a second network, such as 192.168.2.0, with hosts assigned IPs like 192.168.2.10 and 192.168.2.11. For communication between these two networks, a router is necessary. A router interconnects two or more networks and holds an IP address in each network—e.g., 192.168.1.1 for the first network and 192.168.2.1 for the second. When a system on network 192.168.1.0 (say, with IP 192.168.1.11) needs to communicate with a system on network 192.168.2.0, it forwards packets to the router.
The image illustrates a network routing diagram with devices A, B, C, and D connected through two subnets, 192.168.1.0 and 192.168.2.0, via a central router.
Each system must be configured with a gateway or specific route entries to ensure that packets reach the intended destination. To view the current routing table, use:
Initially, communication will be limited to the same subnet. To route traffic destined for 192.168.2.0 via the router (with IP 192.168.1.1), add the following route:
After adding the route, verifying the routing table should show an entry similar to:
If a return route is required (for instance, for a host in network 192.168.2.0 to reach a host in 192.168.1.0), add the appropriate route on that system using its corresponding gateway (e.g., 192.168.2.1).

Configuring Default Routes for Internet Access

To enable internet access (such as reaching external hosts like 172.217.194.0), configure the router as the default gateway. This is done by adding a default route:
Afterward, your routing table might resemble the following:
The “default” or “0.0.0.0” entry indicates that any destination not explicitly listed in the routing table will be directed through the specified gateway.
For scenarios involving multiple routers—such as one handling internet traffic and another managing internal networks—ensure each network has its specific routing entry along with a default route for all other traffic. For example, to route traffic to network 192.168.1.0 via an alternative gateway (192.168.2.2), use:
The updated routing table should include:
If you encounter internet connectivity issues, reviewing the routing table and default gateway configuration is a good troubleshooting practice.

Configuring a Linux Host as a Router

Consider a scenario with three hosts (A, B, and C) where host B connects to two subnets (192.168.1.x and 192.168.2.x) using two interfaces. For example:
  • Host A: 192.168.1.5
  • Host B: 192.168.1.6 and 192.168.2.6
  • Host C: 192.168.2.5
For host A to communicate with host C, host A must direct traffic aimed at network 192.168.2.0 to host B. On host A, execute:
Similarly, host C needs a route for the 192.168.1.0 network via host B (using 192.168.2.6 as the gateway):
Once these routes are established, the “network unreachable” error should no longer occur when pinging between host A and host C.

Enabling IP Forwarding on Linux

Even with the correct routing table, Linux does not forward packets between interfaces by default, as a security measure. This setting is controlled by the IP forwarding parameter in /proc/sys/net/ipv4/ip_forward. To check the IP forwarding status, run:
A return value of 0 indicates that packet forwarding is disabled. To enable forwarding temporarily, run:
Verifying again should now show:
with the output:
To ensure this setting persists across reboots, modify /etc/sysctl.conf and add or update the following line:
Modifying /etc/sysctl.conf ensures that IP forwarding remains enabled even after a system restart.

Summary of Key Commands

Below is a summary table of essential commands covered in this article: Remember, changes made with these commands are temporary and will be reset upon reboot unless they are saved in the appropriate configuration files.
That concludes this article. In the next installment, we will dive into DNS configurations and further enhance your understanding of Kubernetes networking. For additional details and further reading, refer to resources like Kubernetes Documentation and Docker Hub.

Watch Video