File:  [NetBSD Developer Wiki] / wikisrc / guide / net-intro.mdwn
Revision 1.4: download - view: text, annotated - select for diffs
Thu Mar 14 23:17:01 2013 UTC (7 years, 7 months ago) by jdf
Branches: MAIN
CVS tags: HEAD
 * gen_toc.sh: Remove links to subchapters (how to make anchors with ikiwiki?)
 * net-intro: Make all-section first level

    1: # Introduction to TCP/IP Networking
    2: 
    3: ## Audience
    4: 
    5: This section explains various aspects of networking. It is intended to help
    6: people with little knowledge about networks to get started. It is divided into
    7: three big parts. We start by giving a general overview of how networking works
    8: and introduce the basic concepts. Then we go into details for setting up various
    9: types of networking in the second parts, and the third part of the networking
   10: section covers a number of *advanced* topics that go beyond the basic operation
   11: as introduced in the first two sections.
   12: 
   13: The reader is assumed to know about basic system administration tasks: how to
   14: become root, edit files, change permissions, stop processes, etc. See the other
   15: chapters of this NetBSD guide and e.g.*Essential System Administration* by 
   16: Aeleen Frisch (1991, O'Reilly & Associates) for further information on this 
   17: topic. Besides that, you should know how to handle the utilities we're going to 
   18: set up here, i.e. you should know how to use telnet, FTP, ... I will not explain 
   19: the basic features of those utilities, please refer to the appropriate 
   20: man-pages, the references listed or of course the other parts of this document 
   21: instead.
   22: 
   23: This introduction to TCP/IP Networking was written with the intention in mind to
   24: give starters a basic knowledge. If you really want to know what it's all about,
   25: read *TCP/IP Network Administration* by Craig Hunt (1993, O'Reilly & 
   26: Associates). This book does not only cover the basics, but goes on and explains 
   27: all the concepts, services and how to set them up in detail. It's great, I love 
   28: it! :-)
   29: 
   30: ## Supported Networking Protocols
   31: 
   32: There are several protocol suites supported by NetBSD, most of which were
   33: inherited from NetBSD's predecessor, 4.4BSD, and subsequently enhanced and
   34: improved. The first and most important one today is DARPA's Transmission Control
   35: Protocol/Internet Protocol (TCP/IP). Other protocol suites available in NetBSD
   36: include the Xerox Network System (XNS) which was only implemented at UCB to
   37: connect isolated machines to the net, Apple's AppleTalk protocol suite and the
   38: ISO protocol suite, CCITT X.25 and ARGO TP. They are only used in some special
   39: applications these days.
   40: 
   41: Today, TCP/IP is the most widespread protocol of the ones mentioned above. It is
   42: implemented on almost every hardware and operating system, and it is also the
   43: most-used protocol in heterogenous environments. So, if you just want to connect
   44: your computer running NetBSD to some other machine at home or you want to
   45: integrate it into your company's or university's network, TCP/IP is the right
   46: choice. Besides the "old" IP version 4, NetBSD also supports the "new" IP
   47: version 6 (IPv6) since NetBSD 1.5, thanks to code contributed by the KAME
   48: project.
   49: 
   50: There are other protocol suites such as DECNET, Novell's IPX/SPX or Microsoft's
   51: NetBIOS, but these are not currently supported by NetBSD. These protocols differ
   52: from TCP/IP in that they are proprietary, in contrast to the others, which are
   53: well-defined in several RFCs and other open standards.
   54: 
   55: ## Supported Media
   56: 
   57: The TCP/IP protocol stack behaves the same regardless of the underlying media
   58: used, and NetBSD supports a wide range of these, among them are Ethernet
   59: (10/100/1000MBd), Arcnet, serial line, ATM, FDDI, Fiber Channel, USB, HIPPI,
   60: FireWire (IEEE 1394), Token Ring, and serial lines.
   61: 
   62: ### Serial Line
   63: 
   64: There are a couple of reasons for using TCP/IP over a serial line.
   65: 
   66:  * If your remote host is only reachable via telephone, you can use a modem to access it.
   67:  * Many computers have a serial port, and the cable needed is rather cheap.
   68: 
   69: The disadvantage of a serial connection is that it's slower than other methods.
   70: NetBSD can use at most 115200 bit/s, making it a lot slower than e.g. Ethernet's
   71: minimum 10 Mbit/s and Arcnet's 4 Mbit/s.
   72: 
   73: There are two possible protocols to connect a host running NetBSD to another
   74: host using a serial line (possibly over a phone-line):
   75: 
   76:  * Serial Line IP (SLIP)
   77:  * Point to Point Protocol (PPP)
   78: 
   79: The choice here depends on whether you use a dial-up connection through a modem
   80: or if you use a static connection (null-modem or leased line). If you dial up
   81: for your IP connection, it's wise to use PPP as it offers some possibilities to
   82: auto-negotiate IP-addresses and routes, which can be quite painful to do by
   83: hand. If you want to connect to another machine which is directly connected,
   84: use SLIP, as this is supported by about every operating system and more easy
   85: to set up with fixed addresses and routes.
   86: 
   87: PPP on a direct connection is a bit difficult to setup, as it's easy to timeout
   88: the initial handshake; with SLIP, there's no such initial handshake, i.e. you
   89: start up one side, and when the other site has its first packet, it will send it
   90: over the line.
   91: 
   92: [RFC1331](http://tools.ietf.org/html/rfc1331) ("The Point-to-Point Protocol
   93: (PPP) for the Transmission of Multi-protocol Datagrams over Point-to-Point
   94: Links") and [RFC1332](http://tools.ietf.org/html/rfc1332) ("The PPP Internet
   95: Protocol Control Protocol (IPCP)") describe PPP and TCP/IP over PPP. SLIP is
   96: defined in [RFC1055](http://tools.ietf.org/html/rfc1055) ("Nonstandard for
   97: transmission of IP datagrams over serial lines: SLIP").
   98: 
   99: ### Ethernet
  100: 
  101: Ethernet is the medium commonly used to build local area networks (LANs) of
  102: interconnected machines within a limited area such as an office, company or
  103: university campus. Ethernet is based on a bus structure to which many machines
  104: can connect to, and communication always happens between two nodes at a time.
  105: When two or more nodes want to talk at the same time, both will restart
  106: communication after some timeout. The technical term for this is CSMA/CD
  107: (Carrier Sense w/ Multiple Access and Collision Detection).
  108: 
  109: Initially, Ethernet hardware consisted of a thick (yellow) cable that machines
  110: tapped into using special connectors that poked through the cable's outer
  111: shielding. The successor of this was called 10base5, which used BNC-type
  112: connectors for tapping in special T-connectors and terminators on both ends of
  113: the bus. Today, ethernet is mostly used with twisted pair lines which are used
  114: in a collapsed bus system that are contained in switches or hubs. The twisted
  115: pair lines give this type of media its name - 10baseT for 10 Mbit/s networks,
  116: and 100baseT for 100 MBit/s ones. In switched environments there's also the
  117: distinction if communication between the node and the switch can happen in half-
  118: or in full duplex mode.
  119: 
  120: ## TCP/IP Address Format
  121: 
  122: TCP/IP uses 4-byte (32-bit) addresses in the current implementations (IPv4),
  123: also called IP-numbers (Internet-Protocol numbers), to address hosts.
  124: 
  125: TCP/IP allows any two machines to communicate directly. To permit this all hosts
  126: on a given network must have a unique IP address. To assure this, IP addresses
  127: are administrated by one central organisation, the InterNIC. They give certain
  128: ranges of addresses (network-addresses) directly to sites which want to
  129: participate in the internet or to internet-providers, which give the addresses
  130: to their customers.
  131: 
  132: If your university or company is connected to the Internet, it has (at least)
  133: one such network-address for its own use, usually not assigned by the InterNIC
  134: directly, but rather through an Internet Service Provider (ISP).
  135: 
  136: If you just want to run your private network at home, see below on how to
  137: "build" your own IP addresses. However, if you want to connect your machine to
  138: the (real :-) Internet, you should get an IP addresses from your local
  139: network-administrator or -provider.
  140: 
  141: IP addresses are usually written in *dotted quad* notation - the four bytes are
  142: written down in decimal (most significant byte first), separated by dots. For
  143: example, 132.199.15.99 would be a valid address. Another way to write down
  144: IP-addresses would be as one 32-bit hex-word, e.g. 0x84c70f63. This is not as
  145: convenient as the dotted-quad, but quite useful at times, too. (See below!)
  146: 
  147: Being assigned a network means nothing else but setting some of the
  148: above-mentioned 32 address-bits to certain values. These bits that are used for
  149: identifying the network are called network-bits. The remaining bits can be used
  150: to address hosts on that network, therefore they are called host-bits. The
  151: following figure illustrates the separation.
  152: 
  153: ![IPv4-addresses are divided into more significant network- and less significant hostbits](/guide/images/ipv4-en-0bits.png)  
  154: **IPv4-addresses are divided into more significant network- and less significant hostbits**
  155: 
  156: In the above example, the network-address is 132.199.0.0 (host-bits are set to 0
  157: in network-addresses) and the host's address is 15.99 on that network.
  158: 
  159: How do you know that the host's address is 16 bit wide? Well, this is assigned
  160: by the provider from which you get your network-addresses. In the classless
  161: inter-domain routing (CIDR) used today, host fields are usually between as
  162: little as 2 to 16 bits wide, and the number of network-bits is written after the
  163: network address, separated by a `/`, e.g. 132.199.0.0/16 tells that the network
  164: in question has 16 network-bits. When talking about the *size* of a network,
  165: it's usual to only talk about it as `/16`, `/24`, etc.
  166: 
  167: Before CIDR was used, there used to be four classes of networks. Each one starts
  168: with a certain bit-pattern identifying it. Here are the four classes:
  169: 
  170:  * Class A starts with `0` as most significant bit. The next seven bits of a
  171:    class A address identify the network, the remaining 24 bit can be used to
  172:    address hosts. So, within one class A network there can be 2^24 hosts. It's
  173:    not very likely that you (or your university, or company, or whatever) will
  174:    get a whole class A address.
  175: 
  176:    The CIDR notation for a class A network with its eight network bits is an `/8`.
  177: 
  178:  * Class B starts with `10` as most significant bits. The next 14 bits are used
  179:    for the networks address and the remaining 16 bits can be used to address
  180:    more than 65000 hosts. Class B addresses are very rarely given out today,
  181:    they used to be common for companies and universities before IPv4 address
  182:    space went scarce.
  183: 
  184:    The CIDR notation for a class B network with its 16 network bits is an `/16`.
  185: 
  186:    Returning to our above example, you can see that 132.199.15.99 (or
  187:    0x84c70f63, which is more appropriate here!) is on a class B network, as
  188:    0x84... = **10**00... (base 2).
  189: 
  190:    Therefore, the address 132.199.15.99 can be split into an network-address of
  191:    132.199.0.0 and a host-address of 15.99.
  192: 
  193:  * Class C is identified by the MSBs being `110`, allowing only 256 (actually:
  194:    only 254, see below) hosts on each of the 2^21 possible class C networks.
  195:    Class C addresses are usually found at (small) companies.
  196: 
  197:    The CIDR notation for a class C network with its 24 network bits is an `/24`.
  198: 
  199:  * There are also other addresses, starting with `111`. Those are used for
  200:    special purposes (e. g. multicast-addresses) and are not of interest here.
  201: 
  202: Please note that the bits which are used for identifying the network-class are
  203: part of the network-address.
  204: 
  205: When separating host-addresses from network-addresses, the *netmask* comes in
  206: handy. In this mask, all the network-bits are set to `1`, the host-bits are `0`.
  207: Thus, putting together IP-address and netmask with a logical AND-function, the
  208: network-address remains.
  209: 
  210: To continue our example, 255.255.0.0 is a possible netmask for 132.199.15.99.
  211: When applying this mask, the network-address 132.199.0.0 remains.
  212: 
  213: For addresses in CIDR notation, the number of network-bits given also says how
  214: many of the most significant bits of the address must be set to `1` to get the
  215: netmask for the corresponding network. For classful addressing, every
  216: network-class has a fixed default netmask assigned:
  217: 
  218:  * Class A (/8): default-netmask: 255.0.0.0, first byte of address: 1-127
  219:  * Class B (/16): default-netmask: 255.255.0.0, first byte of address: 128-191
  220:  * Class C (/24): default-netmask: 255.255.255.0, first byte of address: 192-223
  221: 
  222: Another thing to mention here is the *broadcast-address*. When sending to this
  223: address, *all* hosts on the corresponding network will receive the message sent.
  224: The broadcast address is characterized by having all host-bits set to `1`.
  225: 
  226: Taking 132.199.15.99 with its netmask 255.255.0.0 again, the broadcast-address
  227: would result in 132.199.255.255.
  228: 
  229: You'll ask now: But what if I want a host's address to be all bits `0` or `1`?
  230: Well, this doesn't work, as network- and broadcast-address must be present!
  231: Because of this, a class B (/16) network can contain at most 2^16-2 hosts, a
  232: class C (/24) network can hold no more than 2^8-2 = 254 hosts.
  233: 
  234: Besides all those categories of addresses, there's the special IP-address
  235: 127.0.0.1 which always refers to the *local* host, i.e. if you talk to 127.0.0.1
  236: you'll talk to yourself without starting any network-activity. This is sometimes
  237: useful to use services installed on your own machine or to play around if you
  238: don't have other hosts to put on your network.
  239: 
  240: Let's put together the things we've introduced in this section:
  241: 
  242:  * *IP-address* -- 32 bit-address, with network- and host-bits.
  243:  * *Network-address* -- IP-address with all host bits set to `0`.
  244:  * *Netmask* -- 32-bit mask with `1` for network- and `0` for host-bits.
  245:  * *Broadcast* -- IP-address with all host bits set `1`.
  246:  * *localhost's address* -- The local host's IP address is always 127.0.0.1.
  247: 
  248: ## Subnetting and Routing
  249: 
  250: After talking so much about netmasks, network-, host- and other addresses, I
  251: have to admit that this is not the whole truth.
  252: 
  253: Imagine the situation at your university, which usually has a class B (/16)
  254: address, allowing it to have up to 2^16 ~= 65534 hosts on that net. Maybe it
  255: would be a nice thing to have all those hosts on one single network, but it's
  256: simply not possible due to limitations in the transport media commonly used
  257: today.
  258: 
  259: For example, when using thinwire ethernet, the maximum length of the cable is
  260: 185 meters. Even with repeaters in between, which refresh the signals, this is
  261: not enough to cover all the locations where machines are located. Besides that,
  262: there is a maximum number of 1024 hosts on one ethernet wire, and you'll lose
  263: quite a bit of performance if you go to this limit.
  264: 
  265: So, are you hosed now? Having an address which allows more than 60000 hosts, but
  266: being bound to media which allows far less than that limit?
  267: 
  268: Well, of course not! :-)
  269: 
  270: The idea is to divide the *big* class B net into several smaller networks,
  271: commonly called sub-networks or simply subnets. Those subnets are only allowed
  272: to have, say, 254 hosts on them (i.e. you divide one big class B network into
  273: several class C networks!).
  274: 
  275: To do this, you adjust your netmask to have more network- and less host-bits on
  276: it. This is usually done on a byte-boundary, but you're not forced to do it
  277: there. So, commonly your netmask will not be 255.255.0.0 as supposed by a class
  278: B network, but it will be set to 255.255.255.0.
  279: 
  280: In CIDR notation, you now write a `/24` instead of the `/16` to show that 24
  281: bits of the address are used for identifying the network and subnet, instead of
  282: the 16 that were used before.
  283: 
  284: This gives you one additional network-byte to assign to each (physical!)
  285: network. All the 254 hosts on that subnet can now talk directly to each other,
  286: and you can build 256 such class C nets. This should fit your needs.
  287: 
  288: To explain this better, let's continue our above example. Say our host
  289: 132.199.15.99 (I'll call him `dusk` from now; we'll talk about assigning
  290: hostnames later) has a netmask of 255.255.255.0 and thus is on the subnet
  291: 132.199.15.0/24. Let's furthermore introduce some more hosts so we have
  292: something to play around with, see the next figure.
  293: 
  294: ![Our demo-network](/guide/images/net-pic1.gif)  
  295: **Our demo-network**
  296: 
  297: In the above network, `dusk` can talk directly to `dawn`, as they are both on
  298: the same subnet. (There are other hosts attached to the 132.199.15.0/24-subnet
  299: but they are not of importance for us now)
  300: 
  301: But what if `dusk` wants to talk to a host on another subnet?
  302: 
  303: Well, the traffic will then go through one or more gateways (routers), which are
  304: attached to two subnets. Because of this, a router always has two different
  305: addresses, one for each of the subnets it is on. The router is functionally
  306: transparent, i.e. you don't have to address it to reach hosts on the *other*
  307: side. Instead, you address that host directly and the packets will be routed to
  308: it correctly.
  309: 
  310: Example. Let's say `dusk` wants to get some files from the local ftp-server. As
  311: `dusk` can't reach `ftp` directly (because it's on a different subnet), all its
  312: packets will be forwarded to its "defaultrouter" `rzi` (132.199.15.1), which
  313: knows where to forward the packets.
  314: 
  315: `Dusk` knows the address of its defaultrouter in its network (`rzi`,
  316: 132.199.15.1), and it will forward any packets to it which are not on the same
  317: subnet, i.e. it will forward all IP-packets in which the third address-byte
  318: isn't 15.
  319: 
  320: The (default)router then gives the packets to the appropriate host, as it's also
  321: on the FTP-server's network.
  322: 
  323: In this example, *all* packets are forwarded to the 132.199.1.0/24-network,
  324: simply because it's the network's backbone, the most important part of the
  325: network, which carries all the traffic that passes between several subnets.
  326: Almost all other networks besides 132.199.15.0/24 are attached to the backbone
  327: in a similar manner.
  328: 
  329: But what if we had hooked up another subnet to 132.199.15.0/24 instead of
  330: 132.199.1.0/24? Maybe something the situation displayed in the next figure.
  331: 
  332: ![Attaching one subnet to another one](/guide/images/net-pic2.gif)  
  333: **Attaching one subnet to another one**
  334: 
  335: When we now want to reach a host which is located in the 132.199.16.0/24-subnet
  336: from `dusk`, it won't work routing it to `rzi`, but you'll have to send it
  337: directly to `route2` (132.199.15.2). `Dusk` will have to know to forward those
  338: packets to `route2` and send all the others to `rzi`.
  339: 
  340: When configuring `dusk`, you tell it to forward all packets for the
  341: 132.199.16.0/24-subnet to `route2`, and all others to `rzi`. Instead of
  342: specifying this default as 132.199.1.0/24, 132.199.2.0/24, etc., 0.0.0.0 can be
  343: used to set the default-route.
  344: 
  345: Returning to our demo network, there's a similar problem when `dawn` wants to
  346: send to `noon`, which is connected to `dusk` via a serial line running. When
  347: looking at the IP-addresses, `noon` seems to be attached to the
  348: 132.199.15.0-network, but it isn't really. Instead, `dusk` is used as gateway,
  349: and `dawn` will have to send its packets to `dusk`, which will forward them to
  350: `noon` then. The way `dusk` is forced into accepting packets that aren't
  351: destined at it but for a different host (`noon`) instead is called *proxy arp*.
  352: 
  353: The same goes when hosts from other subnets want to send to `noon`. They have to
  354: send their packets to `dusk` (possibly routed via `rzi`),
  355: 
  356: ## Name Service Concepts
  357: 
  358: In the previous sections, when we talked about hosts, we referred to them by
  359: their IP-addresses. This was necessary to introduce the different kinds of
  360: addresses. When talking about hosts in general, it's more convenient to give
  361: them *names*, as we did when talking about routing.
  362: 
  363: Most applications don't care whether you give them an IP address or a hostname.
  364: However, they'll use IP addresses internally, and there are several methods for
  365: them to map hostnames to IP addresses, each one with its own way of
  366: configuration. In this section we'll introduce the idea behind each method, in
  367: the next chapter, we'll talk about the configuration-part.
  368: 
  369: The mapping from hostnames (and domainnames) to IP-addresses is done by a piece
  370: of software called the *resolver*. This is not an extra service, but some
  371: library routines which are linked to every application using networking-calls.
  372: The resolver will then try to resolve (hence the name ;-) the hostnames you give
  373: into IP addresses. See [RFC1034](http://tools.ietf.org/html/rfc1034) ("Domain
  374: names - concepts and facilities") and
  375: [RFC1035](http://tools.ietf.org/html/rfc1035) ("Domain names - implementation
  376: and specification") for details on the resolver.
  377: 
  378: Hostnames are usually up to 256 characters long, and contain letters, numbers
  379: and dashes (`-`); case is ignored.
  380: 
  381: Just as with networks and subnets, it's possible (and desirable) to group hosts
  382: into domains and subdomains. When getting your network-address, you usually also
  383: obtain a domainname by your provider. As with subnets, it's up to you to
  384: introduce subdomains. Other as with IP-addresses, (sub)domains are not directly
  385: related to (sub)nets; for example, one domain can contain hosts from several
  386: subnets.
  387: 
  388: Our demo-network shows this: Both subnets 132.199.1.0/24 and 132.199.15.0/24
  389: (and others) are part of the subdomain `rz.uni-regensburg.de`. The domain the
  390: University of Regensburg got from its IP-provider is `uni-regensburg.de` (`.de`
  391: is for Deutschland, Germany), the subdomain `rz` is for Rechenzentrum, computing
  392: center.
  393: 
  394: Hostnames, subdomain- and domainnames are separated by dots (`.`). It's also
  395: possible to use more than one stage of subdomains, although this is not very
  396: common. An example would be `fox_in.socs.uts.edu.au`.
  397: 
  398: A hostname which includes the (sub)domain is also called a fully qualified
  399: domain name (FQDN). For example, the IP-address 132.199.15.99 belongs to the
  400: host with the FQDN `dusk.rz.uni-regensburg.de`.
  401: 
  402: Further above I told you that the IP-address 127.0.0.1 always belongs to the
  403: local host, regardless what's the `real` IP-address of the host. Therefore,
  404: 127.0.0.1 is always mapped to the name `localhost`.
  405: 
  406: The three different ways to translate hostnames into IP addresses are:
  407: `/etc/hosts`, the Domain Name Service (DNS) and the Network Information Service
  408: (NIS).
  409: 
  410: ### /etc/hosts
  411: 
  412: The first and simplest way to translate hostnames into IP-addresses is by using
  413: a table telling which IP address belongs to which hostname(s). This table is
  414: stored in the file `/etc/hosts` and has the following format:
  415: 
  416:     IP-address        hostname [nickname [...]]
  417: 
  418: Lines starting with a hash mark (`#`) are treated as comments. The other lines
  419: contain one IP-address and the corresponding hostname(s).
  420: 
  421: It's not possible for a hostname to belong to several IP addresses, even if I
  422: made you think so when talking about routing. `rzi` for example has really two
  423: distinct names for each of its two addresses: `rzi` and `rzia` (but please don't
  424: ask me which name belongs to which address!).
  425: 
  426: Giving a host several nicknames can be convenient if you want to specify your
  427: favorite host providing a special service with that name, as is commonly done
  428: with FTP-servers. The first (leftmost) name is usually the real (canonical) name
  429: of the host.
  430: 
  431: Besides giving nicknames, it's also convenient to give a host's full name
  432: (including domain) as its canonical name, and using only its hostname (without
  433: domain) as a nickname.
  434: 
  435: *Important:* There *must* be an entry mapping localhost to 127.0.0.1 in
  436: `/etc/hosts`!
  437: 
  438: ### Domain Name Service (DNS)
  439: 
  440: `/etc/hosts` bears an inherent problem, especially in big networks: when one
  441: host is added or one host's address changes, all the `/etc/hosts` files on all
  442: machines have to be changed! This is not only time-consuming, it's also very
  443: likely that there will be some errors and inconsistencies, leading to problems.
  444: 
  445: Another approach is to hold only one hostnames-table (-database) for a network,
  446: and make all the clients query that *nameserver*. Updates will be made only on
  447: the nameserver.
  448: 
  449: This is the basic idea behind the Domain Name Service (DNS).
  450: 
  451: Usually, there's one nameserver for each domain (hence DNS), and every host
  452: (client) in that domain knows which domain it is in and which nameserver to
  453: query for its domain.
  454: 
  455: When the DNS gets a query about a host which is not in its domain, it will
  456: forward the query to a DNS which is either the DNS of the domain in question or
  457: knows which DNS to ask for the specified domain. If the DNS forwarded the query
  458: doesn't know how to handle it, it will forward that query again to a DNS one
  459: step higher. This is not ad infinitum, there are several *root*-servers, which
  460: know about any domain.
  461: 
  462: See [[the separate article|guide/dns]] for details on DNS.
  463: 
  464: ### Network Information Service (NIS/YP)
  465: 
  466: Yellow Pages (YP) was invented by Sun Microsystems. The name has been changed
  467: into Network Information Service (NIS) because YP was already a trademark of the
  468: British telecom. So, when I'm talking about NIS you'll know what I mean. ;-)
  469: 
  470: There are quite some configuration files on a Unix-system, and often it's
  471: desired to maintain only one set of those files for a couple of hosts. Those
  472: hosts are grouped together in a NIS-domain (which has *nothing* to do with the
  473: domains built by using DNS!) and are usually contained in one workstation
  474: cluster.
  475: 
  476: Examples for the config-files shared among those hosts are `/etc/passwd`,
  477: `/etc/group` and - last but not least - `/etc/hosts`.
  478: 
  479: So, you can "abuse" NIS for getting a unique name-to-address-translation on all
  480: hosts throughout one (NIS-)domain.
  481: 
  482: There's only one drawback, which prevents NIS from actually being used for that
  483: translation: In contrast to the DNS, NIS provides no way to resolve hostnames
  484: which are not in the hosts-table. There's no hosts "one level up" which the
  485: NIS-server can query, and so the translation will fail! Suns NIS+ takes measures
  486: against that problem, but as NIS+ is only available on Solaris-systems, this is
  487: of little use for us now.
  488: 
  489: Don't get me wrong: NIS is a fine thing for managing e.g. user-information
  490: (`/etc/passwd`, ...) in workstation-clusters, it's simply not too useful for
  491: resolving hostnames.
  492: 
  493: ### Other
  494: 
  495: The name resolving methods described above are what's used commonly today to
  496: resolve hostnames into IP addresses, but they aren't the only ones. Basically,
  497: every database mechanism would do, but none is implemented in NetBSD. Let's have
  498: a quick look what you may encounter.
  499: 
  500: With NIS lacking hierarchy in data structures, NIS+ is intended to help out in
  501: that field. Tables can be setup in a way so that if a query cannot be answered
  502: by a domain's server, there can be another domain "above" that might be able to
  503: do so. E.g. you could choose to have a domain that lists all the hosts (users,
  504: groups, ...) that are valid in the whole company, one that defines the same
  505: for each division, etc. NIS+ is not used a lot today, even Sun went back to
  506: ship back NIS by default.
  507: 
  508: Last century, the X.500 standard was designed to accommodate both simple
  509: databases like `/etc/hosts` as well as complex, hierarchical systems as can be
  510: found e.g. in DNS today. X.500 wasn't really a success, mostly due to the fact
  511: that it tried to do too much at the same time. A cut-down version is available
  512: today as the Lightweight Directory Access Protocol (LDAP), which is becoming
  513: popular in the last years to manage data like users but also hosts and others in
  514: small to medium sized organisations.
  515: 
  516: ## Next generation Internet protocol - IPv6
  517: 
  518: ### The Future of the Internet
  519: 
  520: According to experts, the Internet as we know it will face a serious problem in
  521: a few years. Due to its rapid growth and the limitations in its design, there
  522: will be a point at which no more free addresses are available for connecting new
  523: hosts. At that point, no more new web servers can be set up, no more users can
  524: sign up for accounts at ISPs, no more new machines can be setup to access the
  525: web or participate in online games - some people may call this a serious
  526: problem.
  527: 
  528: Several approaches have been made to solve the problem. A very popular one is to
  529: not assign a worldwide unique address to every user's machine, but rather to
  530: assign them *private* addresses, and hide several machines behind one official,
  531: globally unique address. This approach is called *Network Address Translation*
  532: (NAT, also known as IP Masquerading). It has problems, as the machines hidden
  533: behind the global address can't be addressed, and as a result of this, opening
  534: connections to them - which is used in online gaming, peer to peer networking,
  535: etc. - is not possible. For a more in-depth discussion of the drawbacks of NAT,
  536: see \[[[RFC3027|guide/index#bilbiography]]\] ("Protocol Complications with the
  537: IP Network Address Translator").
  538: 
  539: A different approach to the problem of internet addresses getting scarce is to
  540: abandon the old Internet protocol with its limited addressing capabilities, and
  541: use a new protocol that does not have these limitations. The protocol - or
  542: actually, a set of protocols - used by machines connected to form today's
  543: Internet is know as the TCP/IP (Transmission Control Protocol, Internet
  544: Protocol) suite, and version 4 currently in use has all the problems described
  545: above. Switching to a different protocol version that does not have these
  546: problems of course requires for a 'better' version to be available, which
  547: actually is. Version 6 of the Internet Protocol (IPv6) does fulfill any possible
  548: future demands on address space, and also addresses further features such as
  549: privacy, encryption, and better support of mobile computing.
  550: 
  551: Assuming a basic understanding of how today's IPv4 works, this text is intended
  552: as an introduction to the IPv6 protocol. The changes in address formats and name
  553: resolution are covered. With the background given here, the next sections will
  554: show how to use IPv6 even if your ISP doesn't offer it by using a simple yet
  555: efficient transition mechanism called 6to4. The goal is to get online with IPv6,
  556: giving an example configuration for NetBSD.
  557: 
  558: ### What good is IPv6?
  559: 
  560: When telling people to migrate from IPv4 to IPv6, the question you usually hear
  561: is *why?*. There are actually a few good reasons to move to the new version:
  562: 
  563:  * Bigger address space
  564:  * Support for mobile devices
  565:  * Built-in security
  566: 
  567: #### Bigger Address Space
  568: 
  569: The bigger address space that IPv6 offers is the most obvious enhancement it has
  570: over IPv4. While today's internet architecture is based on 32-bit wide
  571: addresses, the new version has 128 bit available for addressing. Thanks to the
  572: enlarged address space, work-arounds like NAT don't have to be used any more.
  573: This allows full, unconstrained IP connectivity for today's IP based machines as
  574: well as upcoming mobile devices like PDAs and cell phones will benefit from full
  575: IP access through GPRS and UMTS.
  576: 
  577: #### Mobility
  578: 
  579: When mentioning mobile devices and IP, another important point to note is that
  580: some special protocol is needed to support mobility, and implementing this
  581: protocol - called *Mobile IP* - is one of the requirements for every IPv6 stack.
  582: Thus, if you have IPv6 going, you have support for roaming between different
  583: networks, with everyone being updated when you leave one network and enter the
  584: other one. Support for roaming is possible with IPv4 too, but there are a number
  585: of hoops that need to be jumped in order to get things working. With IPv6,
  586: there's no need for this, as support for mobility was one of the design
  587: requirements for IPv6. See [RFC3024](http://tools.ietf.org/html/rfc3024)
  588: ("Reverse Tunneling for Mobile IP") for some more information on the issues that
  589: need to be addressed with Mobile IP on IPv4.
  590: 
  591: #### Security
  592: 
  593: Besides support for mobility, security was another requirement for the successor
  594: to today's Internet Protocol version. As a result, IPv6 protocol stacks are
  595: required to include IPsec. IPsec allows authentication, encryption and
  596: compression of any IP traffic. Unlike application level protocols like SSL or
  597: SSH, all IP traffic between two nodes can be handled, without adjusting any
  598: applications. The benefit of this is that all applications on a machine can
  599: benefit from encryption and authentication, and that policies can be set on a
  600: per-host (or even per-network) base, not per application/service. An
  601: introduction to IPsec with a roadmap to the documentation can be found in
  602: [RFC2411](http://tools.ietf.org/html/rfc2411) ("IP Security Document Roadmap"),
  603: the core protocol is described in [RFC2401](http://tools.ietf.org/html/rfc2401)
  604: ("Security Architecture for the Internet Protocol").  
  605: 
  606: ### Changes to IPv4
  607: 
  608: After giving a brief overview of all the important features of IPv6, we'll go
  609: into the details of the basics of IPv6 here. A brief understanding of how IPv4
  610: works is assumed, and the changes in IPv6 will be highlighted. Starting with
  611: IPv6 addresses and how they're split up we'll go into the various types of
  612: addresses there are, what became of broadcasts, then after discussing the IP
  613: layer go into changes for name resolving and what's new in DNS for IPv6.
  614: 
  615: #### Addressing
  616: 
  617: An IPv4 address is a 32 bit value, that's usually written in *dotted quad*
  618: representation, where each *quad* represents a byte value between 0 and 255, for
  619: example:
  620: 
  621:     127.0.0.1
  622: 
  623: This allows a theoretical number of 2^32 or ~4 billion hosts to be connected on
  624: the internet today. Due to grouping, not all addresses are available today.
  625: 
  626: IPv6 addresses use 128 bit, which results in 2^128 theoretically addressable
  627: hosts. This allows for a Really Big number of machines to addressed, and it sure
  628: fits all of today's requirements plus all those nifty PDAs and cell phones with
  629: IP phones in the near future without any sweat. When writing IPv6 addresses,
  630: they are usually divided into groups of 16 bits written as four hex digits, and
  631: the groups are separated by colons. An example is:
  632: 
  633:     fe80::2a0:d2ff:fea5:e9f5
  634: 
  635: This shows a special thing - a number of consecutive zeros can be abbreviated by
  636: a single `::` once in the IPv6 address. The above address is thus equivalent to
  637: `fe80:0:00:000:2a0:d2ff:fea5:e9f5` - leading zeros within groups can be omitted,
  638: and only one `::` can be used in an IPv6 address.
  639: 
  640: To make addresses manageable, they are split in two parts, which are the bits
  641: identifying the network a machine is on, and the bits that identify a machine on
  642: a (sub)network. The bits are known as netbits and hostbits, and in both IPv4 and
  643: IPv6, the netbits are the *left*, most significant bits of an IP address, and
  644: the host bits are the *right*, least significant bits, as shown in the following
  645: figure:
  646: 
  647: ![IPv6-addresses are divided into more significant network- and less significant hostbits, too](/guide/images/ipv6-en-0bits.gif)  
  648: **IPv6-addresses are divided into more significant network- and less significant hostbits, too**
  649: 
  650: In IPv4, the border is drawn with the aid of the netmask, which can be used to
  651: mask all net/host bits. Typical examples are 255.255.0.0 that uses 16 bit for
  652: addressing the network, and 16 bit for the machine, or 255.255.255.0 which takes
  653: another 8 bit to allow addressing 256 subnets on e.g. a class B net.
  654: 
  655: When addressing switched from classful addressing to CIDR routing, the borders
  656: between net and host bits stopped being on 8 bit boundaries, and as a result the
  657: netmasks started looking ugly and not really manageable. As a replacement, the
  658: number of network bits is used for a given address, to denote the border, e.g.
  659: 
  660:     10.0.0.0/24
  661: 
  662: is the same as a netmask of 255.255.255.0 (24 1-bits). The same scheme is used
  663: in IPv6:
  664: 
  665:     2001:638:a01:2::/64
  666: 
  667: tells us that the address used here has the first (leftmost) 64 bits used as the
  668: network address, and the last (rightmost) 64 bits are used to identify the
  669: machine on the network. The network bits are commonly referred to as (network)
  670: *prefix*, and the *prefixlen* here would be 64 bits.
  671: 
  672: Common addressing schemes found in IPv4 are the (old) class B and class C nets.
  673: With a class C network (/24), you get 24 bits assigned by your provider, and it
  674: leaves 8 bits to be assigned by you. If you want to add any subnetting to that,
  675: you end up with *uneven* netmasks that are a bit nifty to deal with. Easier for
  676: such cases are class B networks (/16), which only have 16 bits assigned by the
  677: provider, and that allow subnetting, i.e. splitting of the rightmost bits into
  678: two parts. One to address the on-site subnet, and one to address the hosts on
  679: that subnet. Usually, this is done on byte (8 bit) boundaries. Using a netmask
  680: of 255.255.255.0 (or a /24 prefix) allows flexible management even of bigger
  681: networks here. Of course there is the upper limit of 254 machines per subnet,
  682: and 256 subnets.
  683: 
  684: With 128 bits available for addressing in IPv6, the scheme commonly used is the
  685: same, only the fields are wider. Providers usually assign /48 networks, which
  686: leaves 16 bits for a subnetting and 64 hostbits.
  687: 
  688: ![IPv6-addresses have a similar structure to class B addresses](/guide/images/ipv6-en-6adrformats.gif)  
  689: **IPv6-addresses have a similar structure to class B addresses**
  690: 
  691: Now while the space for network and subnets here is pretty much ok, using 64
  692: bits for addressing hosts seems like a waste. It's unlikely that you will want
  693: to have several billion hosts on a single subnet, so what is the idea behind
  694: this?
  695: 
  696: The idea behind fixed width 64 bit wide host identifiers is that they aren't
  697: assigned manually as it's usually done for IPv4 nowadays. Instead, IPv6 host
  698: addresses are recommended (not mandatory!) to be built from so-called EUI64
  699: addresses. EUI64 addresses are - as the name says - 64 bit wide, and derived
  700: from MAC addresses of the underlying network interface. E.g. for ethernet, the 6
  701: byte (48 bit) MAC address is usually filled with the hex bits `fffe` in the
  702: middle and a bit is set to mark the address as unique (which is true for
  703: Ethernet), e.g. the MAC address
  704: 
  705:     01:23:45:67:89:ab
  706: 
  707: results in the EUI64 address
  708: 
  709:     03:23:45:ff:fe:67:89:ab
  710: 
  711: which again gives the host bits for the IPv6 address as
  712: 
  713:     ::0323:45ff:fe67:89ab
  714: 
  715: These host bits can now be used to automatically assign IPv6 addresses to hosts,
  716: which supports autoconfiguration of IPv6 hosts - all that's needed to get a
  717: complete IPv6 address is the first (net/subnet) bits, and IPv6 also offers a
  718: solution to assign them automatically.
  719: 
  720: When on a network of machines speaking IP, there's usually one router which acts
  721: as the gateway to outside networks. In IPv6 land, this router will send *router
  722: advertisement* information, which clients are expected to either receive during
  723: operation or to solicit upon system startup. The router advertisement
  724: information includes data on the router's address, and which address prefix it
  725: routes. With this information and the host-generated EUI64 address, an IPv6-host
  726: can calculate its IP address, and there is no need for manual address
  727: assignment. Of course routers still need some configuration.
  728: 
  729: The router advertisement information they create are part of the Neighbor
  730: Discovery Protocol (NDP, see [RFC2461](http://tools.ietf.org/html/rfc2461)
  731: ("Neighbor Discovery for IP Version 6 (IPv6)")), which is the successor to
  732: IPv4's ARP protocol. In contrast to ARP, NDP does not only do lookup of IPv6
  733: addresses for MAC addresses (the neighbor solicitation/advertisement part), but
  734: also does a similar service for routers and the prefixes they serve, which is
  735: used for autoconfiguration of IPv6 hosts as described in the previous paragraph.
  736: 
  737: #### Multiple Addresses
  738: 
  739: In IPv4, a host usually has one IP address per network interface or even per
  740: machine if the IP stack supports it. Only very rare applications like web
  741: servers result in machines having more than one IP address. In IPv6, this is
  742: different. For each interface, there is not only a globally unique IP address,
  743: but there are two other addresses that are of interest: The link local address,
  744: and the site local address. The link local address has a prefix of fe80::/64,
  745: and the host bits are built from the interface's EUI64 address. The link local
  746: address is used for contacting hosts and routers on the same network only, the
  747: addresses are not visible or reachable from different subnets. If wanted,
  748: there's the choice of either using global addresses (as assigned by a provider),
  749: or using site local addresses. Site local addresses are assigned the network
  750: address fec0::/10, and subnets and hosts can be addressed just as for
  751: provider-assigned networks. The only difference is, that the addresses will not
  752: be visible to outside machines, as these are on a different network, and their
  753: *site local* addresses are in a different physical net (if assigned at all). As
  754: with the 10/8 network in IPv4, site local addresses can be used, but don't have
  755: to. For IPv6 it's most common to have hosts assigned a link-local and a global
  756: IP address. Site local addresses are rather uncommon today, and are no
  757: substitute for globally unique addresses if global connectivity is required.
  758: 
  759: #### Multicasting
  760: 
  761: In IP land, there are three ways to talk to a host: unicast, broadcast and
  762: multicast. The most common one is by talking to it directly, using its unicast
  763: address. In IPv4, the unicast address is the *normal* IP address assigned to a
  764: single host, with all address bits assigned. The broadcast address used to
  765: address all hosts in the same IP subnet has the network bits set to the network
  766: address, and all host bits set to `1` (which can be easily done using the
  767: netmask and some bit operations). Multicast addresses are used to reach a number
  768: of hosts in the same multicast group, which can be machines spread over the
  769: whole internet. Machines must join multicast groups explicitly to participate,
  770: and there are special IPv4 addresses used for multicast addresses, allocated
  771: from the 224/8 subnet. Multicast isn't used very much in IPv4, and only few
  772: applications like the MBone audio and video broadcast utilities use it.
  773: 
  774: In IPv6, unicast addresses are used the same as in IPv4, no surprise there - all
  775: the network and host bits are assigned to identify the target network and
  776: machine. Broadcasts are no longer available in IPv6 in the way they were in
  777: IPv4, this is where multicasting comes into play. Addresses in the ff::/8
  778: network are reserved for multicast applications, and there are two special
  779: multicast addresses that supersede the broadcast addresses from IPv4. One is the
  780: *all routers* multicast address, the others is for *all hosts*. The addresses
  781: are specific to the subnet, i.e. a router connected to two different subnets can
  782: address all hosts/routers on any of the subnets it's connected to. Addresses
  783: here are:
  784: 
  785:  * ff0*`X`*::1 for all hosts and
  786:  * ff0*`X`*::2 for all routers,
  787: 
  788: where `X` is the scope ID of the link here, identifying the network. Usually
  789: this starts from `1` for the *node local* scope, `2` for the first link, etc.
  790: Note that it's perfectly ok for two network interfaces to be attached to one
  791: link, thus resulting in double bandwidth:
  792: 
  793: ![Several interfaces attached to a link result in only one scope ID for the link](/guide/images/ipv6-en-4scope.gif)  
  794: **Several interfaces attached to a link result in only one scope ID for the link**
  795: 
  796: One use of the *all hosts* multicast is in the neighbor solicitation code of
  797: NDP, where any machine that wants to communicate with another machine sends out
  798: a request to the *all hosts* group, and the machine in question is expected to
  799: respond.
  800: 
  801: #### Name Resolving in IPv6
  802: 
  803: After talking a lot about addressing in IPv6, anyone still here will hope that
  804: there's a proper way to abstract all these long & ugly IPv6 addresses with some
  805: nice hostnames as one can do in IPv4, and of course there is.
  806: 
  807: Hostname to IP address resolving in IPv4 is usually done in one of three ways:
  808: using a simple table in `/etc/hosts`, by using the Network Information Service
  809: (NIS, formerly YP) or via the Domain Name System (DNS).
  810: 
  811: As of this writing, NIS/NIS+ over IPv6 is currently only available on Solaris 8,
  812: for both database contents and transport, using a RPC extension.
  813: 
  814: Having a simple address<-\>name map like `/etc/hosts` is supported in all IPv6
  815: stacks. With the KAME implementation used in NetBSD, `/etc/hosts` contains IPv6
  816: addresses as well as IPv4 addresses. A simple example is the `localhost` entry
  817: in the default NetBSD installation:
  818: 
  819:     127.0.0.1               localhost
  820:     ::1                     localhost
  821: 
  822: For DNS, there are no fundamentally new concepts. IPv6 name resolving is done
  823: with AAAA records that - as the name implies - point to an entity that's four
  824: times the size of an A record. The AAAA record takes a hostname on the left
  825: side, just as A does, and on the right side there's an IPv6 address, e.g.
  826: 
  827:     noon            IN      AAAA    3ffe:400:430:2:240:95ff:fe40:4385
  828: 
  829: For reverse resolving, IPv4 uses the in-addr.arpa zone, and below that it writes
  830: the bytes (in decimal) in reversed order, i.e. more significant bytes are more
  831: right. For IPv6 this is similar, only that hex digits representing 4 bits are
  832: used instead of decimal numbers, and the resource records are also under a
  833: different domain, ip6.int.
  834: 
  835: So to have the reverse resolving for the above host, you would put into your
  836: `/etc/named.conf` something like:
  837: 
  838:     zone "0.3.4.0.0.0.4.0.e.f.f.3.IP6.INT" {
  839:           type master;
  840:           file "db.reverse";
  841:     };
  842: 
  843: and in the zone file db.reverse you put (besides the usual records like SOA and
  844: NS):
  845: 
  846:     5.8.3.4.0.4.e.f.f.f.5.9.0.4.2.0.2.0.0.0 IN   PTR   noon.ipv6.example.com.
  847: 
  848: The address is reversed here, and written down one hex digit after the other,
  849: starting with the least significant (rightmost) one, separating the hex digits
  850: with dots, as usual in zone files.
  851: 
  852: One thing to note when setting up DNS for IPv6 is to take care of the DNS
  853: software version in use. BIND 8.x does understand AAAA records, but it does not
  854: offer name resolving via IPv6. You need BIND 9.x for that. Beyond that, BIND 9.x
  855: supports a number of resource records that are currently being discussed but not
  856: officially introduced yet. The most noticeable one here is the A6 record which
  857: allows easier provider/prefix changing.
  858: 
  859: To sum up, this section talked about the technical differences between IPv4 and
  860: IPv6 for addressing and name resolving. Some details like IP header options, QoS
  861: and flows were deliberately left out to not make this document more complex than
  862: necessary.
  863: 

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb