Friday, October 27, 2017

Ubuntu 17.10 Configure Static IP Address Command Line

Having promised a colleague that I would set up a Linux VM for him to play around on, I decided to use Ubuntu Linux 17.10 Server - he's interested in encryption and security so a desktop environment wouldn't be of much value.  The installation was typically Ubuntu smooth, but I was surprised to see that /etc/network/interfaces contained no reference to my active NIC, ens160 on my system - I still miss eth0 :(.

Seeing as Ubuntu 17.10 is quite new at this point in time, there wasn't a great deal of info as to how to statically configure the LAN adapter(s).  So without going into too much detail, you now need to know about netplan in order to configure Ubuntu NIC's.  My understanding is that this provides a more platform agnostic platform for LAN configuration, in order to provide a more consistent method across local, VM and cloud deployments.

Anyways, here it is - you want to edit /etc/netplan/01-netcfg.yaml.  Mine started out looking like this (DHCP auto config for LAN adapter ens160 - note that your LAN adapter might be called something else):

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens160:
      dhcp4: yes

I had to revise it as follows:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens160:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.0.10/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

Save changes and execute "sudo netplan generate", followed by "sudo netplan apply".  Obviously if you're remotely connected you then want to connect to the new IP.  Credit to user Rolf over at askubuntu for helping to shed light on this.

No comments: