By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
IT Infras HolicIT Infras HolicIT Infras Holic
  • News
  • Linux
    • Application
    • SELinux
    • Centos
    • Ubuntu
  • Docker
  • Web Server
    • Kong
    • Nginx
    • Openlitespeed
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
    • 2048
    • Fantasy Forest
    • Hextris
    • Crossword
Search
  • Privacy Policy
© 2024. All Rights Reserved.
Font ResizerAa
IT Infras HolicIT Infras Holic
Font ResizerAa
  • News
  • Linux
  • Docker
  • Web Server
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
Search
  • News
  • Linux
    • Application
    • SELinux
    • Centos
    • Ubuntu
  • Docker
  • Web Server
    • Kong
    • Nginx
    • Openlitespeed
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
    • 2048
    • Fantasy Forest
    • Hextris
    • Crossword
Follow US
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
IT Infras Holic > Blog > Linux > Centos > Add Delete Route in Linux CentOS 7
CentosLinux

Add Delete Route in Linux CentOS 7

writer
Share
4 Min Read
SHARE

Add Delete Route in Linux CentOS 7

Viewing the existing routing table

Before we embark on adding or deleting routes, it’s prudent to check the existing default routes on a system. To do so, simply launch your terminal and issue the command:

Contents
Add Delete Route in Linux CentOS 7Viewing the existing routing tableAdding a static route using IP commandPermanently adding static route (RHEL, Fedora, CentOS)To add a default route run below ‘ip route add’ command,Permanently adding static route (Ubuntu / Debian)Deleting a static routeTo delete a specific route, use the ip route del command.To delete a single IP route in a subnet run the commandTo delete default route run:
1
ip route show

or

1
ip route list

Similar statistics can be displayed using route command,

1
route -n

Also, you can use the good old netstat  command, which is usually used for printing interface statistics as well as the routing table to achieve the same result.

1
sudo netstat -nr

With the default routing statistics in mind, let’s now move a step further and add some routes to our system.

Adding a static route using IP command

Suppose you want to take a backup of a Linux machine and push the backup file to another backup server in the subnet 10.0.2.0/24. However, for one reason or the other, you cannot reach the backup server  via the default gateway. In this case, you will have to create a new route for backup server subnet via another IP, say 192.168.43.223 via the interface enp0s3.

The command for this will be

1
sudo ip route add 10.0.2.0/24 via 192.168.43.223 dev enp0s3
  • 10.0.2.0      ->             is the network you want to connect to
  • /24              ->             is the subnet mask
  • 192.168.43.223 ->    is the IP through which we will reach the server
  • enp0s3       ->            is the network interface

You can confirm whether new static route add been in route table using “ ip route show ” command.

1
sudo ip route show

To add the specific IP of the backup server, say 10.0.2.15 run the command:

1
sudo ip route add 10.0.2.15 via 192.168.43.223 dev enp0s3

Once again, you can check the routing changes to see if the changes exist using the ip route show command:

1
2
3
ip route show
 
route -n

 

Permanently adding static route (RHEL, Fedora, CentOS)

The routes we have just added are temporary and will not survive a reboot. To make the routes persistent, you need to manually add them.

In the /etc/sysconfig/network-scripts/ directory, create an interface file route-interface where the interface attribute is your network interface name. In our case, this will be route-enp0s3 .

1
vim /etc/sysconfig/network-scripts/route-enps03

Next, we will add  the routes as shown:

10.0.2.0/32 via 192.168.43.1

10.0.2.15 via 192.168.43.1

Save the file and exit. Then restart NetworkManager Service

1
sudo systemctl restart NetworkManager

To add a default route run below ‘ip route add’ command,

1
sudo ip route add default via <ip-address> dev interface
For example:

1
sudo ip route add default via 192.168.43.1 dev eth0

 

Permanently adding static route (Ubuntu / Debian)

For Debian distributions, edit the file /etc/network/interfaces

1
sudo vim /etc/network/interfaces
 

Append the following line:

1
up route add -net 10.0.2.0 netmask 255.255.255.0 gw 192.168.43.1 dev enp0s3
 

Save and exit the file. Finally, for the changes to come into effect, run below commands

1
sudo ifdown enp0s3 && sudo ifup enp0s3
 

Deleting a static route

To delete a specific route, use the ip route del command.

For example, to remove the route address we just added, run the command:

1
sudo ip route del 10.0.2.0/24 via 192.168.43.223 dev enp0s3
 

To delete a single IP route in a subnet run the command

1
sudo ip route del 10.0.2.15 via 192.168.43.223 dev enp0s3
 

To delete default route run:

 
1
sudo ip route del default
 

We hope that this tutorial was informative and provided you with insights into how you can go about adding and deleting static route in Linux CentOS 7. Thank you for reading

You Might Also Like

Monitoring File & Directory Changes using Bash Script

Vulnerability Checker CVE-2024-3094

Unleashing the Potential of Knowledge Management with Wiki.js

How to Install Apache Guacamole with Docker Compose

Unlocking Seamless Remote Access: Exploring the Power of Apache Guacamole

TAGGED: centos, centos7, network, route
Share This Article
Facebook Twitter Whatsapp Whatsapp LinkedIn Telegram Copy Link
Previous Article add route in windows How to Add Route in Windows
Next Article backup restore mysql database Backup Restore MySQL Database
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest News

bash
Monitoring File & Directory Changes using Bash Script
Linux Application
vulnerability
Vulnerability Checker CVE-2024-3094
Linux
wiki.js
Unleashing the Potential of Knowledge Management with Wiki.js
Application Linux
Install Apache Guacamole
How to Install Apache Guacamole with Docker Compose
Application Linux

You Might also Like

How to Install Cyberpanel on Ubuntu 22.04
OpenlitespeedUbuntuWeb Server

Install Cyberpanel on Ubuntu 22.04

8 Min Read
How to map SFTP as a drive on Windows 10
LinuxWindows

How to map SFTP as a drive on Windows 10

3 Min Read
Follow US
© 2024
activity notes activity notes
Welcome Back!

Sign in to your account

Lost your password?