IP addresses

| ⌛ 4 minutes read

📋 Tags: Networking


This is a personal braindump on everything I might need to know about IP addresses.

The problem IP addresses solves is uniquely identify what node on the interwebs to send data to. There are billions of devices and an order of magnitude more virtual devices, all wanting to communicate with one another. How do we uniquely identify them?

Addresses

IP addresses are used as a way to identify a network interface. ifconfig on your Linux machine will show you all the different network interfaces on your machine, and the IP address assigned to it.

IPv4 and hierarchies

Addresses are basically numbers. IPv4 addresses are 32b long, and chopped into 4 sections. Each section consists of 8b. So, the upper limit for each section is b1111_1111 == 255.

With this structure, we can implement the idea of subnets, where a group of IPv4 addresses all belong to the same logical group. We first do this by having a subnet mask. The subnet mask sets the top few bits of the 32b long address. The bits that are not set can be used as identifiers for machines inside the subnet.

For example, a subnet mask can be 255.255.255.0, equivalent to /24 since the first 24 bits of the 32 bits total are set. This means that this particular subnet’s last 32-24=8 bits* can be freely used as an ‘id’ for allocation inside the subnet.

*not entirely true, there are reserved addresses that we will discuss shortly.

Consider this address in ‘CIDR’ notation: 192.168.100.0/24. Its subnet mask is 255.255.255.0. It has an address space of $2^8$ identifiers. Valid members of this network can be: 192.168.100.3 (the last 8 bits are b0000_0011), or 192.168.100.254 (the last 8 bits are b1111_1110).

To generalize, in any given network a.b.c.d/n, there are $2^{n}-2$ possible addresses that can be used for regular assignment.

Special reserved addresses:

  • Network Address: The address where none of the n bits are set. 192.100.5.0/24’s network address is 192.100.5.0.
  • Broadcast Address: The address where the last n bits are set. For 192.100.5.0/24, it is 192.100.5.255. Packets sent to this address

Gateway Address:

Consider 192.168.100.0/24. Typically, the FIRST address of this subnet is used as the gateway address (typically, the router’s address). i.e. 192.168.100.1

Demo with ip tools

Linux typically comes with ip. We will use this to explore a Linux machine’s (my linux machine…) ip config.

0
1
2
3
4
5
6
$ ip address
# ... output truncated :)
2: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 10:ff:e0:20:4e:ea brd ff:ff:ff:ff:ff:ff
    inet 192.168.88.15/24 brd 192.168.88.255 scope global dynamic noprefixroute enp8s0
       valid_lft 4800sec preferred_lft 4800sec
# ...output truncated :)

The important/interesting bits:

<BROADCAST,MULTICAST,UP,LOWER_UP> this tells me that the interface can broadcast, can multicast (more on those later), has its state as UP and the physical (lower layer) state is UP.

The MTU is 1500 Bytes, (typical for ethernet). Queueing Discipline qdisc describes how packets queue up at the network interface card (NIC). More details here.

state UP group default qlen 1000: simply, the link is up, belongs to the default group and has a queue length of 1000.

inet 192.168.88.15/24 brd 192.168.88.255 scope global dynamic noprefixroute enp8s0:

  • the ethernet network interface card has an ipv4 (inet) address of 192.168.88.15, with a subnet mask of /24
    • this implies that the network address is 192.168.88.0
  • broadcast address is 192.168.88.255
  • dynamic -> uses DHCP

What about the gateway?

0
1
2
$ ip r
default via 192.168.88.1 dev enp8s0 proto dhcp metric 100
# ... output truncated :)

ip r tells us that the enp8s0 interface uses DHCP and routes packets through to the router with gateway address 192.168.88.1.

Special Addresses

There are some special IP addresses that are reserved. There is an entire wiki page on this, but the important bits are:

  1. 0.0.0.0/8, the local network
  2. 127.0.0.0/8, the loopback address
  3. 255.255.255.255/32, broadcast destination address

IPv6

IPv6 are 128b long addresses. Not often used yet in industry afaik, but is created because IPv4 address space is small and we will probably run out soon.