Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Ubuntu - Multiple Network CIDR Issue

The output of

sudo ip addr

...started as follows:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether a0:36:bc:bd:09:c4 brd ff:ff:ff:ff:ff:ff
    altname enp7s0
    inet 192.168.0.11/21 brd 192.168.7.255 scope global eno1
       valid_lft forever preferred_lft forever
    inet 192.168.0.11/16 metric 100 brd 192.168.255.255 scope global dynamic eno1
       valid_lft 86365sec preferred_lft 86365sec
    inet6 2a00:23c6:e380:e01:a236:bcff:febd:9c4/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 298sec preferred_lft 118sec
    inet6 fe80::a236:bcff:febd:9c4/64 scope link 
       valid_lft forever preferred_lft forever

As you can see from the output, my eno1 interface had been assigned both of the following network CIDRs:

  • 192.168.0.11/21
  • 192.168.0.11/16

This was an issue for me because 192.168.0.11/16 is such a broad CIDR, that it covers the entire range of 192.168.0.0 to 192.168.255.155, which meant that even when I connected to my work VPN, which has a bunch of servers on the 192.168.10.0/24 CIDR, I could not connect to it, because my traffic was going to the home network gateway to be routed, instead of over the tun0 VPN interface.

Running this command to remove the IP address resolved my networking issues.

ip address del 192.168.0.11/16 dev eth0

Source Of The Problem - Bad Netplan Config

In the end, it turned out that my /etc/netplan/current.yml file had dhcp4: yes, instead of dhcp4: no whilst also specifying the static IP address. E.g.

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
      eno1:
          dhcp4: yes
          dhcp6: yes
          addresses:
            - 192.168.0.11/21
          routes:
            - to: default
              via: 192.168.0.1
          nameservers:
            addresses:
              - 192.168.0.222

... when it should have been:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
      eno1:
          dhcp4: no
          dhcp6: yes
          addresses:
            - 192.168.0.11/21
          routes:
            - to: default
              via: 192.168.0.1
          nameservers:
            addresses:
              - 192.168.0.222

References

Last updated: 1st June 2024
First published: 22nd March 2023

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch