What is the proper netmask for an alias IP address?

I did a lot of searching, but there seems to be conflicting info on what the proper netmask for an aliased IP address should be. Some of the conflicting info seems to be FreeBSD-specific. I'm looking for the "most technically proper" answer, if there is one.

I've been assigned x.x.x.168/29.

Here is eth0:

address x.x.x.170
netmask 255.255.255.248
gateway x.x.x.169

So the proper eth0:0 netmask should be 255.255.255.something.

EDIT: Per the comment from Chris S, I am not using FreeBSD; I am using Debian. My understanding is that FreeBSD users should use .255 for aliases. But I could be wrong, so you should do your own research.


Solution 1:

Your eth0:0 subnet mask should be 255.255.255.248, unless you have some reason that you do not want eth0:0 to communicate directly with the rest of the hosts in the subnet. If you make it smaller, you will need a router to allow that IP to communicate with the rest of the network.

Solution 2:

The netmask is per network, not per IP, so as NickW says, it should be the same for all IPs in a given network. There are corner cases where you may restrict a given alias interface further, but those are exceedingly rare.

Solution 3:

Nick W's answer is correct.

However well you understand the theory of these CIDR network specifications, working the numbers out by hand is tedious and error prone. I recommend a tool called ipcalc which is available in the software repositories associated with many of the major Free *nix distributions. It's good for getting the calculations right, and also as an educational tool, clarifying what the numbers represent, by showing you the binary representations.

me@mine$ ipcalc 1.2.3.168/29  
Address:   1.2.3.168            00000001.00000010.00000011.10101 000  
Netmask:   255.255.255.248 = 29 11111111.11111111.11111111.11111 000  
Wildcard:  0.0.0.7              00000000.00000000.00000000.00000 111  
=>  
Network:   1.2.3.168/29         00000001.00000010.00000011.10101 000  
HostMin:   1.2.3.169            00000001.00000010.00000011.10101 001  
HostMax:   1.2.3.174            00000001.00000010.00000011.10101 110  
Broadcast: 1.2.3.175            00000001.00000010.00000011.10101 111  
Hosts/Net: 6                     Class A