How to set static IP for Ubuntu 18.04 Server

How to set static IP for Ubuntu 18.04 Server

1. Background

Netplan is a new command-line network configuration utility introduced in Ubuntu 17.10 for easily managing and configuring network settings in Ubuntu systems. It allows you to configure network interfaces using the YAML abstraction. It works with NetworkManager and the systemd-networkd network daemon (called renderers, you can choose which one to use) as an interface to the kernel.

It reads the network configuration described in /etc/netplan/*.ymal and can store the configuration of all network interfaces in these files.

In this article. We will explain how to configure a network static or dynamic IP address for a network interface in Ubuntu 18.04 using the Netplan utility.

2. Solution

List all active network interfaces on Ubuntu

First, you need to determine which network interface you want to configure. You can use ifconfig command to list all connected network interfaces in your system as shown.

ifconfig -a

Checking Network Interfaces in Ubuntu

From the output of the above command, we have 2 interfaces connected to our Ubuntu system: 1 Ethernet interface and the loopback interface.

Ubuntu sets a static IP address

In this example, we will configure the ens33 Ethernet network interface with a static IP. As shown, use vim to open the netplain configuration file.

Important: If the YAML file was not created by the distribution installer, you can use this command to generate the required configuration for the renderer.

sudo netplan generate

Additionally, the auto-generated files may have different file names on your desktop, server, cloud instance, etc. (e.g. 01-network-manager-all.ymal or 01-netcfg.yaml), but all files under /etc/netplan/*.yaml will be read by netplan.

sudo vim /etc/netplan/xxxx.ymal

Then add the following configuration in the ethernet section.

network:
  ethernets:
    ens33:
      addresses:
      - 192.168.4.254/24
      dhcp4: false
      gateway4: 192.168.4.2
      nameservers:
        addresses:
        - 8.8.8.8
        search: []
  version: 2

illustrate:

•ens33: Network interface name
•dhcp4: Receive dhcp properties of IPV4 interface
•dhcp6: Receive dhcp properties of IPV6 interface
•addresses: static address sequence of the interface
•gateway4: The IPv4 address of the default gateway
•Nameservers: DNS server address, separated by ,

Once added, your configuration file should have the following contents as shown in the following screenshot.

The address property of an interface expects a sequence entry such as [192.168.4.254/24,"20001:1::1/64"] or [192.168.1.254/24,] (refer to the netplan man page for more information).

Configure Static IP in Ubuntu

Save the file and exit. Then apply the recent network changes using the following netplan command.

sudo netplan apply

Now verify all available network interfaces again. The ens33 Ethernet interface should now be connected to the local network and have an IP address as shown in the following screenshot.

ifconfig -a

Verify Network Interface in Ubuntu

Ubuntu sets a dynamic IP address

To configure the ens33 Ethernet interface to receive an IP address dynamically via DHCP, simply use the following configuration.

network:
  ethernets:
    ens33:
      dhcp6: true
      dhcp4: true
  version: 2

Save the file and exit. Then apply the recent network changes using the following netplan command.

sudo netplan apply
ifconfig -a

From now on, your system will obtain an IP address dynamically from the router.

You can find more information and configuration options by viewing the netplan man page.

man netplan

At this point, you have successfully configured a network static IP address to your Ubuntu server.

Summarize

The above is the method of setting static IP for Ubuntu 18.04 Server introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to set static IP address in Ubuntu 14.04 under VMware
  • Detailed explanation of how to set static IP in Ubuntu 14.04
  • Ubuntu16.04 static IP address setting (NAT method)
  • How to set static IP in ubuntu
  • Ubuntu 20.04 sets a static IP address (including different versions)

<<:  Detailed explanation of Vue's caching method example

>>:  Join operation in Mysql

Recommend

Basic usage of JS date control My97DatePicker

My97DatePicker is a very flexible and easy-to-use...

Implement MySQL read-write separation and load balancing based on OneProxy

Introduction Part 1: Written at the beginning One...

A brief summary of all encapsulation methods in Vue

Table of contents 1. Encapsulation API 2. Registe...

Simple steps to configure Nginx reverse proxy with SSL

Preface A reverse proxy is a server that receives...

How to create a MySQL database and support Chinese characters

Let's first look at the MySQL official docume...

More popular and creative dark background web design examples

Dark background style page design is very popular...

Detailed explanation of viewing and setting file permissions on Mac

Preface To modify file permissions in the termina...

MySQL 8.0.12 winx64 decompression version installation graphic tutorial

Recorded the installation of mysql-8.0.12-winx64 ...

Summary of HTML horizontal and vertical centering issues

I have encountered many centering problems recent...

TimePicker in element disables part of the time (disabled to minutes)

The project requirements are: select date and tim...

Bug of Chinese input garbled characters in flex program Firefox

Chinese characters cannot be input in lower versio...