8

I have some real issues with one brand new Ubuntu 20.04 installation. I'm trying to accomplish simple network configuration - one physical interface with 2 different IP addresses from the same network using the same gateway. I see netplan is not supporting aliases anymore so I was following the recommendation from netplan page. Here is my config:

network:
version: 2
renderer: networkd
  ethernets:
    enp2s0:
     addresses:
       - 192.168.1.100/24
       - 192.168.1.99/24
     gateway4: 192.168.1.1
     nameservers:
         addresses: [1.1.1.1, 1.0.0.1]  

So when I netplan apply server disappears from the network completely. By looking in the syslog i see the following error:

enp2s0: Could not set route: Nexthop has invalid gateway. Network is unreachable enp2s0: Failed

I was following the examples from here https://netplan.io/examples#using-multiple-addresses-on-a-single-interface This should be very simple configuration which I don't understand why not working. Am I missing something? Thanks, Andrey

here is an output from netplan debug:

srv1:~$ sudo netplan --debug generate
DEBUG:command generate: running ['/lib/netplan/generate']
** (generate:1744): DEBUG: 11:04:55.637: Processing input file /etc/netplan/00-installer-config.yaml..
** (generate:1744): DEBUG: 11:04:55.637: starting new processing pass
** (generate:1744): DEBUG: 11:04:55.637: We have some netdefs, pass them through a final round of validation
** (generate:1744): DEBUG: 11:04:55.637: enp2s0: setting default backend to 1
** (generate:1744): DEBUG: 11:04:55.637: Configuration is valid
** (generate:1744): DEBUG: 11:04:55.637: Generating output files..
** (generate:1744): DEBUG: 11:04:55.637: NetworkManager: definition enp2s0 is not for us (backend 1)
(generate:1744): GLib-DEBUG: 11:04:55.637: posix_spawn avoided (fd close requested)
Andrey Hinov
  • 83
  • 1
  • 1
  • 4
  • You only have one .yaml file in /etc/netplan, correct? enp2s0 is your ethernet interface, yes? If you're using my exact .yaml, what happens after a sudo netplan apply and reboot? – heynnema May 23 '20 at 15:29
  • output is the same as above however after restart it started working. I'm little bit confused as doesn't work unless restarted. Even sudo systemctl restart system-networkd doesn't bring the network up. – Andrey Hinov May 23 '20 at 15:49
  • Reboot required due to the static IPs... as per my instructions. Please remember to accept my answer by clicking on the checkmark icon that appears just to the left of my answer. Thanks! – heynnema May 23 '20 at 15:50
  • Thank you for your help!!! – Andrey Hinov May 23 '20 at 15:57

1 Answers1

14

Netplan is very fussy about spacing, indentation, and no tabs.

Try this slight variation of your .yaml file...

network:
  version: 2
  renderer: networkd
  ethernets:
    enp2s0:
      addresses:
        - 192.168.1.100/24
        - 192.168.1.99/24
      gateway4: 192.168.1.1
      nameservers:
        addresses: [1.1.1.1, 1.0.0.1]
      optional: true

sudo netplan generate

sudo netplan apply

reboot

heynnema
  • 70,711
  • 2
    Thank you for this. Although my config was applied after sudo netplan apply. No need for me to reboot for it to work. (On Ubuntu 20.04) – Majal Aug 03 '21 at 01:24