-1

The command ifup from ifupdown fails when using some mask for static configuration on Ubuntu 20.04 LTS.

Example of working configuration

$ cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto enp1s0
iface enp1s0 inet static
    address         172.31.1.102
    netmask         255.255.255.0

Example of non-working configuration

$ cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto enp1s0
iface enp1s0 inet static
    address         172.31.1.102
    netmask         255.255.255.8

The error

$ sudo ifup enp1s0
Error: any valid prefix is expected rather than "172.31.1.102/255.255.255.8".
ifup: failed to bring up enp1s0
4
  • 1
    255.255.255.8 is not a valid netmask – Swisstone May 14 '20 at 14:10
  • "Computers that belong to a subnet are addressed with an identical most-significant bit-group in their IP addresses." I guess it is because of this sentence. It is not possible to separate network with non continuous range of IPs? For example, I don't want 172.31.1.102 to be able to reach 172.31.1.118, but 172.31.1.230 should be reachable. – Clèm May 14 '20 at 14:59
  • That was not in your initial post, you said that it's not working, I told you why. Add more details and a question in your initial post, see How do I ask a good question ? – Swisstone May 14 '20 at 15:03
  • There is no need. You answered my question. I thought I could just do what I want with a netmask because I didn't know subnetwork had to be continuous range of IPs. – Clèm May 14 '20 at 15:27
0

Stop. 255.255.255.8 is just plain dangerous, and the OS is warning you. Your mask would use only addresses that end in multiples of 16!

You need to use the "high" bits in your mask, not the low ones, in order to make contiguous blocks. Below are some valid examples.

A Class C is a /24 mask, or 24 bits, and looks 255.255.255.0 or
11111111.11111111.11111111.00000000

/25 bits 255.255.255.128 or 11111111.11111111.11111111.10000000

/26 bits 255.255.255.192 or 11111111.11111111.11111111.11000000

/27 bits 255.255.255.224 or 11111111.11111111.11111111.11100000 << you probably want this one

(and so on)

/28 bits 255.255.255.240 (16 IPs, 14 usable);

/29 bits 255.255.255.248 (8 IPs, 6 usable);

/30 bits 255.255.255.252 (4 IPs, 2 usable);

/31 bits 255.255.255.254 (never really used, since there's no addresses free.)

/32 bits 255.255.255.255 (normally only used to describe a host, versus a network.)

3
  • I am working on a complex network and after listing all IPs (some are set on the hardware by the vendor and cannot be changed), 255.255.255.8 would have done exactly what I wanted in a simple way. I was not aware of the "high" bits constrain, which, in other words, means that subnetworks must be continuous. – Clèm May 15 '20 at 9:42
  • While it is technically possible to do what you're asking (the first Ethernet cards didn't care what you did to them, as it was jumper based) but this helps you avoid other problems. You can still use a proper /27 or .224 mask to get your "stub nets" to work. The simple workaround is to have your .230 device also listen to an IP inside your "stub net" range, as well as the .230 address. The .230 device keeps the wider, or over-arching, mask, while each virtual NIC will only listen inside the /27 mask. You may want to take a quick read on subnetting and adding multiple IPs to the same NIC. – Bee Kay May 22 '20 at 6:12
  • Ran out of space to reply - Thanks for marking mine as the best answer! Hope this helps you get past your issue! – Bee Kay May 22 '20 at 6:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.