Open In App

How to Turn a Linux Server into a Router to Handle Traffic Statically and Dynamically

Last Updated : 30 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The fundamental unit used to convey information within a network is called a packet, to put it simply. The principles for transmitting data across networks that utilize TCP/IP are the same: the actual information is divided into packets that contain both the data and the address to which it should be transmitted. The act of “guiding” data across a network from source to destination is known as routing. For static routing, a routing table must have a manually established set of rules. These set rules specify a packet’s process when moving from one system to another intelligent routing, often known as dynamic routing, is the path a packet takes can be automatically changed by the system as necessary.

Advanced IP and Network Device Configuration

iproute package

The iproute suite’s main tool is referred to as IP. The fundamental syntax is as follows:

# ip object command
IProute Package

 

Execute the following command to see all the commands that may be used on a certain object:

# ip link help
Commands used on  a certain object

 

Setting up quagga to route IP traffic dynamically

We’ll use the following configuration with two routers for this example.

Connect to Zebra, the logical gateway between the kernel and the router:

# telnet localhost zebra

Connecting to zebra

 

Disabling and enabling a network interface

1. disable and enable eth1

# ip link show
# ip link set eth1 down
# ip link show
Disabling and enabling eth1

 

2. Using a Linux server to route packets between two private networks

In order to route ICMP (ping) packets from dev2 to dev4 and vice versa (note that both client machines are on different networks). Each NIC’s name and associated IPv4 address are provided between square brackets.

Client 1: CentOS 7 [enp0s3: 192.168.0.17/24] – dev1

Client 2: openSUSE 13.2 [enp0s3: 10.0.0.18/24] – dev4

 route packets between two private networks

 

3. Displaying the main routing table

With one of the following three commands, you may inspect your current primary routing table.

# ip route show

# route -n

# netstat -rn

Disabling main routing table

 

4. Using a Linux server to route packages between private networks and the Internet

When you need to share your Internet connection with a private LAN, a Linux computer can also be used as a router.

# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# iptables -A FORWARD -i eth0 -o eth1 -m state –state RELATED,ESTABLISHED -j ACCEPT

# iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

route packages between private networks and the Internet

 

Dynamic Routing with Quagga

Quagga is now the most used by Linux users for dynamic routing. It enables system administrators to provide the same capabilities offered by robust (and expensive) Cisco routers using a Linux server that is reasonably inexpensive. The program alters the kernel routing database as it discovers new, optimal routes for handling packets rather than handling the routing itself. It keeps the same commands and structure as zebra since it is a branch of software whose development was stopped in the past. As a result, zebra will be mentioned frequently moving forward.

Installing Quagga in Linux

Step 1: To install quagga on the distribution of your choice:

# aptitude update && aptitude install quagga

Installing Quagga

 

Step 2: The only distinction is that eth0 is linked to a primary gateway router with IP 192.168.0.1.

# service quagga restart
Starting Quagga service

 

Step 3: Finally, connect again to the zebra service on both routers and note how each one of them has “learned” the route to the network that is behind the other, and which is the next hop to get to that network, by running the command show ip route:

# show ip route
Showing IP route

 

Conclusion:

Using a Linux box router, we have demonstrated how to set up static and dynamic routing in this post. You are free to explore as much as you like and install as many routers as you like.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads