List All Active Network Interfaces on Ubuntu

First, you need lớn identify the network interface you are going lớn configure. You can danh mục all attached network interfaces on your system using the command as shown below:

Ip a

From the output đầu ra of the above command, we have 3 interfaces attached to lớn the Ubuntu system: 2 ethernet interfaces (one of them is docker) và the loopback interface. The ens33 ethernet interface has been configured lớn obtain IP address from DHCP. And we need to change it to static IP.

Bạn đang xem: How to configure static ip address on ubuntu 18

Set Static IP Address in Ubuntu 18.04

In this example, we will configure a static IP for the ens33 ethernet network interface. Khổng lồ make this happen we will use the netplan utility.

Netplan is a new command-line network configuration utility introduced in Ubuntu 17.10 lớn manage và configure network settings easily in Ubuntu systems. It allows you khổng lồ configure a network interface using YAML abstraction. It works in conjunction with the NetworkManager and systemd-networkd networking daemons (referred to lớn as renderers, you can choose which one of these khổng lồ use) as interfaces lớn the kernel.

It reads network configuration described in /etc/netplan/*.yaml and you can store configurations for all your network interfaces in these files.

So the first thing to vày is to check what configuration files bởi vì we have in /etc/netplan/We can check this out by using the command:

ls /etc/netplan/

As we can see there is a configuration file called 50-cloud-init.yaml. We need to lớn edit it to change configuration.

If there’s no configuration files in /etc/netplan/ you can use command as shown below khổng lồ generate it:

sudo netplan generate

In addition, tự động generated files may have different filenames on desktop, servers, cloud instantiations etc (for example 01-network-manager-all.yaml or 01-netcfg.yaml, 50-cloud-init.yaml, etc.), but all files under /etc/netplan/*.yaml will be read by netplan.

Open the netplan configuration file using your text editor as shown:

sudo nano /etc/netplan/50-cloud-init.yaml


Find your network interface name in there. It’s ens33 in this example.

As you can see there’s dhcp4: true = dchp for ipv4 is enabled.

To change that simply change the config lượt thích that:


ens33 – network interface name.dhcp4and dhcp6 – dhcp properties of an interface for IPv4 and IPv6 receptively.addresses– sequence of static addresses to lớn the interface. (with subnet mask)gateway4– IPv4 address for default gateway.nameservers– sequence of IP addresses for nameserver.

The addresses property of an interface expects a sequence entry for example <, “2001:1::1/64”> or <, > (see netplan man page for more information).

Important: don’t use tabs in this configuration file.

Save the file và exit. (to save tệp tin press Ctrl+O and then choose the filename & press Enter. To exit nano press Ctrl+X)

Then apply the recent network changes using the following command:

sudo netplan apply

If everything is ok you’ll not get any error messages.

Just kiểm tra your ip configuration again with the command:

ip a

As you can see now the ens33 have an IP addresses as we configured before in yaml file.

Xem thêm: Cách Chat Với Người Lạ Trên Messenger Facebook Bằng Tính Năng Chatible

Congratulations! You’ve successfully configured a network static IP addresses khổng lồ your Ubuntu server.