Trying to set up a static IP address for a VM for a personal project but I keep getting some form of Invalid YAML syntax error
772
Currently this is what I have in the Ubuntu VM. I have followed the guide from the video that I am watching, but it keeps saying that there is a syntax error. I have check it multiple times and have done a new installation, but it still hase the same error.
The syntax of Netplan YAML files are very particular with respect to indentation. First of all, you're not allowed to use tab characters. Instead, you have to use space characters only.
The number of spaces isn't particular. You can use a single space if that suits you. In your case, you used four. In my example below, I used two, which is my preference. The important consideration is the consistency.
With regards to your configuration and the error you're receiving, the stanzas for addresses, nameservers, and routes need to fall under the stanza for enp0s3.
Therefore, edit your Netplan YAML configuration file as follows:
network:
version: 2
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.10.10/24]
nameservers:
addresses: [8.8.8.8]
routes:
- to: default
via: 192.168.10.1
Then run the following commands to apply the changes:
The syntax of Netplan YAML files are very particular with respect to indentation. First of all, you're not allowed to use tab characters. Instead, you have to use space characters only.
The number of spaces isn't particular. You can use a single space if that suits you. In your case, you used four. In my example below, I used two, which is my preference. The important consideration is the consistency.
With regards to your configuration and the error you're receiving, the stanzas for
addresses
,nameservers
, androutes
need to fall under the stanza forenp0s3
.Therefore, edit your Netplan YAML configuration file as follows:
Then run the following commands to apply the changes:
Afterwards, check the status with
netplan status
.Here's a link to the Netplan documentation.