I'm unable to create a static ip route. error says: RTNETLINK answers: Network is unreachable

9,191

I see the problem.

You are trying to connect from vm-client1 which has only one interface with connected network 192.168.101.0/24 but you are trying to add gateway on network 192.168.102.0/24 which is not actually available on this interface hence you are getting message "Network is unreachable".

Please bear in mind that any gateway (the ip address behind "via" word) must be reachable directly on connected interfaces (and this is not your case).

Furthermore there is no need to set-up routing on vm-client1 because everything will be going to default gateway vm-router which is responsible for routing.

Actually there is only one thing you need to do - enable IP forwarding ( https://askubuntu.com/questions/311053/how-to-make-ip-forwarding-permanent ) on vm-router and your packets will be forwarded automatically.

You do not need to make any changes to default routes in this scenario. Just enable IP forwarding on vm-router and you will be just fine.

Share:
9,191

Related videos on Youtube

VaTo
Author by

VaTo

Updated on September 18, 2022

Comments

  • VaTo
    VaTo over 1 year

    Im trying to setup a test network with VMs to practice how static routing works, so what I thought to do is to setup two internal networks and one box with two interfaces to work as a router, here's the setup with the IPs:

    enter image description here

    I configured the static IPs in each box and also I added the default gateway to be adapter1 for vm-client-1 and adapter2 for vm-client-2.

    Now, I'm in the last step to create the ip route, I executed in vm-client-1:

    sudo ip route add 192.168.102.0/24 via 192.168.101.1 dev enp0s3

    and I get this error as the output:

    RTNETLINK answers: Network is unreachable.

    Note: I cleared all the iptables rules with iptables -F so that the firewall is not the problem. Also, vm-client can ping 192.168.102.1 (the gateway of vm-client-2) so, I don't know why it says that Network is unreachable, help is appreciated.

    Here's the information of vm-client-1:

    enter image description here