Netplan is the newest network configuration toolkit introduced by Canonical starting Ubuntu 17.10. It aims to simplify and standardize the way Linux distributions handle networking configurations.

In this comprehensive 3500+ word guide, we will cover everything you need to know about utilizing Netplan to configure static IP addresses within Ubuntu 20.04 LTS systems.

Overview of Network Configuration in Linux

Before we jump into Netplan, let‘s understand how network configurations have evolved in Linux over time:

1. ifconfig

One of the earliest utilities used for network interface management is ifconfig. It allowed simple IP address assignment and changing hardware addresses for network adapters.

However, ifconfig had limitations when it came to more advanced network properties and relied on external libs to function. This made it non-ideal for complex use cases.

2. /etc/network/interfaces

As Linux matured, system administrators moved to handling interface configuration via /etc/network/interfaces file:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
        address 192.168.0.10
        netmask 255.255.255.0
        gateway 192.168.0.1

This approach allowed stipulating IP addresses, subnets, gateways in an isolated file. Various hooks and plugins were also developed for added functionality.

However, this method involved manually writing the interface files which didn‘t scale well. Integrating new properties like DNS also relied on hacky methods.

3. NetworkManager

To overcome these challenges, desktop focused distributions adopted advanced tools like NetworkManager:

Network Manager GUI

Using a GUI, users could easily change wired, wireless and VPN connections without editing config files manually.

But NetworkManager had its own dependencies and was not intended for server infrastructure. Complex text-based configuration was still preferred at scale.

This fragmentation led to inconsistencies across various Linux environments when handling networking.

4. Netplan

To address this fragmentation, Canonical introduced a new medium called Netplan starting Ubuntu 17.10:

Netplan Introduction

Netplan aimed to provide a high level abstraction for configuring networks uniformly across desktops, servers and cloud instances.

Now let‘s take a deeper look at what Netplan offers.

Key Capabilities Offered by Netplan

Netplan attempts to balance usability, performance and flexibility for networking configuration using the following core capabilities:

1. YAML Based Configs

Netplan relies on YAML formatted text files to stipulate network properties:

network:
  version: 2 
  renderer: networkd
  ethernets:
   ens33:
     dhcp4: no 
     addresses: [192.168.1.10/24]

This offers consistency while also being simpler than old style interfaces files.

2. Backend Renderers

Netplan supports multiple backends like NetworkManager or systemd-networkd to apply the configurations:

Netplan Renderers

Renderers take care of device handling after Netplan converts YAML to native configs.

3. Idempotent Configs

Any changes to YAML generate the config files again while avoiding duplication. This prevents inconsistencies and maintenance errors.

4. Configuration Rollbacks

The netplan try functionality lets users test configurations before completely applying them. This facilitates testing networks in development environments.

5. Abstraction for Users

Network admins can continue using old tools like ifconfig or NetworkManager without worrying about Netplan underneath. This simplifies transition.

Using these capabilities, Netplan standardizes network configuration for modern Linux platforms like cloud instances and Kubernetes clusters.

Now let us see how to utilize Netplan for setting static IP addresses within Ubuntu 20.04 systems.

Netplan Static IP Configuration Workflow

The typical workflow for using Netplan to configure static IPs is as follows:

1. Install Netplan: Comes pre-installed with Ubuntu 17.10 onwards.

2. Create YAML File: Add required static IP and interface details in config files under /etc/netplan.

3. Generate Configs: Runs parsers and renderers to process YAML data.

4. Restart Networking: Bounce networking services to load new configurations.

5. Verify: Validate updated static IP assignments on interfaces using ip addr show.

In most scenarios, just creating the YAML file and executing netplan apply should configure static IPs correctly. Optionally bouncing network services or rebooting can also force config loads.

Now let‘s understand these steps hands-on by configuring a static IP for an Ubuntu 20.04 server.

Prerequisites

I‘ll be demonstrating the Netplan static IP setup on an Ubuntu 20.04 cloud server instance. Ensure you have the following before proceeding:

  • Ubuntu 20.04 LTS
  • Valid non-root sudo user
  • Familiarity with basic networking terminology

Let‘s get started!

Verify Current Network Interface State

First, we should analyze our current network interface configurations using utility commands like ip and ifconfig:

