Categories
Coding Computers

How to Delete a Static/Persistent Route in Linux

In Linux, the ip command or the older route command can be used to manage routing tables. Here’s how you can delete a static/persistent route:

Using the ip command:

  1. Delete the Route:

    Use the following format to delete a route:

    sudo ip route del <destination_network>

    For instance, to delete a route to the 192.168.1.0/24 network via the gateway 10.0.0.1, you would use:

    sudo ip route del 192.168.1.0/24 via 10.0.0.1
  2. Persistency:

    Routes added with the ip route command are non-persistent, meaning they will be lost after a system reboot. If you’ve made the route persistent by adding it to a configuration file (e.g., /etc/network/interfaces on Debian/Ubuntu or /etc/sysconfig/network-scripts/route-<interface_name> on RedHat/CentOS), you’ll need to edit the corresponding file and remove the route specification to ensure it’s not re-applied at boot.

Using the older route command:

  1. Delete the Route:
    sudo route del -net <destination_network> netmask <netmask> gw <gateway_ip>

    For instance, to delete a route to the 192.168.1.0 network with a netmask of 255.255.255.0 via the gateway 10.0.0.1, you’d use:

    sudo route del -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.0.1
  2. Persistency:

    Just as with the ip command, routes added using route are non-persistent. If you made the route persistent by adding it to a configuration file, you should edit the corresponding file and remove the route specification.

Remember to backup any configuration files before editing them. After making changes, you can usually apply them without rebooting by restarting the networking service or by bringing the network interface down and then back up.

Leave a Reply

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