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:
- 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 gateway10.0.0.1
, you would use:sudo ip route del 192.168.1.0/24 via 10.0.0.1
- 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:
- 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 of255.255.255.0
via the gateway10.0.0.1
, you’d use:sudo route del -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.0.1
- Persistency:
Just as with the
ip
command, routes added usingroute
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.