0

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
  • Can you dump an output of your route print? From my unprofessional opinion it's stating that the router/gateway you've defined isn't reachable in your layer-2 broadcast domain, hence it cannot be your next hop; you need to point to your L2 broadcast, and add the route on the router.
    – DankyNanky
    May 19, 2020 at 10:07
  • Edited the question
    – Pizza
    May 19, 2020 at 10:35
  • Are you using internal, non-routable IP ranges? If so, please don't obfuscate them. You have a global route, and are using a /24 route - meaning, if you have 192.168.0.1-255 and you want to route to 10.1.0.254 using 10.1.0.1, your next hope needs to be in the logical 192.168.0 range, and the static route needs to be added to 10.1.0.1 - is this what you're doing?
    – DankyNanky
    May 19, 2020 at 10:51
  • All the ip addresses are internal, though I cannot expose them. Every expression with letters representing ip addresses is a full segment described by the mask. I'll try to explain a bit more: my segment is z.z.z.0/24, default gateway is z.z.z.254. I want my machine on z to access the x.x.x.0/24 segment from a component on y.y.y.y (which will route to x). The machine on z will be routed to y using the z.z.z.254 default gateway. Hope I was able to make it a bit clearer.
    – Pizza
    May 19, 2020 at 11:59
  • Sorry...you'll need to forgive me, I'm a bit too slow to work with letters. I have added "an answer" denoting what I've attempted to relay...see if that helps (it sounds as though you're trying to route in your logical network). If I'm completely off topic do let me know :)
    – DankyNanky
    May 19, 2020 at 15:13

1 Answer 1

1

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
  • 1
    Thank you for your very good detailed answer. I understand in terms of networking how and why such connection will not work, though I hoped there is some easier way of configuring such routing on a machine (reach segment A via segment B, and segment B is to be reached via default gateway). You see, I actually want my machine to access that segment in two ways, one time using the default gateway only, and let my routers and firewalls to handle my standard configuration, and another time to force it use a path with a dev segment that will proxy this connection with some modifications first.
    – Pizza
    May 20, 2020 at 7:34
  • 1
    Unfortunately, if there is no easier way of doing so, I assume I will have to create a virtual interface on that machine and just create static routes between the routers and other network components to force such path. Thus segment A will do it's alterations to the connection and then route it to B.
    – Pizza
    May 20, 2020 at 7:36
  • No worries - all the best in getting it configured :)
    – DankyNanky
    May 21, 2020 at 10:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.