Reputation: 168
I am trying to config IPv6 addresses in Linux and I struggle how am I suppose to add values to netplan's YAML file, here is the file:
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses: [155.128.134.198/23,'2002:18f0:b009:f84:5200:03ff:fdf7:d0c2/64']
gateway4: 155.128.134.198
nameservers:
addresses: [108.61.10.10]
routes:
- to: 169.254.0.0/16
via: 155.138.148.1
metric: 100
And I would like to add IPv6 addresses at the keyaddresses
, but keep those existing there. Is it possible to do through yq
or somewhat simple in any other way, so I can do bash script from that? I haven't found any tool which is specific tool for netplan to be able to easily add addresses in the range. Any help would be highly appreciated.
Upvotes: 1
Views: 1039
Reputation: 569
To append from a shell script, it does appear possible with the newest version of yq.
I can append to it as follows:
$ yq e '.network.ethernets.ens3.addresses += "127.0.0.1/32"' myyaml.yml
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses: [155.128.134.198/23, '2002:18f0:b009:f84:5200:03ff:fdf7:d0c2/64', 127.0.0.1/32]
gateway4: 155.128.134.198
nameservers:
addresses: [108.61.10.10]
routes:
- to: 169.254.0.0/16
via: 155.138.148.1
metric: 100
Note this doesn't update the actual file, you can either pipe that output to a new file or use the -i
flag to update it in place.
Upvotes: 1