I'm a bit confused on how to configure my Ubuntu 18 server with two NICS using Netplan. Each NIC is on a separate subnet. They are directly connected to separate router interfaces on the router (this is a SMB router so each interface is configurable as a different subnet).

So for example on my server I have two NICs named below with the appropriate information they need:

eth0 - 192.168.2.2/24
       gateway - 192.168.2.1
       dns - 192.168.2.1

eth1 - 192.168.22.2/24
       gateway - 192.168.22.1
       dns - 192.168.22.1

I was playing around with the source routing example at netplan.io, but its not quite what I want. I don't want to route all outgoing traffic through just one interface. I need to be able to route traffic out of eth0 through eth0's gateway and I need to be able to route traffic out of eth1 through eth1's gateway.

I'll let the router handle routing between the two subnets via firewall rules. I just need Neplan to play nice with my two NICs and let me setup two subnets each with its own gateway information. Any ideas?

  • Looks like this question for serverfault.com community. – mature Nov 13 at 17:22
  • Ok, I'll try over there. Thanks! – Biggen Nov 14 at 2:04

Edit: Unfortunately, my own answer is incorrect after further testing.

The way the below is setup, it's still routing all traffic destined for an external IP (internet traffic) through the eth1 device which is not want I wanted. I needed traffic routed out of each NIC respectively. So, if eth1 needs to get out to the internet, it needs to send those packets out of the gateway that is directly connected to eth1. Likewise, if eth2 needs to get out to the internet, then it also needs to send its own packets to the directly connected gateway that is connected to eth2.

I ended up dumping Netplan and went back to standard networking tools (ifconfig and /etc/network/interfaces) and setup a routing table/policy that does want I want. I'll never go back to Netplan. They made it way too complicated for what should be simple stuff. I spent days trying to get Netplan to work only to give up on that abortion of an abstraction layer. I'm leaving my incorrect answer below for documentation.

**** Wrong answer below ****

So it appears this seems to work:

ethernets:
eth0:
  addresses:
    - 192.168.2.2/24
  routes:
   - to: 0.0.0.0/0
     via: 192.168.2.1
     metric: 100
     table: 101
  routing-policy:
   - from: 192.168.2.0/24
     table: 101
eth1:
  addresses:
    - 192.168.22.2/24
  gateway4: 192.168.22.1
  nameservers:
    addresses: [192.168.22.1]

I was attempting to list a gateway4 for each NIC stanza and that was incorrect from what I've been reading. One must setup static routes to 0.0.0.0/0 for the other NICs/subnets attached directly to different gateways. You only need one gateway4 listing if you do it this way.

Hope this helps someone else in the future (or me when I need to set this up again a few years later and will have forgotten it).

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.