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

How to install the latest version of docker using deepin apt command

Step 1: Add Ubuntu source Switch to root su root ...

Detailed tutorial on installing and configuring MySql5.7 on Ubuntu 20.04

Table of contents 1. Ubuntu source change 2. Inst...

Tutorial on how to install and use Ceph distributed software under Linux

Table of contents Preface 1. Basic Environment 1....

Detailed tutorial on building nextcloud private cloud storage network disk

Nextcloud is an open source and free private clou...

Docker image creation Dockerfile and commit operations

Build the image There are two main ways to build ...

Introduction to the use of html base tag target=_parent

The <base> tag specifies the default address...

Tutorial on downloading, installing, configuring and using MySQL under Windows

Overview of MySQL MySQL is a relational database ...

Nginx external network access intranet site configuration operation

background: The site is separated from the front ...

Install mysql 5.6 from yum source in centos7.4 system

System environment: centos7.4 1. Check whether th...

Introduction to Linux system swap space

Swap space is a common aspect of computing today,...

How to filter out duplicate data when inserting large amounts of data into MySQL

Table of contents 1. Discover the problem 2. Dele...

Centos6.9 installation Mysql5.7.18 step record

Installation sequence rpm -ivh mysql-community-co...

Example analysis of the usage of the new json field type in mysql5.7

This article uses an example to illustrate the us...

js, css, html determine the various versions of the browser

Use regular expressions to determine the IE browse...