3

I'm trying to connect to internet using static IP, but when I enter sudo netplan apply command, the console returns the following error:

Invalid YAML at //etc/netplan/01-netcfg.yaml line 8 column 5: did not find expected key.

How to fix this? The content of my 01-netcfg.yaml looks like:

network:
version: 2
renderer: networkd
ethernets:
enp0s3:
            dhcp4: no
            dhcp6: no
            addresses: [10.0.2.15/64]
            gateway4: 10.0.2.0
            nameservers:
            addresses: [8.8.8.8,8.8.4.4]
1
  • Just going to point out a few things, your entire network config is fubar. /64 isn't a valid IPv4 CIDR, 10.0.2.0 isn't a valid gateway, and you also really need to learn how YAML works - specifically its indentation. My answer covers all these specific bits. And since this is your network, you need to either know these settings, or contact your network administrator(s) to know what the gateway and CIDR range are supposed to be.
    – Thomas Ward
    May 8, 2018 at 15:19

4 Answers 4

4

So, with regards to the specific error you're getting, you've failed basic YAML syntax and indentation, which is one of the reasons netplan is complaining. YAML is extremely indentation-oriented for how it interprets commands, config arguments, etc. You need to have proper indentation for YAML configs to be parsed. Surprise, you aren't doing that at all, and breaking YAML syntax. That's why netplan is complaining because you aren't providing proper YAML.

But even more importantly than the YAML syntax which will make Netplan work, you have some critical failures with your network configuration, and you really need to fix these regardless. These failures are, specifically:

  • 10.0.2.15/64 is not a valid IPv4 CIDR range. The acceptable CIDR ranges are between /0 (for all IPv4) and /32 (for a single address) for IPv4. Most networks are /24 for the CIDR range (with this IP range, that would encompass 10.0.2.1 - 10.0.2.255 as usable address space, though I would assume the .1 is the Gateway and the .255 is the Broadcast, but that might differ in your network so double check all the values!). The proper CIDR range is needed so the system knows what its netmask and reachable IP space is.
  • 10.0.2.0 isn't a proper gateway address. The .0 address is not a usable address in IP subnetting, as it's usually held by the network prefix alone. And since your netowrk config attempts to do a /24 but horrendously fails, this gateway should probably be 10.0.2.1 - but again, double check these values with your network admin first.

So, fixing your indentation and fixing the network to assume it's a /24 based on the attempted IP and gateway you specified, your YAML should look like the below, with the proper indentations. And compared to your existing one, you really need to learn how indentation works.

network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: no
      dhcp6: no
      addresses: [10.0.2.15/24]
      gateway4: 10.0.2.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
6
  • @user9507446 if this fixes the issues and fixes your network, consider marking this answer as accepted by clicking the checkbox underneath the voting buttons. That will mark the question as solved/answered. Note that you should only do that if you actually don't get any other errors or such. Also note that network configuration errors such as incorrect IP addresses or IP ranges is not covered here, because I'm not the admin of your network.
    – Thomas Ward
    May 8, 2018 at 15:21
  • Now I get Invalid YAML at //etc/netplan/01-netcfg.yaml line 9 column 16: mapping values are not allowed in this context. Could it mean that I'm using the incorrect IP? May 8, 2018 at 15:36
  • @user9507446 Put the YAML you're trying to use in a pastebin at paste.ubuntu.com and then provide the link to that here in another comment.
    – Thomas Ward
    May 8, 2018 at 15:36
  • paste.ubuntu.com/p/gv6nsYNnxY May 8, 2018 at 15:44
  • @user9507446 Line 13 of that config doesn't match the proper syntax for the addresses line - go compare what you've got to what my answer has.
    – Thomas Ward
    May 8, 2018 at 15:47
3

This one worked for me:

 network:
    ethernets:
        enp2s0:
            addresses:
            - 192.168.0.2/24
            dhcp4: false
            gateway4: 192.168.0.1
            nameservers:
                addresses:
                - 192.168.0.1
                - 8.8.8.8
                search:
                - workgroup
    version: 2

then followed these commands:

sudo netplan generate

sudo netplan apply

Hope it does for you too.

1
0

I tried to configure netplan, using guides like the one above and the following:

0
-1

When I edited the .yaml file and executed: $ netplan try it failed.

In my case I could solve it leaving the space that had the original file: This is on Ubuntu Server 18.04.1 LST. Backup the original file before edit it. Good luck.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .