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).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens6:
#      addresses: [46.16.78.229/24]
      dhcp4: yes
#      nameservers:
#        addresses: [46.16.78.1]
#      routes:
#      - to: 0.0.0.0/0
#        via: 46.16.78.1
#        on-link: true
#      gateway4: 46.16.78.1
    ens7:
      dhcp4: no
      addresses: [10.14.160.15/24]

root@ubuntu:~# ip route
default via 46.16.78.1 dev ens6 proto dhcp src 46.16.78.29 metric 100 
10.14.160.0/24 dev ens7 proto kernel scope link src 10.14.160.15 
46.16.78.1 dev ens6 proto dhcp scope link src 46.16.78.29 metric 100 
root@ubuntu:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         46.16.78.1      0.0.0.0         UG    100    0        0 ens6
10.14.160.0     0.0.0.0         255.255.255.0   U     0      0        0 ens7
46.16.78.1      0.0.0.0         255.255.255.255 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: [46.16.78.229/32]

to

adresses: [46.16.78.229/24]

/32 indicates that it is a subnet with only 46.16.78.229 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.