3

TL;DR

Given 8.8.8.8, what do I call its 8.8.8.0 or 8.8.8.1?

Why do I need this information?

I'm working on a program that resolves the location of IP addresses. To reduce the number of API requests it makes, I replace the last octet of each IP address with 0 and cache the results, presuming that whole subnet belongs to the same location anyway.

What do I need to know?

I need to name the database column for that value, and I'd like to do that properly. What word should I choose for a column name?

Also, is there something I need to know about 8.8.8.0 vs 8.8.8.1? Should I prefer one over another?

I found this question but there doesn't seem to be an answer to my question on that page.

Thank you!

  • 2
    This is incredibly dangerous. All IPs out of a /24 are not inherently all going to be in the same location. If you're proceeding under this assumption, you're going to break a lot of things. – Aaron Mar 02 '16 at 23:18
  • @Aaron please confirm if I got this right: you're saying `8.8.8.123` and `8.8.8.234` can resolve to different geographical locations? If so, can you please provide an example? Because this would make a huge difference – ᴍᴇʜᴏᴠ Mar 05 '16 at 20:08
  • 2
    Absolutely. The ISP I work for assigns smaller than /24 to customers all the time. So 8.8.8.0/29 and 8.8.8.128/29 could be across the country from one another. Now we do regional aggregation but people do move so that is by no means a guarantee. Also what's your tolerance? Is 100 miles apart the same location? 25? – Aaron Mar 05 '16 at 20:35

2 Answers2

6

The first IP address in a prefix is usually called the network address. In most setups, the first assignable address is the gateway, though any IP address within a prefix could be configured as gateway. So assuming 8.8.8.8 is in a /24 network, 8.8.8.0 would be the network address and 8.8.8.1 the gateway.

Also, is there something I need to know about 8.8.8.0 vs 8.8.8.1? Should I prefer one over another?

That's hard for us to tell, we don't know your application, but if you're looking at /24's, I'd take 8.8.8.0.

Teun Vink
  • 16,953
  • 6
  • 44
  • 70
  • 3
    Just to make sure there is no misunderstanding - the only really fixed name is "network address" for the x.x.x.0. (on a /24 or greater) The .1 on a network being the gateway is a commonly used practice, nevertheless there is no standard for that, there is a lot of networks where it is done differently, and a networker who reads "Gateway" has a different understanding of what that is supposed to mean than "first IP of the subnet". – xpac Feb 15 '16 at 11:36
  • 2
    I would also note that if the example network is a /23, the network address would be 8.8.7.0 and not 8.8.8.0. It is difficult, if not impossible to know what the actual subnet is from the remote side. So this process would only be making a guess at the *first usable address* (which is the term I would use for it). – YLearn Feb 15 '16 at 13:26
2

You're making the assumption that all networks are /24s (equivalent of a pre-CIDR "Class C", with a subnet mask of 255.255.255.0), which is definitely not the general case. There are lots of much smaller and much larger blocks.

You should try to find out the CIDR network the IP is part of, and make a note of that network. A CIDR network is defined by its starting address and prefix-length.

The starting address can be called:

  • the start address
  • the network address
  • the prefix

Depending on what exactly you are trying to achieve, different levels of granularity may be needed. It may be enough for you to know that a given block is allocated to a single ISP and has a single "route" in BGP. Or you may want to know the specific company the network is assigned to.

jcaron
  • 733
  • 3
  • 9