How to setup two dhcp network interfaces with netplan on Ubuntu 18.04 server.

3,896 views
Skip to first unread message

Petar Kozić

unread,
Jun 1, 2018, 9:03:02 AM6/1/18
to gce-discussion
Hi Folks,
I have some problem with netplan and Ubuntu 18.04 server.

I have two NIC, one private and one public. Both NIC have dhcp and both DHCP I'm control.

I have problem with default route.

First interface ens18 need to have public IP with reserverved IP in DHCP. That's works. An IP is 213.133.xxx.xxx
Second interface ens19 need to have private IP with also reserved IP in DHCP. That's works. An IP is 10.10.10.xxx

Both interface get IP over DHCP regulary but default route is problem.
I can't access on that machine from public because default route Netplan set on this private interface.

If I change something in netplan, as add nameserver or delete nameserver and apply configuration and reboot server, somethimes ens18 public interface was boot first than I can access from public,

How can I setup persistent default interface and route in netplan.

My config in netplan now is:


network:
   version: 2
   renderer: networkd
   ethernets:
      ens18:
          dhcp4: yes
          dhcp6: no
    ethernets:
       ens19:
           dhcp4: yes
           dhcp4: no


Thank you in advanced.

Mathieu Trudel-Lapierre

unread,
Jun 1, 2018, 1:43:22 PM6/1/18
to gce-discussion
On Friday, June 1, 2018 at 9:03:02 AM UTC-4, Petar Kozić wrote:
[...] 
First interface ens18 need to have public IP with reserverved IP in DHCP. That's works. An IP is 213.133.xxx.xxx
Second interface ens19 need to have private IP with also reserved IP in DHCP. That's works. An IP is 10.10.10.xxx

Both interface get IP over DHCP regulary but default route is problem.
I can't access on that machine from public because default route Netplan set on this private interface.
 
[...]

network:
   version: 2
   renderer: networkd
   ethernets:
      ens18:
          dhcp4: yes
          dhcp6: no
    ethernets:
       ens19:
           dhcp4: yes
           dhcp4: no

The issue is that networkd will bring up both networks, and both will have a default gateway set, and both will be at the same metric.

Netplan does not currently allow you to skip setting the route on one interface, but you can configure networkd separately to tell it to do this, by basing the config on what netplan has already generated.

I have copied the commands below. Here I am assuming that ens19 is the "secondary" interface for which you do not want a default gateway set -- note that to do this successfully, it also needs to happen before rebooting with the new interface (or you can copy part of the config, omit the MACAddress= line, etc. so that it's generic enough that a new interface will be matched).

sudo cp /run/systemd/network/10-netplan-ens19.network /etc/systemd/network
sudo vi /etc/systemd/network/10-netplan-ens19.network

Then add under [DHCP]:

UseRoutes=false            # if you don't want to apply any routes from DHCP

RouteMetric=200        # any number above 100 if you want the routes applied, but that they are less preferred.

If you don't have the file yet (ie. you have not attached the interface yet) then you could copy the contents of another interface set for DHCP, and remove MACAddress=.

In general, the file should look something like this:

[Match]
Name=interfacename

[Network]
DHCP=ipv4

[DHCP]
UseMTU=true
RouteMetric=200    # or UseRoutes=false, as you prefer.


Digil (Google Cloud Platform Support)

unread,
Jun 1, 2018, 8:29:03 PM6/1/18
to gce-dis...@googlegroups.com
With regards to a GCP virtual machine instance, you might need to check this documentation on DHCP's behavior over multiple network interfaces. As per the documentation, you could be able to change the default route by configuring the policy routing.

In addition towards the valuable suggestion made by the other community member, it would be a prudent decision, if you post this concern in 'serverfault.com' as well. In 'serverfault' community, you have access to a large community of enthusiasts and experts to share ideas with and get support from. While posting the concern, make sure to include all relevant details and error messages which would help the community troubleshoot.  

Reply all
Reply to author
Forward
0 new messages