Logo  

CS469 - Linux and Unix Administration and Networking

Internet Protocol (IP) (man 7 ip)

Provides a route-able protocol for delivering data-gram packets across networks based on IP address. There are two version, version 4 (IPv4) which uses 32 bit addresses (< 4 billion addresses) and a less widely used version 6 (IPv6) which uses 128 bit addresses (< ~340 undecillion addresses). For now IPv4 still remains the primary Internet protocol:

  • An IPv4 Header contains among other information:

    • Source IP address
    • Destination IP address
    • Total length of the IP packet
    • Protocol - i.e. TCP / UDP - The protocol encapsulated within the IP packet
    • Time to live (TTL) - A number decremented at every hop along the packets journey, upon reaching zero, the packet is discarded. This prevents a packet caught in a loop from being passed around forever.
    • Other fields for IP fragmentation and options.
  • Packets are routed based on destination. It isn't necessarily the case that a packet will be returned along the same path that one was sent. It is also the case that the source address can be completely bogus.

Files:

/etc/protocols

  • List of protocols (man 5 protocols) (mostly useful to programmers)

Programs:

> ifconfig

  • Configure a network interface (being deprecated)

Example:

ifconfig eth0 139.102.14.201 netmask 255.255.255.0 broadcast 139.102.14.255
or maybe: ifconfig eth0 139.102.14.201/24

  • Configures eth0 for:
IP address 139.102.14.201
Netmask 255.255.255.0
Broadcast address 139.102.14.255

> ip

  • show/manipulate routing, devices, policy routing and tunnels. Too many options to list. Typically not used by humans, but in scripts.

IPv4 Addresses:

  • Consist of 32 bits, typically listed in 4 8-bit "octet" dot-decimal notation.

  • Distributed by the Internet Assigned Numbers Association (IANA) a department of ICANN (Internet Corporation of Assigned Names and Numbers):

    • Delegates allocations to Regional Internet Registries (RIRs) which each address different areas of the world.

    • Administers the data in the root domain name servers

    • ICANN also:

      • Administers protocol parameters of IETF (Internet Engineering Task Force (who publish the RFCs))
      • Maintain a time zone database.
  • IPv4 Private addresses:

    • These are addresses that are not routed on the internet (but might be routed on the local network.)
    • They consist of three reserved blocks:
CIDR Starting address Ending address Number of IPs
10.0.0.0/8 10.0.0.0 10.255.255.255 (~16M)
172.16.0.0/12 172.16.0.0 172.31.255.255 (~1M)
192.168.0.0/16 192.168.0.0 192.168.255.255 (~65K)
  • The 127.0.0.0/8 block is the loopback or localhost address range and is a virtual network range that exists only with a machine itself via the virtual loopback device lo or lo0, typically assigned the address 127.0.0.1.

  • IP addresses are usually assigned in two ways:

    • Static assignment, where the IP address is configured manually on the host and does not change.

    • Dynamic assignment, where a protocol, such as DHCP (Dynamic Host Configuration Protocol) or BOOTP is used to request an IP address.

  • The Broadcast address for a host is the host part of the IP address where all bits are 1's.
    (139.102.14.201&255.255.255.0)|0.0.0.255 -> 139.102.14.255
    Packets with the destination set to the broadcast address are typically recieved by all machines on the local network.

  • Multicast IP addresses: 224.0.0.0/4 (224.0.0.0-239.255.255.255)

Network commands:

> route

  • print and set routes

> routel

  • List routes

> traceroute [-n] hostname

  • Show routes taken from host to destination.

# echo "1" > /proc/sys/net/ipv4/ip_forward

  • Enables packet forwarding between interfaces. Lets Linux be a gateway.

> ping hostname

  • Send ICMP echo's to a machine.

Subnetting:

  • Classful network design:

    • Originally divided networks into 3 sizes, Class A (24 bits), Class B (16 bits) (ISU's network was originally a Class B network (139.102.0.0) and Class C (8 bits).
  • Classless Inter-Domain Routing (CIDR)

    • Prior to CIDR IPv4 networks were represented using dot-decimal notation for both IP address and netmask: 192.168.100.0/255.255.255.0 (classful) == 192.168.100.0/24 (CIDR)
  • CIDR divides an IP network into smaller logical sub-networks. Given:

[ Network prefix ][ Host number ]
                      /       \
[ Network prefix ][Subnet #][Host #]


  • The host part is determined by (IP address & ~ Netmask)
  • All zeros in the host part is reserved for the network ID.
  • All ones in the host part is reserved for the broadcast address.

Examples:

  • 192.168.1.0/30: (2 bits for host part)

    11111111.11111111.11111111.111111 00 Netmask: 255.255.255.252
    11000000.10101000.00000001.000000 00 Network address: 192.168.1.0
    11000000.10101000.00000001.000000 01 1st IP: 192.168.1.1
    11000000.10101000.00000001.000000 10 2nd IP: 192.168.1.2
    11000000.10101000.00000001.000000 11 Broadcast address: 192.168.1.3
  • 192.168.1.4/30: (2 bits for host part, second network)

    11111111.11111111.11111111.111111 00 Netmask: 255.255.255.252
    11000000.10101000.00000001.000001 00 Network address: 192.168.1.4
    11000000.10101000.00000001.000001 01 1st IP: 192.168.1.5
    11000000.10101000.00000001.000001 10 2nd IP: 192.168.1.6
    11000000.10101000.00000001.000001 11 Broadcast address: 192.168.1.7
  • 192.168.1.10/16: (16 bits for host part)

    11111111.11111111. 00000000.00000000 Netmask: 255.255.0.0
    11000000.10101000. 00000000.00000000 Network address: 192.168.0.0
    11000000.10101000. 00000000.00000001 1st IP: 192.168.0.1
    11000000.10101000. 11111111.11111110 last IP: 192.168.255.254
    11000000.10101000. 11111111.11111111 Broadcast address: 192.168.255.255
  • 139.102.14.201/24: (8 bits for host part):

    11111111.11111111.11111111. 00000000 Netmask: 255.255.255.0
    10001011.01100110.00001110. 00000000 Network address: 139.102.14.0
    10001011.01100110.00001110. 00000001 1st IP: 139.102.14.1
    10001011.01100110.00001110. 11111110 last IP: 139.102.14.254
    10001011.01100110.00001110. 11111111 Broadcast address: 139.102.14.255