Linux route delete default route

proper syntax to delete default route for a particular interface?

On this client, I have started an OpenVPN client (after previously starting an OpenVPN server in the cloud), logged into a remote-access website, and used that site’s web UI to connect to a (proprietary) F5 SSL VPN (which I want to tunnel through the OpenVPN). (More details on the design goal here and the problem configuration here.) This produces

me@client:~$ date ; sudo ifconfig Thu Jan 22 11:48:43 EST 2015 eth0 Link encap:Ethernet HWaddr inet addr:192.168.1.142 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:10224715 errors:0 dropped:0 overruns:0 frame:0 TX packets:6011530 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12886933501 (12.0 GiB) TX bytes:677423768 (646.0 MiB) Interrupt:20 Memory:f2600000-f2620000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:497 errors:0 dropped:0 overruns:0 frame:0 TX packets:497 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:51273 (50.0 KiB) TX bytes:51273 (50.0 KiB) # Note I get slightly different IP#s for interface=ppp0 each time I run this scenario. ppp0 Link encap:Point-to-Point Protocol inet addr:10.144.15.234 P-t-P:10.144.0.1 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:6 errors:0 dropped:0 overruns:0 frame:0 TX packets:18 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:3 RX bytes:56 (56.0 B) TX bytes:2418 (2.3 KiB) tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:10.8.0.6 P-t-P:10.8.0.5 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:4 errors:0 dropped:0 overruns:0 frame:0 TX packets:4 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:304 (304.0 B) TX bytes:304 (304.0 B) me@client:~$ date ; sudo route -n Thu Jan 22 11:48:48 EST 2015 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.144.15.100 128.0.0.0 UG 1 0 0 ppp0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 10.144.0.1 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0 128.0.0.0 10.144.15.100 128.0.0.0 UG 1 0 0 ppp0 134.67.15.30 10.8.0.5 255.255.255.255 UGH 1 0 0 tun0 

Once at that point, I’m directed (IIUC) to delete the default route being set by the F5VPN (on interface= ppp0 , for debugging. Furthermore, I need to do this quickly, because (and this is the problem with the current misconfiguration) the misconfiguration causes the OpenVPN tunnel to fail quickly, which breaks the situation I want to debug. Hence it is quite infuriating that I cannot seem to find the correct route syntax to do this:

me@client:~$ sudo route del default ppp0 SIOCDELRT: No such process me@client:~$ sudo route del default dev ppp0 SIOCDELRT: No such process me@client:~$ sudo route del -net default dev ppp0 SIOCDELRT: No such process me@client:~$ sudo route del -net default gw 10.144.15.234 dev ppp0 SIOCDELRT: No such process me@client:~$ sudo route del -net default netmask 128.0.0.0 gw 10.144.15.234 dev ppp0 SIOCDELRT: No such process me@client:~$ sudo route del -net default gw 0.0.0.0 dev ppp0 SIOCDELRT: No such process me@client:~$ sudo route del -net default netmask 255.255.255.255 gw 0.0.0.0 dev ppp0 SIOCDELRT: No such process 

info route is not helping, nor are my websearches finding helpful doc. (Both cases probably due to my lack of networking experience.) What am I doing wrong?

Читайте также:  Windows usb drivers in linux

Источник

How to Add and Delete Static Route in Linux using IP Command

Part of the skill set for any Linux user, and particularly a systems administrator, is the ability to perform some network tweaks on a Linux system. This includes adding and deleting routes to enable the system to communicate with other systems o a local network. In this guide, we explore exactly how you can go about adding and deleting routes on a Linux system.

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:

$ ip route show Or $ ip route list

ip-route-show-command-output-linux

Similar statistics can be displayed using route command,

route-n-command-output-linux

route-command-output-linux

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.

netstat-nr-command-output-linux

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

$ sudo ip route add 10.0.2.0/24 via 192.168.43.223 dev enp0s3

ip-route-add-command-linux

  • 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
Читайте также:  What is run directory linux

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

ip-route-command-output-linux

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

$ sudo ip route add 10.0.2.15 via 192.168.43.223 dev enp0s3

ip-route-add-single-ip-linux

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

ip-route-show-linux-command

route-n-linux-command-ouput

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 .

$ 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

$ sudo systemctl restart NetworkManager

Permanently adding static route (Ubuntu / Debian)

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

$ sudo vim /etc/network/interfaces

Append the following line:

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

$ 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:

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

ip-route-del-subnet-linux-command

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

$ sudo ip route del 10.0.2.15 via 192.168.43.223 dev enp0s3

ip-route-del-ip-linux-command

To delete default route run:

$ sudo ip route del default

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

Читайте также:  Адрес домашней папки linux

$ sudo ip route add default via dev interface

$ sudo ip route add default via 192.168.43.1 dev eth0

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.

Also Read : 12 ip Command Examples for Linux Users

Источник

How To Delete Route In Ubuntu Linux?

I have some route in my routing table. But I want to delete one route from routing table. How can accomplish this?

List Existing Routes

To get detailed information about route that will be removed we list the existing routes in our system.

$ sudo ip route show default via 192.168.122.1 dev ens3 10.0.3.0/24 dev lxcbr0 proto kernel scope link src 10.0.3.1 172.16.0.0/24 via 192.168.122.1 dev ens3 192.168.122.0/24 dev ens3 proto kernel scope link src 192.168.122.211

Remove Specific Route

This command can be run all modern Linux distributions like Kali, Debian, Ubuntu, Fedora, CentOS. We remove the route by giving specific details about route like below. We will use ip route del command and provide related parameters.

$ sudo ip route del 172.16.0.0/24 via 192.168.122.1 dev ens3
  • ip route del is the command issues for removal
  • 172.16.0.0/24 via 192.168.122.1 dev ens3 is our route to be removed. We give the full detail route so there will no space for error.

Check

We want to check the last status of our routing table. We issue the same command we issued when starting.

$ sudo ip route show default via 192.168.122.1 dev ens3 10.0.3.0/24 dev lxcbr0 proto kernel scope link src 10.0.3.1 192.168.122.0/24 dev ens3 proto kernel scope link src 192.168.122.211

As we can see from the output the route to the 172.16.0.0/24 is deleted from routing table.

How To Delete Route In Ubuntu Linux? Infografic

Источник

Оцените статью
Adblock
detector