Hamsa K
4 min read | 10 months ago

How to Setup Static Ip Address on Ubuntu 18 04

Configure Static IP Address on Ubuntu 18.04

Netplan is a new command-line network configuration utility to manage and configure network settings in ubuntu systems.Netplan uses configuration files with YAML syntax.

The first step is to identify the name of the ethernet interface you want to configure. You can use the ip link command as shown below

root@test-VirtualBox:~# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:c6:a9:ae brd ff:ff:ff:ff:ff:ff

Netplan configuration files are stored in the /etc/netplan directory  and have the extension .yaml file and you can store configurations for all your network interfaces in these files. The file may differ from one version to another. Generally, the file is named either 01-netcfg.yaml or 01-network-manager-all.yaml or 50-cloud-init.yaml etc

set static ip using netplan

To assign a static IP address to enp0s3 interface edit the file as follows:

set DHCP to dhcp4: no
enp0s3: network interface name
Specify the static IP address
addresses: you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface.
Specify the gateway as gateway4:
Under nameservers, specify the nameservers addresses: [,]

we need to modify yaml file like below

root@test-VirtualBox:/etc/netplan# cat 01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
  version: 2
  renderer: networkd
      dhcp4: no
      addresses: []
        addresses: [,]

Note: yaml file might not work if there is a syntax error in the configuration.

Apply netpaln

Before applying netplan we can check for errors with debug

netplan apply --debug

If you get an empty response, everything was ok and your new IP configuration has been applied.

Now Verify the changes by typing below command

root@test-VirtualBox:~# ifconfig -a
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast
        inet6 fe80::a00:27ff:fec6:a9ae  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:c6:a9:ae  txqueuelen 1000  (Ethernet)
        RX packets 12508  bytes 13643699 (13.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7786  bytes 827514 (827.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet  netmask
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 554  bytes 46991 (46.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 554  bytes 46991 (46.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0








Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy