Netplan configuration error: "Invalid YAML ... did not find expected key."
Solution 1:
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 encompass10.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 be10.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]
Solution 2:
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.