0

I am new to the netplan on Ubuntu 18.04, just discovered it exists today. I have an interface that I am trying to add to create a floating IP on google cloud. It is based on this example: https://cloud.google.com/solutions/best-practices-floating-ip-addresses#implementing_option_4

I tested the example, and it works, but now I try to do the same on ubuntu, and I don't know how to convert this:

cat << EOF >> /etc/network/interfaces
auto eth0:0
iface eth0:0 inet static
    address 10.190.1.1
    netmask 255.255.255.255
EOF

to netplan.

The output for ls /etc/netplan is '50-cloud-init.yaml'. and the output for cat /etc/netplan/*.yaml is:

network:
    version: 2
    ethernets:
        ens4:
            dhcp4: true
            match:
                macaddress: 42:01:0a:8e:00:3e
            set-name: ens4

my ifconfig:

# ifconfig  ens4
ens4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1460
    inet 10.142.0.62  netmask 255.255.255.255  broadcast 0.0.0.0
    inet6 fe80::4001:aff:fe8e:3e  prefixlen 64  scopeid 0x20<link>
    ether 42:01:0a:8e:00:3e  txqueuelen 1000  (Ethernet)
    RX packets 9430  bytes 1635180 (1.6 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 13383  bytes 1513428 (1.5 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

What is the equivalent of what he said to put in the file, for netplan?

  • Are you using Ubuntu Desktop or Ubuntu Server? When you say "floating IP", do you mean that you want a dynamic IP address, or a static IP address? Is eth0 or ens4 your ethernet device? Do you have multiple machines where you want failover? – heynnema Dec 16 '18 at 16:51
  • I am using google cloud platform. The vm was generated with 'ens4' ethernet device. When creating the vm, I choose static ip (10.142.0.62), /etc/netplan/50-cloud-init.yaml was autogenerated. What I want to do is to add the floating ip as explained in option#4 in the link that is in the question. – justadev Dec 16 '18 at 17:05
0

First, your /etc/network/interfaces is incorrect. You can't ask for "auth eth0" and then set a static address later.

auto eth0:0
iface eth0:0 inet static
    address 10.190.1.1
    netmask 255.255.255.255

If I understand what you're trying to do, then this netplan .yaml snippet is the minimum that you need...

network:
  version: 2
  renderer: networkd
  ethernets:
    ens4:
      dhcp4: false
      dhcp6: false
      addresses:
        - 10.142.0.62/24 # server #1, 10.142.0.63/24 for server #2
        - 10.190.1.1/24  # floating IP in keepalived.conf
      gateway4: 10.142.0.1

Assumptions:

  • only one ethernet interface, ens4:
  • if you have a multiport ethernet card, my .yaml needs additional code
  • Ubuntu Server environment
  • not using NetworkManager
  • only one ethernet interface, yes. ubuntu server, and not using NetworkManager as much as I know (how do I check?) The /etc/network/interfaces in the example is copy-paste from google official doc example in the OP. I tested it and it worked. What I don't understand in your answer is where did the floating IP disappeared (10.190.1.1). This is an explanation about floating/virtual ip docs.oracle.com/cd/E37670_01/E41138/html/… – justadev Dec 16 '18 at 17:57
  • So there suppose to be two addresses from the ens4 nic: one static (10.142.0.62) and one virutal/floating (10.190.1.1) that is used for failover. – justadev Dec 16 '18 at 17:59
  • @justadev No, from my understanding, the "floating/virtual IP" is configured in the keepalived .conf files. My .yaml snippet assigns an IP to the hardware in server #1. If 10.142.0.62 is your floating/virtual IP, that needs to go in keepalive, and server addresses could be... say... 10.142.0.2 and 10.142.0.3... and my .yaml would require a simple edit for those addresses on each server. – heynnema Dec 16 '18 at 18:07
  • @justadev slight edit in my answer. – heynnema Dec 16 '18 at 18:16
  • thanks, the code edit looks good, I will try, but in yoru comment you mixed things up (10.190.1.1 is the floating point, not 10.142.0.62). Question: can 10.142.0.62 be assigned by dhcp rather than to be statically declared in the config file? Reason I am asking is because conf file is saved on disk, so if in the future I will create disk snapshot and restore it can cause networking issue. no? – justadev Dec 16 '18 at 19:26
0

Seems like you cannot create eth0:0

Check this out: https://netplan.io/examples

Multiple addresses on an interface
network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
     addresses:
       - 10.100.1.38/24
       - 10.100.1.39/24
     gateway4: 10.100.1.1

Multiple gateways and multiple ips

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
     addresses:
       - 9.0.0.9/24
       - 10.0.0.10/24
       - 11.0.0.11/24
     #gateway4:    # unset, since we configure routes below
     routes:
       - to: 0.0.0.0/0
         via: 9.0.0.1
         metric: 100
       - to: 0.0.0.0/0
         via: 10.0.0.1
         metric: 100
       - to: 0.0.0.0/0
         via: 11.0.0.1
         metric: 100
  • You may want to explain how to configure netplan to make use of the second IP address/alias? – Thomas Dec 16 '18 at 12:35
  • You should add the relevant part to your answer, not in the comment. – Thomas Dec 16 '18 at 13:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.