Monday, May 17, 2021

[Netplan/Ubuntu/Azure] Create a gateway for second NIC on Azure VM with netplan

I have an Azure VM running Ubuntu 18.04 LTS with two NICs. By default, Azure creates a gateway for the first NIC and not the second NIC. I want to create a gateway for the second NIC as well and I have been using ip commands to do this, specifically:

ip route add default via 11.0.0.1 dev eth1 table 11 ip rule add from 11.0.0.7 table 11 ip route add default via 11.0.0.1 dev eth1 proto dhcp src 11.0.0.7 metric 101 

I want to use cloud-init and netplan to do this instead of ip commands to do this but I have had no luck getting it to work. The netplan I am currently using is:

network: version: 2 ethernets: eth0: dhcp4: yes routes: - to: 0.0.0.0/0 via: 11.0.0.1 table: 10 routing-policy: - from: 11.0.0.6/32 table: 10 eth1: dhcp4: yes routes: - to: 0.0.0.0/0 via: 11.0.0.1 table: 11 routing-policy: - from: 11.0.0.7/32 table: 11 

I never worked with netplan or networking in general before so I am not able to debug it correctly. I followed netplan documentation, blog posts and stackoverflow answers with different variations of gateway4, routes and routing-policy parameters but no luck. Can someone please help me with the correct netplan configuration? Thanks!



No comments:

Post a Comment