This week as per your requests and feedback we have a new tutorial on how to do ubuntu network configuration and set static IP.
Before going into details check Our Best VPS Hosting and WordPress hosting for scaling your cloud-based applications and processes.
Netplan is a new command-line network configuration utility introduced in Ubuntu 17.10 which helps you manage and configure network settings easily in Ubuntu systems.
- It allows you to configure a network interface using YAML abstraction. It works in conjunction with the NetworkManager and system-networkd networking daemons (referred to as renderers –
Interfaces to the Kernel
- you may choose which one of those to use) as interfaces to the kernel.
- It reads network configuration described in /etc/netplan/*.yaml, and you could store configurations for all your network interfaces in those files.
Ubuntu Network Configuration
In this tutorial, we will show you how to configure a static or dynamic network IP address for a network interface in Ubuntu 18.04 using the Netplan utility.
List All Active Network Interfaces on Ubuntu
First, you have to identify the network interface you will be configuring. You can list all attached network interfaces on your system by using the ifconfig command as in the example below:
$ ifconfig -a
Set Static IP in Ubuntu 18.04
In this example, we are going to configure a static IP for the enp0s8 ethernet network interface. Open the netplan configuration file using your text editor as shown below.
Important: in case a YAML file is not created by the distribution installer, you may generate the needed configuration for the renderers by using the command below:
$ sudo netplan generate
In addition, auto-generated files might have a different filename between desktops, servers, cloud instantiations etc., (for example 01-network-manager-all.yaml or 01-netcfg.yaml) but every file under /etc/netplan/*.yaml is going to be read by netplan.
$ sudo vim /etc/netplan/01-netcfg.yaml
Now append the following configuration under the Ethernet area.
enp0s8: dhcp4: no dhcp6: no addresses: [192.168.56.110/24, ] gateway4: 192.168.56.1 nameservers: addresses: [22.214.171.124, 126.96.36.199]
- enp0s8 – network interface name.
- dhcp4 and dhcp6 – dhcp properties of an interface for IPv4 and IPv6 receptively.
- addresses – sequence of static addresses to the interface.
- gateway4 – IPv4 address for default gateway.
- nameservers – sequence of IP addresses for nameserver.
After you have addended this, your configuration file will now have the following content.
The first interface, enp0s3, is configured to use DHCP, and enp0s8 will use a static IP address.
IP Address Property
The addresses property of an interface expects a sequence entry, for example [192.168.14.2/24, “2001:1::1/64”] or [192.168.56.110/24, ] (see netplan man page for more information).
# This file describes the network interfaces available on your system # For more information, see netplan(5). network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: yes enp0s8: dhcp4: no dhcp6: no addresses: [192.168.56.110/24, ] gateway4: 192.168.56.1 nameservers: addresses: [188.8.131.52, 184.108.40.206]
Save the file and exit. Then apply the recent network changes by using the netplan command below:
$ sudo netplan apply
Now confirm the available network interfaces again. The enp0s8 ethernet interface will now be connected to the local network and have an IP address.
$ ifconfig -a Set Dynamic DHCP IP Address in Ubuntu
In order to configure the enp0s8 ethernet interface to retrieve an IP address dynamically through DHCP, just use the following configuration:
# This file describes the network interfaces available on your system # For more information, see netplan(5). network: version: 2 renderer: networkd ethernets: enp0s8: dhcp4: yes dhcp6: yes
Save the file and exit. Then apply the recent network changes and confirm the IP address using the following commands:
$ sudo netplan apply $ ifconfig -a
From now on, your system will get an IP address dynamically from a router.
You should be able to find more information and configuration options by consulting the netplan man page.
$ man netplan
Congratulations! You’ve successfully configured a network static IP address to your Ubuntu servers. If you have any queries, share them with us via the comment form below.
Also, here are a few hand-picked guides that must read next:
Do let us know if you want to add any specific Linux or Windows hosting topics into this tutorial series.