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.

      route - show / manipulate the IP routing table


      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 gw netmask dev eth0

sudo route add -net gw netmask dev eth0

View route

We can use

route -n
sudo ip route show
netstat -rn

Deleting route

sudo route del -net gw netmask dev eth0

sudo route del -net gw netmask dev eth0

A quick way to add default route

route add default gw

A  quick way to delete default route

route del default gw

No comments:

Post a Comment