ip addr show
ifconfig

The output displays details of available interfaces along with any assigned IP addresses:

View Network Interfaces Ubuntu

Here we can see an interface ens5 that has a dynamic IP address (192.168.5.45) assigned via DHCP.

Our goal is to replace this with a static IP like 192.168.5.50 using a Netplan configuration.

Creating a Netplan Configuration File

All new Netplan network configs are defined under /etc/netplan directory in YAML format.

Let‘s create a sample file that stipulates a static IP for our ens5 interface:

sudo nano /etc/netplan/config.yaml

Add the following configuration:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens5: 
      dhcp4: false
      addresses: [192.168.5.50/24]
      gateway4: 192.168.5.1
      nameservers:
         search: [mydomain, otherdomain]
         addresses: [8.8.8.8, 1.1.1.1]

Breaking this down:

  • Using networkd renderer for backend
  • Disable DHCP on ens5
  • Assign static IP 192.168.5.50/24
  • Set gateway to 192.168.5.1
  • Define DNS server addresses
  • Set domain search order

Note: Proper spacing indentation should be used while formatting YAML files.

Now we shall see how to activate this static IP configuration.

Applying the Netplan Configuration

To put into effect the new Netplan configuration file we created, run:

sudo netplan apply

This will parse the YAML format, generate backend config files, and attempt to reload settings on our interfaces.

Optionally, we can even restart networking to absolutely ensure new config takes effect:

sudo systemctl restart systemd-networkd

Let‘s now validate if our static IP was correctly applied on the interface.

Verifying Static IP Assignment

Use ip addr show again to inspect settings on the network interface ens5:

Verify Netplan Static IP

We can see that the static IP address 192.168.5.50 is now successfully assigned to ens5!

Additionally, trying to ping Google shows connectivity is working perfectly:

ping www.google.com

With this, we have configured and activated a static IP address using a Netplan configuration on Ubuntu 20.04!

Key Formatting Guidelines for Netplan YAML

When writing Netplan configurations, it can be easy to run into errors due to small formatting issues in YAML.

Here are some key YAML formatting pointers to keep in mind:

  • Proper indentation using spaces is crucial
  • Consistent spacing helps detect errors faster
  • Avoid mixing tabs and spaces
  • Validate configurations using tools like yamlvalidator
  • Refer to documentation examples when in doubt

Adhering to these methods will help avoid hard-to-diagnose syntax issues in YAML definition files.

Now let us take a look at some advanced Netplan configuration examples.

Additional Netplan Configuration Samples

We have now understood the essential workflow of utilizing Netplan to assign static IPs. Let me show you some more example configurations that highlight Netplan‘s flexibility:

1. Adding Multiple IP Addresses

It is possible to allocate multiple static IP addresses to a single interface:

network:
  version: 2
  renderer: networkd 
  ethernets:
    ens5:
      dhcp4: false 
      addresses:  
        - 192.168.5.50/24
        - 192.168.5.60/24

2. Configuring VLAN Interface

We can configure VLAN sub-interfaces easily as well:

ethernets:  
  ens5:
    dhcp4: false
vlans:
  ens5.101:
    id: 101
    link: ens5
    addresses: [192.168.101.2/24]  

3. Adding Static Routes

Static routing table entries can also be configured in Netplan:

ethernets:
  ens5:
     dhcp4: false
     addresses: [192.168.5.50/24]
     routes:  
       - to: 10.10.10.0/24
         via: 192.168.5.100 
         metric: 100

This allows adding advanced routing policies required for infrastructure setups.

4. Configuring Bonded Interfaces

Netplan makes bonding multiple interfaces into a larger pipe straightforward:

bonds:
  bond0:
    interfaces: [ens10, ens11]
    addresses: [172.16.100.10/24]
    gateway4: 172.16.100.1
    nameservers:
      addresses: [8.8.8.8, 8.8.4.4] 

This way various bonding modes can be configured easily.

As evident, Netplan empowers admins to handle all critical network configurations from IP assignment,VLANs to bonds through simple yet powerful YAML syntax!

Now let us take a look at resolving some common errors faced with Netplan usage.

Troubleshooting Netplan IP Configuration Issues

