1

I'm trying to configure a static IP and I keep getting this error when I try and execute the changes:

Invalid YAML: mapping values are not allowed in this context:
network:
       ^

I've edited my /etc/netplan/00-installer-config.yaml to:

network:
 version: 2
 ethernets:
  eno1:
   dhcp4: false
   addresses: [192.168.20.6/24]
   gateway4: 192.168.20.2
   nameservers:
    addresses: [8.8.8.8,8.8.4.4,192.168.20.2]

I used this guide for this configuration, but I've also followed a bunch of other guides and each time with same result.

All the other questions I've read that are related to this issue have been some problem to do with incorrect indentation or spacing, but I can't see where I'm going wrong. I've followed a few different examples, and have rewritten the file several times to try and make sure I'm not missing a stray spaces but I'm getting the same result every time.

Sebr
  • 187
  • Does adding --debug to the netplan apply command provide any useful information? – steeldriver Jul 04 '20 at 12:26
  • @steeldriver, using --debug still gave me the same error message but made me go back and look at the network line. I was missing the # to comment the developer credit which I didn't notice because I was so focussed on looking for spaces that I didn't notice it :/ – Sebr Jul 04 '20 at 20:13

2 Answers2

0

I believe that your yaml file is invalid for exactly the reason you suspected: indentation and spacing. Your file says, in part:

network:
 version: 2
 ethernets:
  eno1:

Notice that the indentation is one space below network:. Compare the supplied templates:

cat /usr/share/doc/netplan/examples/static.yaml 

Which says, in part:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:

Notice that the indentation is, in every case (except nameservers), two spaces. I suggest that you amend your file to:

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      addresses:
        - 192.168.20.6/24
      gateway4: 192.168.20.2
      nameservers:
          addresses: [8.8.8.8,8.8.4.4,192.168.20.2]

Netplan is also very specific in that it allows spaces in the file and not tabs. Follow with:

sudo netplan generate
sudo netplan apply  

Please see: https://netplan.io/examples

chili555
  • 60,188
  • This comment didn't answer my problem, but that link was really useful as someone who's new to Linux and found it hard to get clear and simple information on setting up a static IP – Sebr Jul 04 '20 at 22:46
0

Your /etc/netplan/00-installer-config.yaml should look like this. Netplan is very fussy about formatting. Use my .yaml EXACTLY as I show it.

  • 2 space indentation
  • no tabs
  • added "renderer: networkd"
  • "dhcp4: false" is not required, as false is the default
  • brackets around [192.168.20.6/24]
  • spaces after commas in nameservers addresses

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      addresses: [192.168.20.6/24]
      gateway4: 192.168.20.2
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4, 192.168.20.2]

sudo netplan --debug generate

sudo netplan apply

reboot

heynnema
  • 70,711
  • Thanks for your help, I made those changes but it turned out I hadn't commented out the developers credit in the first line, which fixed it – Sebr Jul 04 '20 at 20:14
  • @Sebr You didn't show that in your example .yaml file. What did it say? – heynnema Jul 04 '20 at 20:15
  • Yeah I know, sorry. It said # This is the network config written by 'subiquity'. I'm new to Linux so I didn't notice that it wasn't commented out and didn't think it was relevant – Sebr Jul 04 '20 at 20:21
  • @Sebr Correct analysis! Good job! – heynnema Jul 04 '20 at 20:22