The network setting for /etc/network/interfaces for static IP of a supernet address

1

I want to change my Ubuntu to static IP. My current IP setting is:

eth0      Link encap:Ethernet  HWaddr 00:0c:29:xx:xx:xx  
      inet addr:192.168.16.59  Bcast:192.168.31.255  Mask:255.255.240.0
      inet6 addr: fe80::20c:xx:xx:xx/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:234690 errors:0 dropped:0 overruns:0 frame:0
      TX packets:1864 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:22953435 (22.9 MB)  TX bytes:205616 (205.6 KB)

what should I put as the network in /etc/network/interfaces (note the network mask of 255.255.240.0)?

xpt

Posted 2014-03-31T19:51:41.680

Reputation: 5 548

What exactly do you have trouble with? I don't see any network statements in interfaces(5). You might consider rephrasing your question and add some details. – Andreas Wiese – 2014-03-31T19:56:24.873

1Stop using ifconfig, use ip addr instead. This is what ifupdown (the software that parses /etc/network/interfaces) uses under the hood anyway, so you will definitely want to get used to it. – BatchyX – 2014-03-31T20:06:09.840

@BatchyX, I use ip addr for other things but not this one, because it'd be worse that ifconfig -- ifconfig at least gives me address, broadcast & netmask, but ip addr doesn't give me netmask, at least my version doesn't. – xpt – 2014-04-01T02:40:52.493

@xpt: ip addr gives you the modern CIDR prefix length just next to the IP address. It also accept old-style netmask on input (i.e. 192.168.31.254/255.255.240.0) – BatchyX – 2014-04-02T17:52:31.950

Answers

1

If I'm understanding your question, to set a static IP, your network runs from 191.168.16.1 - 191.168.31.254, with the identity address at 192.168.16.0 and the broadcast at 192.168.31.255. I've never had to use the Network keyword, but I've never used a supernet address on a host. I've only seen them used for route aggregation.

 auto eth0
 iface eth0 inet static
 address 192.168.16.59
 network 192.168.16.0
 netmask 255.255.240.0
 broadcast 192.168.31.255
 gateway 192.168.0.1

Frank Thomas

Posted 2014-03-31T19:51:41.680

Reputation: 29 039

Classes was droped 20 years ago to use classless networks. Only set address, netmask, and gateway in the stanza. All others are calculated by Linux, and done right. You also might want to set the dns-nameservers etc (see man page for resolvconf(8)). One would also want to use ipcalc(1) and/or sipcalc(1) when one do calculation on IP-addresses and netmasks. And please use CIDR format. – Anders – 2016-07-12T04:28:30.383

@Anders, I hear what you are saying, but you are neglecting that any address can be looked at both from a classfull or classless perspective, when looking at a single address/mask. The only difference at a purely IP level (discounting old ASICs that calculated addresses in hardware) is that CIDR allows larger masks to most networks; what used to be called "supernets". remember however that the R in CIDR is for Routing, because CIDR was invented as a route aggregation method, not as some kind of revolution in how IPs are grouped. – Frank Thomas – 2016-07-12T11:37:31.837

But still, IP classes was droped 20 years ago to classless nets. Yes, netmasks are just another way of writing CIDR addresses. Class nets never used netmasks. – Anders – 2016-07-13T00:51:43.580

Thats not true. Network masks were present to provide subnetting, which does not require CIDR at all. CIDR only allows the mask to be "larger" than the class-natural mask. Subnetting absolutely requires the concept of classfullness so that the overall network ID and broadcast can be established and disambiguated from the subnet IDs and broadcast addresses. that way all the subnets of a class C can be aggregated under a single route from more than one hop away. CIDR just allows aggregation at a higher level than the class-natural mask would allow. IE you could aggregate a route to 7 class C's. – Frank Thomas – 2016-07-13T12:47:15.243

My IP is not a good example for network for this case. I guess if my IP is 192.168.18.159, my network value is still 192.168.16.0, correct? BTW, are you saying that is network optional for /etc/network/interfaces? I'm following http://guylabs.ch/2013/07/25/configure-a-static-ip-in-ubuntu-13-04/, and there is a network there.

– xpt – 2014-04-01T02:29:31.200

it depends on your network mask. for the Class C network 192.168.X.Y, a subnetted network would have >24 bits of mask (255.255.255.0-252), a supernetted net would have < 24 bits mask (255.0-255.0-252.0), and a normal (class natural) Class C would be 255.255.255.0. which one it is defines the "shape" of your IP address layout. – Frank Thomas – 2014-04-01T11:27:34.890

Yeah, all these is because of the supernetted net, a term that I just learned from you. Otherwise, for 255.255.255.0 network mask, the examples are everywhere. So again, to confirm, for network mask of 255.255.240.0, for all IP of 192.168.18., 192.168.28. till 192.168.31.*, their network value are all 192.168.16.0, right? – xpt – 2014-04-01T14:07:02.723

1

yep. now that said, there is the possibility that subnetworks are defined under this address space, so make sure when configuring systems in this way that they all have a 255.255.240.0 mask. if you see any more confining masks (more than 20 bits) you will need to recalculate the network range, ID, and broadcast when configuring systems on that network. I use this calculator: http://www.subnet-calculator.com/

– Frank Thomas – 2014-04-01T14:16:20.840

2network is totally ignored by ifupdown, the system can figure it by itself anyway. Your broadcast is useless here: the system will pick the same in your case. Your gateway is not part of your subnet, so ifupdown will fail at that point. – BatchyX – 2014-04-02T18:00:41.310

1And nobody told you that classful addressing has been deprecated and dead for 20 years now ? All the Internet uses Classless interdomain routing now (CIDR for short, see RFC 4632), so there is no concept of "classes" or "supernetting" anymore. You may even specify a prefix length in netmask (like netmask 20) instead of a netmask. – BatchyX – 2014-04-02T18:08:43.843

@BatchyX, I did notice that the gateway is not not the same as mine, but Frank had already said that he's never used a supernet address before, and it is not part of my question anyway. BTW, instead of saying everything in a negative way, I think saying what is correct is more important (e.g., one doesn't need to specify broadcast in /etc/network/interfaces). – xpt – 2014-04-03T02:08:44.723