How to set static ip on ubuntu server using yaml file.
$ cd /etc/netplan/You need check what file you have in this directory some have 01-netcfg.yaml or 50-cloud-init.yaml that depends on you, for this tutorial i have 50-cloud-init.yaml
so type ls to find whats inside ?
50-cloud-init.yaml so we have 50-cloud-init.yaml in our directory, first i will backup this file, for that you need to type following commands, if i type ls again i can see backup file and current configuration file, before that i will login as root, for that i will use sudo su
$ sudo su
$ cp 50-cloud-init.yaml 50-cloud-init.yaml.backup
$ ls
$ 50-cloud-init.yaml 50-cloud-init.yaml.backupnow i need to edit 50-cloud-init.yaml , i will use nano to edit the file.
$ nano 50-cloud-init.yamlthis will open 50-cloud-init.yaml in nano. your ethernet adpter may vary, mine is ens160:
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
#network:
# ethernets:
# ens160:
# dhcp4: yes
# version: 2
network:
version: 2
renderer: networkd
ethernets:
ens160:
dhcp4: no
addresses: [192.168.1.230/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8]
Now if you see above you can find i have commended default dhcp, and added my static ip, you can copy same settings and change to your settings if you want.
Now press ^x (Ctrl + x ) to exit, and save it.
sudo netplan --debug apply
Last updated
Was this helpful?