Error configuring static routing using cli

I'm trying to add a static route on my Ubuntu Desktop 16.04 machine with the cli, but with no success. I'm using the classic ip route command: ip route add x.x.x.0/24 via y.y.y.y dev eno1 (hid the actual addresses here), and I receive the following error: RTNETLINK answers: Network is unreachable. My machine will access y.y.y.y through its default gateway. The actual routing from the default gateway to y.y.y.y which will route to x.x.x.x is already set and working.

The error received is fine by me, as it is actually reachable (tested myself), as must be a false error caused by network components (such as FW).

My question is: is there a way to ignore that error? This error is causing the static routing not to be saved, and I want it to be saved even though the command thinks it is unreachable. My route command shows only my default and link-local acquired by the dhcp and also shows my vmnet.

Why am I using the cli?

I know Ubuntu 16.04 should use /etc/network/interfaces, and Ubuntu 18.04 and above versions use /etc/netplan, but my /etc/network/interfaces file is absolutely empty (probably because of the dhcp method).

Edit: contents of /etc/network/interfaces:

auto lo
iface lo inet loopback

Output of route command:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default z.z.z.254 0.0.0.0 UG 100 0 0 eno1
z.z.z.0 * 255.255.255.0 U 100 0 0 eno1
link-local * 255.255.255.0 U 1000 0 0 eno1
g.g.g.0 * 255.255.255.0 U 0 0 0 vmnet1

Output of ip route list command:

default via z.z.z.254 dev eno1 proto static metric 100
z.z.z.0/24 dev eno1 proto kernel scope link src z.z.z.101 metric 100
169.254.0.0/16 dev eno1 scope link metric 1000
g.g.g.0/24 dev vmnet1 proto kernel scope link src z.z.z.1 

Overall, I'm looking for a way to sometimes force a path for a machine without having to create a virtual interface and configure my network components for that interface.

5

1 Answer

This "answer" most likely will be devoured by the internet for it's wording and whatnot, but, my assumption with your question is you're attempting to reach outside of your broadcast domain.

In your latest comment, it does appear as though you're attempting to route externally, using your default router - but I'll add the below here and we'll refine as we go.


Your computer can only route in a Layer-2 Broadcast Domain. What this means is, you cannot attempt to define a next-hop on another logical network, except for a router (ignoring more advanced networking; this is a Ubuntu forum). On a "traditional" private network, you will operate from a "/24" network range (sometimes denoted as 192.168.0.0/24 or 255.255.255.0 CIDR).

When you want to add a static route, unless you have a router with RIP, OSPF or BGP running, you must have a logical next-hop on the device. Take the following example of a network "design":

  1. My computer has an IPv4 address allocated via DHCP of 10.128.129.1 (mask of 255.255.255.0) and routes via 10.128.129.254 on VLAN 10;
  2. My Cisco Router has a logical interface in VLAN 10 (10.128.129.254) and VLAN 11 (10.128.130.254) and;
  3. My Server has an IP address of 10.128.130.1 (VLAN 11) and has a default route of 10.128.130.254;

On my host address, if I am not learning internal routes, my default will be via 10.128.129.254 - which, in it's ARP table, should have a known address to route to the server - this is a Layer 3 function.

What happens if my router isn't learning routes, and itself isn't the gateway address for VLAN 11? Then, I need to denote a route entry (I'll not go into details on BGP and other technologies)

Client Side Routing

For this situation on my Linux box, I still need to know where I can contact VLAN 11 - 10.128.130.0/24 - so I add a static route:

$ sudo ip route add 10.128.130.0/24 via 10.128.129.254 dev eno2 

Why does this work? Because on a broadcast range, my PC can reach 10.128.129.254 without needing Layer 3 functionality.

I cannot, for example, add the following:

$ sudo ip route add 10.128.130.0/24 via 10.128.130.254 dev eno2

As the router is not in the same logical subnet.

Configuring Routing - Router Modifications

Right, so at this point clients are using the router to attempt to route to 10.128.130/24 - so now the router needs to know it's next hop. Depending on the device depends on the syntax, and what solutions you have available; for now, we just assume your router has a next hop to a router in the logical VLAN, and all is working fine.

Why is the command failing?

Some examples of the same issue can be found on other sites, and also point to not being in a logical network. You could attempt (if this is multi-spanning) add an IP alias to an interface and go from there.

Just double check that the network you want to route to, and the next-hop on the PC are in the same logical network.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like