Monday, March 4, 2019

how to add or delete routes in linux ?


There are two commands which are useful either to add or delete route, those are  route and ip.
We will see how to change route using command route.

Understanding of routing

On Linux and UNIX systems, information on how packets are to be forwarded is stored in a kernel structure called a routing table. You need to manipulate this table when configuring your computer to talk to other computers across a network. The routing table can be used for both static and dynamic routing. Dynamic routing consists of the kernel making decisions as to which route, out of multiple present routes, a packet should take. Since dedicated routers and ISPs generally deal more with dynamic routing.



NAME
      route - show / manipulate the IP routing table

SYNOPSIS

      route [-CFvnee]

      route [-v] [-A family] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M]
[window W] [irtt I] [reject] [mod] [dyn] [reinstate] [[dev] If]

      route [-v] [-A family] del [-net|-host] target [gw Gw] [netmask Nm] [metric N] [[dev] If]

      route [-V] [--version] [-h] [--help]




Adding route


sudo route add -net 192.168.3.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

sudo route add -net 192.168.3.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

View route

We can use

route -n
Or
sudo ip route show
Or
netstat -rn

Deleting route



sudo route del -net 192.168.3.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

sudo route del -net 192.168.3.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

A quick way to add default route



route add default gw 192.168.1.1

A  quick way to delete default route


route del default gw 192.168.1.1



No comments:

Post a Comment