Notes – Static IP Ubuntu 18.04 LTS

Check your current IP address and interfaces via “ifconfig -a” or “ip addr” command.

root@localhost:~# ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.15  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe4d:4587  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4d:45:87  txqueuelen 1000  (Ethernet)
        RX packets 924  bytes 573835 (573.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 546  bytes 62672 (62.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 184  bytes 15016 (15.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 184  bytes 15016 (15.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@localhost:~#
root@localhost:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:4d:45:87 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.15/24 brd 192.168.1.255 scope global dynamic ens33
       valid_lft 86060sec preferred_lft 86060sec
    inet6 fe80::20c:29ff:fe4d:4587/64 scope link
       valid_lft forever preferred_lft forever
root@localhost:~#

Find the default network configuration file by issuing the “ls /etc/netplan/” command. Then we edit the network configuration file via nano (sudo nano /etc/netplan/50-cloud-init.yaml).

root@localhost:~# ls /etc/netplan/
50-cloud-init.yaml
root@localhost:~#
root@localhost:~# sudo nano /etc/netplan/50-cloud-init.yaml

You’ll see the following and will need to edit the highlighted and add the static IP values.

  GNU nano 2.9.3                        /etc/netplan/50-cloud-init.yaml

# 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:
        ens33:
            dhcp4: true
    version: 2










^G Get Help    ^O Write Out   ^W Where Is    ^K Cut Text    ^J Justify     ^C Cur Pos     M-U Undo
^X Exit        ^R Read File   ^\ Replace     ^U Uncut Text  ^T To Spell    ^_ Go To Line  M-E Redo
  GNU nano 2.9.3                        /etc/netplan/50-cloud-init.yaml                         Modified

# 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:
        ens33:
            addresses: [192.168.1.102/24]
            gateway4: 192.168.1.1
            dhcp4: no
            nameservers:
              addresses: [8.8.8.8,1.1.1.1]
            optional: true
    version: 2





^G Get Help    ^O Write Out   ^W Where Is    ^K Cut Text    ^J Justify     ^C Cur Pos     M-U Undo
^X Exit        ^R Read File   ^\ Replace     ^U Uncut Text  ^T To Spell    ^_ Go To Line  M-E Redo

Ctrl + X, then save/overwrite when prompted.

Lastly, we apply the new network configuration via “sudo netplan apply“. You can also run “sudo netplan –debug apply” to check if there are any issues with the configuration.

root@localhost:~# sudo netplan apply
root@localhost:~#
root@localhost:~# sudo netplan --debug apply
** (generate:2138): DEBUG: 07:50:42.205: Processing input file /etc/netplan/50-cloud-init.yaml..
** (generate:2138): DEBUG: 07:50:42.205: starting new processing pass
** (generate:2138): DEBUG: 07:50:42.205: ens33: setting default backend to 1
** (generate:2138): DEBUG: 07:50:42.205: Generating output files..
** (generate:2138): DEBUG: 07:50:42.205: NetworkManager: definition ens33 is not for us (backend 1)
DEBUG:netplan generated networkd configuration exists, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:ens33 not found in {}
DEBUG:Merged config:
network:
  bonds: {}
  bridges: {}
  ethernets:
    ens33:
      addresses:
      - 192.168.1.102/24
      dhcp4: false
      gateway4: 192.168.1.1
      nameservers:
        addresses:
        - 8.8.8.8
        - 1.1.1.1
      optional: true
  vlans: {}
  wifis: {}

DEBUG:Skipping non-physical interface: lo
DEBUG:device ens33 operstate is up, not changing
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for ens33
root@localhost:~#
root@localhost:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:4d:45:87 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.102/24 brd 192.168.1.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:4587/64 scope link
       valid_lft forever preferred_lft forever
root@localhost:~#
Notes – Static IP Ubuntu 16.04 LTS Return to Notes list

Leave a Reply