netplan configuration on Ubuntu 17.04 virtual machine
For me removing gateway4
from configuration did the trick. With it configured I was also not able to ping internet.
Here is my netPlan config if it can help others.
Note: enp0s3 is for ssh via port forwarding and enp0s8 for static ip
network:
ethernets:
enp0s3:
addresses: []
dhcp4: true
optional: true
enp0s8:
addresses: [192.168.10.20/24]
dhcp4: no
dhcp6: no
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
version: 2
I found this problem doing exactly the same thing this afternoon. Somehow managed to figure it out and netplan finally created only 1 default route through the NAT interface of my VM. In my case, both IP's were 192.168.56.101 (host-only) and 10.0.3.x/24 (NAT dhcp4). I'm using this netplan file:
network:
version: 2
renderer: networkd
ethernets:
enp0s8:
dhcp4: yes
dhcp6: yes
routes:
- to: 0.0.0.0/0
via: 10.0.3.2
metric: 0
enp0s3:
dhcp4: no
dhcp6: no
addresses: [192.168.56.101/24]
routes:
- to: 192.168.56.1/24
via: 192.168.56.1
metric: 100
With this I have only one default route, and it's using the NAT so it can reach the internet through my host.
Output of ip r
default via 10.0.3.2 dev enp0s8 proto dhcp src 10.0.3.15 metric 100
10.0.3.0/24 dev enp0s8 proto kernel scope link src 10.0.3.15
10.0.3.2 dev enp0s8 proto dhcp scope link src 10.0.3.15 metric 100
192.168.56.0/24 dev enp0s3 proto kernel scope link src 192.168.56.10