View Single Post
  #7   (View Single Post)  
Old 27th August 2012
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,983
Default Chapter 6: Internet Protocol: IP addresses, nets, subnets, and routing

If you knew nothing else about TCP/IP networking before reading this introduction, you probably knew about IP addresses. You knew that every computer on a TCP/IP network has one. This is the layer that provides us with routing. With nothing more than a pair of IP addresses we can interconnect two LANs and route packets between them.

This layer is still part of our TCP/IP network, even if we only have an isolated LAN, such as two computers connected via a single cable. Because the IP address numbers are how we address all our communication in TCP/IP.
Internet Domain names like www.bsdforums.org are not part of TCP/IP addressing. Domain names are converted to IP addresses with requests (over your TCP/IP network) to a nearby Domain Name Server. Your BSD computer has the IP addresses of one or more Domain Name Servers in your /etc/resolv.conf file... put there by you or by a nearby Dynamic Host Configuration Protocol (DHCP) server at network startup.
The devices on the LAN make and keep maps between IP addresses and MAC addresses as they communicate, via an Address Resolution Protocol. It's fairly simple. The first time device 10.0.0.1 needs to send a message to IP address 10.0.0.2, it sends a broadcast packet to the LAN, asking, "Who is 10.0.0.2?" -- and it gets a reply, stating, "I am 10.0.0.2 - I am MAC address 12:34:56:78:9a:bc." On BSD systems you can see the results with the arp(8) command, or with the route(8) command's show option.

When you need packets to leave the LAN and travel to other networks, you use a router. As described in Chapter 2 of this introduction, a router is a computer with multiple network interfaces. One NIC on the LAN, and one or more NICs on other networks.

IP addresses use a definition -- a subnet -- to define the IP address range for a LAN. IP addresses within a LAN's subnet are on the LAN and can be directly addressed via the data link layer. Addresses outside of the LAN subnet are elsewhere, and must be routed. For my computer to route any packets outside the LAN, my computer needs to know which of the many devices on my LAN is the router. That information is stored along with the network(s) reachable by the router in a table in my computer's RAM -- called a routing table. Routes are fairly simple. To route a packet anywhere, my computer only needs to know:
  • Its own IP address and the destination IP address
  • The range of IP addresses on the local LAN.
  • The address of the router on the LAN that will route the traffic to its destination.
Most small LANs only have a single router. If that's the case for me, then my computer only has a single entry in the routing table, a default route, which states, "Traffic to any non-LAN address goes to the router at <IP address>."

Subnets are defined by netmasks -- the number of bits defining the address range of a subnet. Your ifconfig(8) command will display NICs IP addresses and netmasks. There are a variety of notations to show how many bits make up a subnet. "255.255.255.0" and "/24" are two ways to describe the same netmask. IPv4 addresses are 32 bits, and both notations define the left-most 24 bits as masked out, and not part of the subnet, with the right most 8 bits available for addresses. An 8-bit subnet (256 numbers, 254 usable addresses) is very common because it is easy for human-readable IP address notations. But it is not required. Other length netmasks may be used.

Netmasks are also used in routing tables ... when there are multiple routers on a LAN. For instance, there might be 2 entries in the table, for two routers, one of which is for the internet, and one of which is for any address that begins with 10.x.x.x:
  1. Route packets destined for the 10/8 network to the router at 192.168.1.1
  2. My default route for all other packets is my router at 192.168.1.2
Assuming an em0 NIC, no DCHP server, and no configuration files at all, here are commands to configure this example on OpenBSD. Other BSDs will be the same or similar.
Code:
# ifconfig em0 192.168.1.3/24
# route add 10/8 192.168.1.1
# route add default 192.168.1.2

Last edited by jggimi; 4th September 2012 at 12:03 AM.
Reply With Quote