By default , most OS comes with the DHCP client enabled and it will then get an IP from the DCHP server pool . But in some cases, you may need to add a static IP instead of receiving a dynamc IP via DHCP .
So ubuntu on latest versions uses a utility called netplan for this :
First you need to find your ethernet interface name
ifconfig
The file we need is:
/etc/netplan/00-installer-config.yaml
As this is an important file , its better to take a backup and incase something goes wrong we can restore it back :
cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
Then you can modify the file using the nano editor:
nano /etc/netplan/00-installer-config.yaml
You will see DHCP True in this file ,that should be changed to ‘no’ , so edit it as below : Make sure you provide your own ethernet interface name which you found using ifconfig . Then your private/public static IP, subnet mask, gateway etc .The namersever we just used are external name servers but you can use your own if you want .
network:
ethernets:
ens5:
dhcp4: no
addresses:
- 10.10.0.10/24
gateway4: 10.10.0.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
version:2
Then apply the configuration :
netplan apply
Leave a Reply