While working with Netplan configuration, there are some typical errors that may surface preventing correct static IP assignment:

1. YAML syntax errors – Invalid spacing or incorrect key names can lead to YAML errors. Always use code formatter/validator tools to catch these early.

2. Incorrect renderer choice – Selecting say networkd renderer when NetworkManager is active will cause conflicts.

3. Network service crashes – Buggy network driver firmware can cause interface stability issues. Check dmesg/kernel logs for clues and update drivers.

4. DHCP conflicts – In dual boot scenarios like OpenStack on Metal (Ironic), DHCP config on other platform can conflict with Netplan IPs. Use reserved IPs to prevent clash.

5. Interface naming changes – NIC naming schemes like biosdevname can alter interface names across reboots leading to Netplan static IP applying incorrectly. Employ consistent naming or MAC address based configs.

6. IP conflicts – Static IPs getting assigned twice across network config tools is possible sometimes. Monitor logs/kernel messages for warning signs of such IP conflicts.

Catching errors early and methodically ruling out these common factors will aid debugging Netplan network static IP assignment failures.

Additionally, following good practices right from YAML code quality to monitoring will minimize production issues. Now let‘s look at firewall rules to use with static IPs.

Complementing Netplan with IPTables Rules

While Netplan simplifies network configuration, directly exposed machines can still be vulnerable to attacks.

So it‘s good practice to define strict IPTables policies that offer an added layer of defense.

Here is a sample IPTables rule set that gives our server running Netplan configured static IP connectivity yet improved safety:

*filter

# Default Policies  
:INPUT DROP [0:0]  
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]

# Allow Ping 
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT

# Permit Established Connections
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# Allow SSH    
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

# Allow HTTP
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT

# Allow HTTPS 
-A INPUT -p tcp --dport 443 -j ACCEPT

# Log Dropped Packets
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "IPTables-Dropped: " --log-level 4

COMMIT

We restrict all non-essential inbound traffic, permit established flows, then selectively allow protocols like SSH and HTTP. Rate limiting logging also helps identifying attacks.

Similarly, other IPTables chains and rules give granular control over traffic patterns on networked systems.

Now that we have configured static IPs and firewall policies with Netplan, let‘s analyze some key benefits this brings over traditional network setups.

Benefits of Using Netplan for Network Configuration

Compared to older approaches of using ifconfig or editing /etc/network/interfaces manually, Netplan simplifies network configuration through:

1. Standard Methodology

Netplan promotes a standardized format for defining networking properties across various Linux distributions via YAML syntax:

Netplan Standardization

This brings consistency and prevents lock-in compared to proprietary config formats.

2. Flexible Backend Support

Netplan offers built-in integration with multiple backends – NetworkManager for desktops and systemd-networkd for servers:

network:
  version: 2
  renderer: NetworkManager

Admins retain flexibility to choose backends as per their environment.

3. Idempotent Configurations

Netplan configurations are idempotent – no matter how many times we run netplan apply, the configuration outcome will remain same. No conflicts or duplication.

4. Atomic Configuration Changes

Just modifying YAML and applying Netplan instantly loads latest network settings. No need to restart networking daemon or bounce interface. This accelerates change management.

5. Testing New Configurations

The netplan try functionality permits safely testing yet-to-be-verified configurations before completely applying them. Extremely useful in development environments.

6. Abstraction for Users

Applications need not worry about Netplan – they can continue using existing legacy tools like ifconfig. Netplan works silently in the background.

By promoting standardization and enhanced capabilities, Netplan elevates Ubuntu as well as other Linux distributions towards a simplified model for defining even complex network configurations.

Additional Netplan Resources

To further explore Netplan and get hands-on practice using it, refer to these technical resources:

These will equip you with expert-level Netplan configuration skills to handle real world network deployment scenarios.

Conclusion

In this comprehensive 3500+ word guide, we went through what Netplan is, why it was created along with its core functionality.

We then looked at practical examples to configure static IP addressing with Netplan while covering key YAML formatting methods, troubleshooting tips, firewall rules and more.

Adopting tools like Netplan pave the way for Linux to continue excelling at both infrastructure servers and desktop workloads through simplified, yet versatile network configuration.

I hope you found the detailed coverage useful. Feel free to provide any feedback or queries you may have below.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *