Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ThomasLeister/640812441505447ba8f19f85314fbf5b to your computer and use it in GitHub Desktop.

Select an option

Save ThomasLeister/640812441505447ba8f19f85314fbf5b to your computer and use it in GitHub Desktop.
Ubuntu netplan config for secondary ip address

In case there's already a DHCP config for netplan for the private IP address:

File: /etc/netplan/50-cloud-init.yaml

Contents:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}

network:
    ethernets:
        ens3:
            addresses: []
            dhcp4: true
            optional: true
    version: 2

To add a secondary, public IP address:

Create /etc/netplan/60-static.yaml

Contents:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      addresses:
        - 148.251.64.58/24

Then apply config:

netplan try

@RaJiska

RaJiska commented Aug 15, 2018

Copy link
Copy Markdown

Thanks, exacly what I needed. Gotta get familiar with netplan now Ubuntu 18 uses it by default 👍

@sabretus

sabretus commented Nov 9, 2018

Copy link
Copy Markdown

Thanks! For me it works only after installing latest version of netplan.io (0.40.1) package from "proposed" repo.

@galaczi

galaczi commented Nov 13, 2019

Copy link
Copy Markdown

Thanks, worked on my Vultr droplet. Tip for Vultr people: you have to reboot from their dashboard (not console) first and then change the config.

@joxerg

joxerg commented Mar 5, 2020

Copy link
Copy Markdown

Working perfect in Ubuntu 18.04 VPS.
One question...for adding more IPs we should add new .YAML files or what would be the way?
Thank you,

@ThomasLeister

ThomasLeister commented Mar 6, 2020

Copy link
Copy Markdown
Author

@miesismore you could add another file, or just add the new IP address in the same file:

addresses: 
  - 148.251.64.58/24
  - 148.251.64.59/24

@ThomasLeister

Copy link
Copy Markdown
Author

@miesismore for more information have a look at https://netplan.io/reference (there's also an example page)

@joxerg

joxerg commented May 16, 2020

Copy link
Copy Markdown

@miesismore you could add another file, or just add the new IP address in the same file:

addresses: 
  - 148.251.64.58/24
  - 148.251.64.59/24

Thank you Thomas!!

@ontzuevanhussen

Copy link
Copy Markdown

How to add multiple IP from 1 interfaces?

@yitsup2u

Copy link
Copy Markdown

Thanks, worked on my Vultr droplet. Tip for Vultr people: you have to reboot from their dashboard (not console) first and then change the config.

@galaczi save my day. Thanks for the good tip!

@baydakovss

Copy link
Copy Markdown

On Ubuntu 20.04, I had to add 'dhcp4: true' on second file, otherwise my first address is overwritten

netplan get
network:
  version: 2
  renderer: networkd
  ethernets:
    hotplug:
      match:
        name: "ens*"
      dhcp4: true
    ens4:
      addresses:
      - "10.255.0.252/32"
      **dhcp4: true**

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment