IPv4 addressing

When Internet was started, it starts with IPv4 address, which is 32-bit number. Initially the IPv4 address is classified into type A, B, C, D, E. In 1993 IETF introduced Classless Inter-Domain Routing (CIDR) with goal to slow the growth of routing tables on routers across the Internet, and to help slow the rapid exhaustion of IPv4 addresses.

ipv4 address

Classful IPv4 address

The IPv4 address is classified into class A, B, C, D and E, D is for multicast, and E is reserved. In fact, it is really not used in the nwtwork. Below table shows Class A, B and C address.

ipv4 class

Class A - *0xxxxxxx

First octet is used for numbering the networks as defined by default mask.

Available number of bits that can be ‘modified’ as represented by ‘x’ are 7 and therefore number of possible different network number combinations using those bits is equal to 2^7. For each Class A network, it can have hosts up to 2^24-2.

Note: that 10.x.x.x is defined as private IPv4 address, which means these addresses are not routable in the public internet, rather they are extensive used inside corprate network, i.e. intranet. Inside Cisco network, majority of linux servers in the data center has 10.x.x.x address.

Class B - 10xxxxxx.xxxxxxxx

First two octets are used for numbering the networks as defined by default mask.

Available number of bits that can be ‘modified’ as represented by ‘x’ are 14 and therefore number of possible different network number combinations using those bits is equal to 2^14. For each Class B network, it can have hosts up to 2^16-2.

Note: that 172.16.x.x - 172.32.x.x are defined as private IPv4 address, which means these addresses are not routable in the public internet, rather they are extensive used inside corprate network, i.e. intranet. Inside Cisco network, 172.16.x.x-172.32.x,x are used for lab, i.e. linux server, router interfaces etc.

Class C - 110xxxxx.xxxxxxxx.xxxxxxxx

First three octets are used for numbering the networks as defined by default mask.

Available number of bits that can be ‘modified’ as represented by ‘x’ are 21 and therefore number of possible different network number combinations using those bits is equal to 2^21. For each Class C network, it can have hosts up to 2^8-2

Note: that 192.168.x.x is defined as private IPv4 address, which means these addresses are not routable in the public internet, rather they are extensive used inside corprate network, i.e. intranet. Inside Cisco network, 192.168.x.x is used as private network for group/BU specific set up, they are typically going through NAT to talk to coprate network.

As we can see in the case of Class A network, the maximum allowed hosts is huge, which is often not the case in the actual network. This leads to waste of limited precious IPv4 address. In Cisco router, by default, the routing protocol assumes classless addressing, i.e. when it advertises the route, it will include network with subnet mask. Still if the customer really wants to enable classful routing, it can do so by “no ip classless”:

IR809-WEWENG-1(config)#no ip c?
cache-ager      cache-invalidate-delay  cef  classless
community-list

IR809-WEWENG-1(config)#no ip classless

CIDR, VLSM, CIDR notation

Under CIDR, IPv4 addresses are described as consisting of two groups of bits in the address: the most significant bits are the network address (or network prefix or network block), which identifies a whole network or subnet, and the least significant set forms the host identifier, which specifies a particular interface of a host on that network.Under CIDR, the restriction of network block is either 8, 16, or 24 bits is removed. Based on the actual network set up, the network can be any size as appropriate.

Classless Inter-Domain Routing is based on variable-length subnet masking (VLSM). Under CIDR, one host is described through CIDR notation, e.g.

  • 192.168.100.14/24 represents the IPv4 address 192.168.100.14 and its associated routing prefix 192.168.100.0, or equivalently, its subnet mask 255.255.255.0, which has 24 leading 1-bits.
  • block 192.168.100.0/22 represents the 1024 IPv4 addresses from 192.168.100.0 to 192.168.103.255.

One of advantge of CIDR, it provides the possibility of fine-grained routing prefix aggregation. For example, sixteen contiguous /24 networks can be aggregated and advertised to a larger network as a single /20 routing table entry, if the first 20 bits of their network addresses match. Two aligned contiguous /20 blocks may be aggregated to a /19, and so forth. This results in reduction of the number of routes that have to be advertised.

IPv4 Address configuration

There are two ways to have IPv4 address configurated for an interface: static or dhcp.

static IPv4 address configuration

Under Cisco router, the address can be assigned using CLI, see example below, it is to configure GigabitEthernet1 interface to IPv4 address 192.168.100.1/24:

IR809-WEWENG-1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
IR809-WEWENG-1(config)#interface GigabitEthernet1
IR809-WEWENG-1(config-if)#ip address ?
  A.B.C.D  IP address
  dhcp     IP Address negotiated via DHCP
  pool     IP Address autoconfigured from a local DHCP pool

IR809-WEWENG-1(config-if)#ip address 192.168.100.1 ?
  A.B.C.D  IP subnet mask

IR809-WEWENG-1(config-if)#ip address 192.168.100.1 255.255.255.0
IR809-WEWENG-1(config-if)#end
IR809-WEWENG-1#

Under linux, let’s sya there is an ethernet interface “eth0”, you can Assign static IP Address to eth0 interface editing configuration file /etc/network/interfaces to make permanent changes as shown below.

auto eth0
iface eth0 inet static
address 192.168.100.2
netmask 255.255.255.0
gateway 192.168.100.1

To confiugre the interface “eth0” right away , there are two commands: old one “ifconfig “, and new one “ip addr add …”.

root# ip addr add 192.168.100.2/24 dev eth0
root# # or
root# ifconfig eth0 192.168.100.2 netmask 255.255.255.0 up

DHCP: dynamic address configuration

Cisco IOS can server a DHCO server to provide IP address to local interface or to hosts in the network. Below is a quick example of a dhcp pool, which provides the IPv4 address to interface gigabitEthernet 1.

IR809-WEWENG-1(config)#
IR809-WEWENG-1(config)#ip dhcp?
dhcp  dhcp-client  dhcp-server

IR809-WEWENG-1(config)#ip dhcp pool ?
  LINE  Pool name

IR809-WEWENG-1(config)#ip dhcp pool local-pool1
IR809-WEWENG-1(dhcp-config)#network 192.168.100.0 ?
  /nn or A.B.C.D  Network mask or prefix length
  <cr>

IR809-WEWENG-1(dhcp-config)#network 192.168.100.0 /24
IR809-WEWENG-1(dhcp-config)#lease ?
  <0-365>   Days
  infinite  Infinite lease

IR809-WEWENG-1(dhcp-config)#lease 1 ?
  <0-23>  Hours
  <cr>

IR809-WEWENG-1(dhcp-config)#lease 1 12
IR809-WEWENG-1(dhcp-config)#exit
IR809-WEWENG-1(config)#interface gigabitEthernet 1
IR809-WEWENG-1(config-if)#ip address ?
  A.B.C.D  IP address
  dhcp     IP Address negotiated via DHCP
  pool     IP Address autoconfigured from a local DHCP pool

IR809-WEWENG-1(config-if)#ip address pool ?
  LINE  Pool name

IR809-WEWENG-1(config-if)#ip address pool local-pool1 ?
LINE    <cr>

IR809-WEWENG-1(config-if)#ip address pool local-pool1
IR809-WEWENG-1(config-if)#end
IR809-WEWENG-1#show interfaces gigabitEthernet 1
GigabitEthernet1 is administratively down, line protocol is down
  Hardware is Gigabit Ethernet, address is 78ba.f9c3.1948 (bia 78ba.f9c3.1948)
  Internet address is 192.168.100.1/24
  MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation ARPA, loopback not set
  Keepalive set (10 sec)
  Half Duplex, Auto Speed, media type is RJ45
  output flow-control is XON, input flow-control is XON
  ARP type: ARPA, ARP Timeout 04:00:00
  Last input never, output never, output hang never
  Last clearing of "show interface" counters never
  Input queue: 0/250/0/0 (size/max/drops/flushes); Total output drops: 0
  Queueing strategy: fifo
  Output queue: 0/40 (size/max)
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     0 packets input, 0 bytes, 0 no buffer
     Received 0 broadcasts (0 IP multicasts)
     0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
     0 watchdog, 0 multicast, 0 pause input
     0 packets output, 0 bytes, 0 underruns
     0 output errors, 0 collisions, 0 interface resets
     0 unknown protocol drops
     0 babbles, 0 late collision, 0 deferred
     0 lost carrier, 0 no carrier, 0 pause output
     0 output buffer failures, 0 output buffers swapped out
IR809-WEWENG-1#

As shown above, interface gigabitethernet 1 acquires the IP address “192.168.100.1/24” from the dhcp pool “local-pool1”.