i just start to use the Ubuntu 18.04. When i try to set up the static IPs on that VM. i can't access the internet. But if i switch to use the gateway as the DHCP device, it works. Any idea what went wrong?

Attached is a screenshot for the ouput of route -n and netplan configuration fileenter image description here

Here is the output if i switch to use the gateway for DHCP:

   root@ubuntu:~# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
  version: 2
  renderer: networkd
#      addresses: []
      dhcp4: yes
#      nameservers:
#        addresses: []
#      routes:
#      - to:
#        via:
#        on-link: true
#      gateway4:
      dhcp4: no
      addresses: []

root@ubuntu:~# ip route
default via dev ens6 proto dhcp src metric 100 dev ens7 proto kernel scope link src dev ens6 proto dhcp scope link src metric 100 
root@ubuntu:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    100    0        0 ens6   U     0      0        0 ens7 UH    100    0        0 ens6
New contributor
Chao Yuan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Change the

adresses: []


adresses: []

/32 indicates that it is a subnet with only in the network, with no access to any other IP addresses. Thus your computer has no idea of how to reach your configured GW.

  • i tried to change to /24, but it still does't work.. – Chao Yuan Dec 4 at 11:44
  • Update your question with the output of ip route with the correct configuration. – vidarlo Dec 4 at 11:46
  • just updated the output – Chao Yuan Dec 4 at 12:36
  • 1
    The 'ip route' information shown corresponds to a dhcp-provided route, not to a statically configured route. This is clearly inconsistent. Listing /32 in the addresses is clearly wrong, switching this to /24 reliably fixes this problem. – slangasek Dec 5 at 8:43
  • Indeed. Please provide output of ip route when you have the corrected configuration in place, not DHCP. – vidarlo Dec 5 at 8:46

Your Answer

Chao Yuan is a new contributor. Be nice, and check out our Code of Conduct.

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.