Score:1

Proper Netplan configuration for dual nic dhcp/static IP setup

jp flag

I am having trouble getting a good mental map of how to configure netplan for a common network setup we are seeing.

  1. Two network interfaces
  2. Network interface A, connected to the internet on 10.0.1.40/24, assigned via DHCP
  3. Network interface B, connected to a network on 192.168.50.1/24 via 192.168.50.1/24 assigned a static IP (192.168.50.20/24)

Something like:

network:
  version: 2
  ethernets:
    eno1:
      dhcp4: yes
    enp6s0f1:
      dhcp4: no
      addresses:
        - 192.168.50.20/24
      gateway4: 192.168.50.1

Seems like it should work, but after applying this, it seems that either

  1. The server loses internet access and somehow the static IP address has a lower priority than the dhcp interface? Is that possible?
  2. The server has network access, but cannot communicate with any of the devices on the 192.168.50.1/24 network (possibly using the wrong ethernet card).

FWIW, removing the non-dhcp interface from netplan and just using sudo ip addr add 192.168.50.20/24 dev eno2 "just works", however doesn't persist across reboots.

The final route table looks like this:

$ ip route
default via 192.168.50.1 dev enp6s0f1 proto dhcp src 192.168.50.11 metric 100 
default via 10.1.10.1 dev eno1 proto dhcp src 10.1.10.178 metric 100 
10.1.10.0/24 dev eno1 proto kernel scope link src 10.1.10.178 
10.1.10.1 dev eno1 proto dhcp scope link src 10.1.10.178 metric 100 
192.168.50.0/24 dev enp6s0f1 proto kernel scope link src 192.168.50.11 
192.168.50.1 dev enp6s0f1 proto dhcp scope link src 192.168.50.11 metric 100 

In this case, the 192.168.50.1 is the static network that does not have public internet access, but the 10.1.10.1 route is not used.

mpboden avatar
do flag
Can you update your question with the output of `ip route` when using this Netplan configuration that you’re having a problem with?
killachaos avatar
jp flag
The output of `ip route` has been added.
mpboden avatar
do flag
The interfaces and IP addresses in the output of `ip route` aren't matching with what you've described. You're configuring `eno1` and `eno2` yet `ip route` is showing `eno1` and `enp6s0f1`. Could you please edit question to include the output of `ip a` and `lshw -C network`?
killachaos avatar
jp flag
I've updated the question match the results of the test setup I had to deliver the results I've shown. Conceptually the problem is still the same - it looks like netplan assigns a default route to the secondary network and it isn't clear how to disable that.
Score:1
do flag

The way you have your Netplan YAML file configured now, you have two default routes setup. The output of ip route indicates that. The first default route on eno1 is given to you from the DHCP server. The other on enp6s0f1 is being defined in your YAML file. Furthermore, each default route has a metric of 100, so one default route isn't getting a priority over the other.

You have two options...either assign a different metric for eno1 so that it takes priority over enp6s0f1, or remove the gateway4 stanza for enp6s0f1. Since you indicate that all internet traffic should go out eno1 and enp6s0f1 is strictly for the 192.168.50.0/24 subnet, just remove the gateway4 stanza as follows:

network:
  version: 2
  ethernets:
    eno1:
      dhcp4: yes
    enp6s0f1:
      dhcp4: no
      addresses:
        - 192.168.50.20/24
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.