Goglides Dev 🌱

Balkrishna Pandey
Balkrishna Pandey

Posted on

Linux basic routing- static route how it works?

I can reach Host B from Host A using interface eth0. Host B has Ip address assigned to interface eth3. Ip address is reachable from host A. Now host B has another Ip address,, at interface interface_at_hostb. But this Ip is not reachable from Host A. How to fix this issue using linux static route approach?

To add a static route in Host A so that you can reach Host B using the IP address, you can use the command:

route add -host <ip-address-you-want-resolve> gw <HostB_eth3_IP> dev <interface_eth0> 
Enter fullscreen mode Exit fullscreen mode

You will need to replace the following with the appropriate values:

  • <HostB_eth3_IP>: the IP address assigned to the eth3 interface on Host B (example:

  • <interface_eth0>: the interface on Host A that is used to connect to Host B (example: eth0)

For example:

route add -host gw dev eth0 
Enter fullscreen mode Exit fullscreen mode

You can verify the route has been added by using the command route -n.

This command will add a static route in host A to reach host B's IP via gateway IP, which is assigned to host B's interface eth3, and you will be able to reach to host B via interface interface_at_hostb as well.

You can delete this route using following command.

route del -host
Enter fullscreen mode Exit fullscreen mode

Top comments (0)