0%

0/1 Lessons

Introduction to Linux Server Operating Systems

• 30min

0 / 3 lessons complete

Linux Server Installation and Lab Setup

• 23min

0 / 6 lessons complete

Working with the Linux Command Line Interface

• 1hr 30min

0 / 12 lessons complete

User and Group Management

• 44min

0 / 7 lessons complete

Linux Storage

• 30min

0 / 6 lessons complete

Linux Administration Basics

• 53min

0 / 8 lessons complete

Linux Networking

• 47min

0 / 8 lessons complete

Course Conclusion

• 5min

0 / 1 lessons complete

Configuring Network Interfaces with Netplan

Instructions

Q&A (0)

Notes (0)

Resources (0)

Saving Progress...

Resources

There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

In this lesson, you'll learn how to configure a static IP address on a Linux server with netplan. This is an essential skill for network management and server configuration, as it ensures that your server always has the same IP address, facilitating reliable and consistent access.

This is particularly important in environments where the server hosts websites, provides remote access, or runs network services. Unlike dynamic IP addresses assigned by DHCP (Dynamic Host Configuration Protocol), a static IP does not change, making it easier to set up DNS (Domain Name System) and firewall rules.

Understanding IP Address Configuration

Every device on a network, like a local network or the internet, requires an IP address to communicate. While DHCP can be used to automatically assign an IP address, a static IP address is manually configured and remains constant. This is particularly useful for servers that need to maintain the same address for consistent access or services.

Configuring a Static IP Address

To set a static IP address, you need to edit the network configuration files. The process can vary slightly depending on the Linux distribution and the network manager in use. In this example, we'll focus on Ubuntu Server, which is a popular choice for many server environments.

  1. Identifying the Network Interface: First, you need to identify the network interface you want to configure. You can do this using the ip a command, which lists all network interfaces and their current configuration.bash
ip a

Editing the Netplan Configuration File: Ubuntu Server uses Netplan for network configuration. You'll find the configuration file in /etc/netplan/. The filename can vary, but it usually ends with .yaml. If I ls or ll the /etc/netplan/ directory I see the following file:

paulh@ubuntu-server:~$ ls /etc/netplan/
00-installer-config.yaml

Open the file with a text editor, like nano:

sudo nano /etc/netplan/00-installer-config.yaml

Replace 00-installer-config.yaml with the actual filename in your system.

My yaml config file contains the following configuration to enable DHCP for IPv4:

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s3:
      dhcp4: true
  version: 2

Setting the Static IP: In the Netplan configuration file, you'll see configurations under the ethernets section. Modify the settings for your interface to something like this:

I have updated the netplan below by removing gateway4 and adding a routes entry since gateway4 is now depreciated in netplan

network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: no
      addresses: [192.168.1.153/24]
      routes:
        to: 0.0.0.0/0
        via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

Replace enp0s3 with your network interface name. The addresses field is where you set your desired static IP (in this case, 192.168.1.100) and the subnet mask (/24). The gateway4 is your network's gateway, and nameservers are the DNS servers.

Applying these configurations will disconnect your SSH session because you're potentially changing your IPv4 address. Reconnect after applying to the newly assigned static IP, if that doesn't work, go back to VirtualBox and connect with the VirtualBox console by double clicking the VM.

Applying the Changes: After editing the configuration file, apply the changes with:

sudo netplan apply

This will apply the new network configuration. Because I am SSH'd into the VM, I get disconnected while the apply is in progress. I need to reconnect to the new IP address like so:

ssh paulh@192.168.1.153

When I run this command, I will get the authenticity verification prompt again. Enter yes to connect:

The authenticity of host '192.168.1.153 (192.168.1.153)' can't be established.
ED25519 key fingerprint is SHA256:cmrP54cZeg7Xy+dH9eUgeH94ppMPDM8FnfEwFZD/EvM.
This host key is known by the following other names/addresses:
    C:\Users\BlackIce/.ssh/known_hosts:13: 192.168.1.152
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments