Session 2: Routing and Gateway Configuration

90 minutes; session 2 of 5

Viewing IP Routes with ip route

The ip route command allows viewing and managing IP routing tables. This provides visibility into how traffic flows across networks. This tutorial covers the basics of viewing routes.

Introduction

Understanding routing is key to managing network connectivity. Routes define the pathways for data to travel to destinations. Let’s look at how to view routes.

Steps

Open Terminal

First, open a terminal window on your system.

View Routes

Use this command to view the IP routing table:

ip route show

This will display all configured routes and their details.

Understand Output

The output will contain each destination network, the gateway/interface used to reach it, and other metadata.

Key elements:

  • Destination network - The target subnet for the route.

  • Gateway - The router IP used to reach the destination.

  • Interface - The network interface used to forward packets.

  • Scope - The route scope like global, link, host etc.

Change Routes

Routes can also be added, deleted, and modified using ip route. See other tutorials for examples.

Summary

The ip route show command provides visibility into the IP routing configuration. Viewing routes is essential for understanding network connectivity and traffic flow.

For additional Linux network administration tutorials, contact our experts at any time.

Adding IP Routes with ip route

The ip route add command allows creating new routes in Linux. This provides manual control over network traffic flow. Let’s look at how to add a route.

Introduction

Being able to add custom routes is useful for shaping traffic and managing connectivity. Follow along to see a basic example.

Steps

Open Terminal

First, open a terminal window on your system.

Add Route

Use this command to add a new route:

sudo ip route add <destination> via <gateway>

Where <destination> is the target network and <gateway> is the router IP.

For example:

sudo ip route add 192.168.2.0/24 via 10.0.0.1

View Routes

Check that the new route appears:

ip route show

The route you added should now be listed.

Test Route

Try sending data to the destination to verify routing through the specified gateway:

ping 192.168.2.10

Summary

The ip route add command allows manually inserting new routes into the IP routing table. This is useful for controlling traffic flow for testing or management purposes.

For more Linux network administration tutorials, contact our experts any time. We’re happy to help guide you.

Setting the Default Gateway with ip route

The ip route add default command configures the default gateway in Linux. This provides internet access and routing beyond the local network. Let’s look at how to set the default route.

Introduction

The default gateway is the router used to reach external networks. Setting this correctly is essential for internet connectivity.

Steps

Open Terminal

First, open a terminal window on your system.

Find Gateway IP

Determine the IP address of your router you want to use as the default gateway. Often this is your LAN’s first valid IP.

Set Default Route

Use this command to set the default route:

sudo ip route add default via <gateway_ip>

Replace <gateway_ip> with your actual gateway IP address.

For example:

sudo ip route add default via 192.168.1.1

Test Connectivity

Try reaching a public website to confirm internet access:

ping google.com

This should now succeed through your configured gateway.

Summary

The ip route add default command specifies the default gateway used for external and internet traffic. Configuring this correctly is required for full network connectivity.

For more Linux network administration tutorials, contact our team of experts at any time.

Deleting Routes with ip route del

The ip route del command removes routes from the IP routing table in Linux. This can disable connectivity to specific networks. Let’s look at an example.

Introduction

Deleting routes allows you to manually block or reroute traffic. This can be useful for testing or traffic shaping purposes.

Steps

Open Terminal

First, open a terminal window on your system.

Identify Destination

Determine the route destination you want to remove. For example, let’s use the 192.168.2.0/24 subnet.

Delete Route

Use this command to delete the route:

sudo ip route del 192.168.2.0/24

View Routes

Check that the route no longer appears:

ip route show

The deleted route should be removed from the table.

Test Connectivity

Try pinging an address in the removed subnet. This should now fail due to the missing route.

Summary

The ip route del command removes routes from the IP routing table. This disables connectivity to the specified destinations.

For additional Linux network administration tutorials, our experts are available 24/7 to assist you.