Ubuntu Network Configuration - richiedennis/Tech-Journal-SYS265- GitHub Wiki

This is a tutorial for setting up Ubuntu 18.0 Static IP configuration

  • CD into the /etc/netplan directory. This is where the file is that we need to edit to configure the IP. Do an ls command and you should see a file named something like, "50-cloud-init.yaml."
  • Use a text editor to open the file (my preferred choice is vi) and you should see something like this:

network:

version: 2 renderer: networkd ethernets:

ens192:

dhcp4: yes

  • You will want to edit the file to look similar the example below (change the addresses to suit your network):

network:

version: 2 renderer: networkd ethernets:

ens192:

dhcp4: no addresses: [192.168.1.222/24] gateway4: 192.168.1.1 nameservers:

addresses: [8.8.8.8]

  • After the file has been edited and saved, run the following command to apply what you just did

sudo netplan apply

Changing Hostname

  • Use the below command to display the hostname

hostnamectl

  • You can change the hostname using the hostnamectl command like below (I made my hostname ubuntu-richard, make your whatever you please)

sudo hostnamectl set-hostname ubuntu-richard

  • Now we have to edit the /etc/hosts file to change the old hostname. Just change all the spots where it said the previous hostname (i.e. localhost) to your new hostname and then save the file.
  • Finally we have to edit the cloud.cfg file. Check to see if it is installed by using the command below. If it isn't installed you should be good and you can skip the following steps. If your system does have it tho, follow the directions.

ls -l /etc/cloud/cloud.cfg

  • Use a text editor to view the file and change the field 'preserve_hostname' from false to true. Save the file.

Add a sudo user

  • Run the following commands (my name is richard, make yours whatever you want)

sudo adduser richard

sudo usermod -aG sudo richard