3

When I add a route using nmcli, the route as reported by ip route show is incorrect: nmcli connection modify eth2 +ipv4.routes "10.0.6.1/32 10.1.7.1"

10.0.6.1 dev eth2 proto static src 10.1.7.1

This route does not work.

However if I use ip route add the ip route show is correct and the route works:

ip route add 10.0.6.1/32 dev eth2 src 10.1.7.1

10.0.6.1 dev eth2  scope link  src 10.1.7.1

I can't seem to find the correct way to add the route using nmcli and have it show up correctly. Any ideas, or is there something I'm missing?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
pacmanwa
  • 359
  • 4
  • 16
  • can you be more specific about why you _know_ the reported route is incorrect? `proto static` sounds reasonable to me, it looks the same as my default route (using networkmanager+DHCP4 on Fedora 24). – sourcejedi Dec 05 '16 at 16:18
  • I have a virtual machine assigned the 10.0.6.1 address. When the route is added by NetworkManager via `nmcli` resulting in a route with `proto static` ntp time sync fails. When the route is added by `ip route add` resulting in a route with `scope link` ntp time sync succeeds. To be honest its confusing the heck out of me because I know the `proto static` route SHOULD work. – pacmanwa Dec 05 '16 at 16:58
  • Are you sure NM isn't changing something else about the routing table? – Bratchley Dec 05 '16 at 18:07
  • Hmm, maybe it works differently because default route has a target IP as well. Anyway perhaps you could look at the result of `ip route get` in each case http://unix.stackexchange.com/a/192065/29483 – sourcejedi Dec 05 '16 at 18:12
  • 1
    The route has a `src` but NM doesn't support that. Hence it looks like the route is not added by NM. Also, `nmcli con modify` modifies a connection profile. Did you activate the connection afterwards for the change to take effect? – thaller Dec 05 '16 at 23:21
  • Yes, `nmcli connection up eth2` is the last thing I do. – pacmanwa Dec 06 '16 at 14:22
  • @thaller that was my problem too. NetworkManager seems ... limited .. in some aspects - and that's as nice as I can put it. Unless I'm unaware of how to do it. I started to use the plugin `ifcfg-rh` though I've not tested a reboot yet. Only the other day have I been forced away from the old way. I really am not liking NetworkManager. The idea that NM doesn't support `src` is absurd. It definitely is needed for some set ups! – Pryftan May 15 '23 at 10:36
  • Re my previous comment: it seems that with `routing-rules` you can specify `src` but I've not tested this. – Pryftan May 15 '23 at 10:52
  • my comment is 6.5 years old. Things change. Read `man nm-settings`. `nmcli connection modify "$PROFILE" +ipv4.routes '10.0.6.1/32 src=10.1.7.1'`. The `ipv4.routing-rules` also have a source attribute, but that has an entirely different purpose. – thaller May 16 '23 at 11:19

1 Answers1

2

Perhaps your problems are related to the setup of the VM? In a simpler case, where I have another router on my network, nmcli works as expected. In my case, the network is 192.168.1.0/24, default route is 192.168.1.1, and there is another router at 192.168.1.9 which connects to another network 192.168.8.0/24.

nmcli c modify eth0 +ipv4.routes "192.168.8.0/24 192.168.1.9"
nmcli c up eth0

This produces expected result in ip route:

default via 192.168.1.1 dev eth0  proto static  metric 100
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.5  metric 100
192.168.8.0/24 via 192.168.1.9 dev eth0  proto static  metric 100 

and in nmcli c show eth0:

IP4.ADDRESS[1]:                         192.168.1.5/24
IP4.GATEWAY:                            192.168.1.1
IP4.ROUTE[1]:                           dst = 192.168.8.0/24, nh = 192.168.1.9, mt = 100

This is on fedora 24.

waldemar
  • 21
  • 2
  • But `nh` is not the same as `src` (or so I think) and thus this does not solve the specific problem. NM does not seem to support the latter (which is ridiculous) and `src` **IS** important. If it wasn't `ip(8)` wouldn't have it! Using in `nmcli` the describe command: `Enter a list of IPv4 routes formatted as: ip[/prefix] [next-hop] [metric],...`. – Pryftan May 15 '23 at 10:39
  • Re my previous comment: according to https://xy2401.com/local-docs/redhat/8/configuring-and-managing-networking/OEBPS/Configuring-Networking-with-nmcli_configuring-and-managing-networking.html it's possible to add `src` at the command line. But if so it doesn't seem to be possible in the edit command - or else they don't say how. – Pryftan May 15 '23 at 10:48
  • I take that back. With the `ipv4.routing-rules` you can it seems do it with the editor. – Pryftan May 15 '23 at 10:51
  • nmtui currently(!) does not support configuring route attributes beside the metric and next hop. Use nmcli instead and see `man nm-settings` about `ipv4.routes`. – thaller May 16 '23 at 11:21