这一章 (介绍 TCP/IP 网路) 是由 Hubert Feyrer <hubert@feyrer.de> 所贡献的。
在这本指导手册中,有关网路的这一章,解释了有关网路方面的各种 基本知识,是为了帮助初学者而设计的。它分成了三部份。 一开始,我们让你大概了解网路是如何运作的,并介绍基本的概念。 接著,我们会进一步地说明各种不同类型网路的设定。在第三部份中, 会涵盖各种在前两部份中,未提到的"进阶"课题。
我们假设读者已经知道一些基本的系统管理工作:如何成为 root, 编辑档案,更改权限,终止程序,等。在 [AeleenFrisch] 中可以得到这方面的资讯。此外, 你应该了解如何使用一些基本的工具,例如,你应该知道如何使用 telnet, FTP, ...。我将不会解释这些工具的基本用法,请参考相关的 man-pages,或是这本手册的其他章节。
这一章的目的是为了让初学者具备基本的 TCP/IP 网路的知识。 如果你想要一窥全貌,可以参阅 [CraigHunt]。 这本书不只包含了基础的部份,更解释了所有的概念,服务程式并详细 说明如何设定它们。它很棒,我喜欢这本书! :-)
NetBSD 支援好几种协定,大部份是来自 NetBSD 的前身,4.4BSD, 并经过而后的增强和改进。 第一个,也是最重要的一个是 DARPA 的 Transmission Control Protocoll/Internet Protocoll (TCP/IP)。 其他在 NetBSD 中有效的协定包括 Xerox Network System (XNS),只被在 UCB 中 用来连接单独的机器到网路上,Apple 的 AppleTalk 协定和 ISO 协定,CCITT X.25 和 ARGO TP。 在今日,它们只用在一些特别的应用上。
在今日,TCP/IP 是在上述的协定中,最被广泛应用的一个。它在大部 份的硬体和作业系统上被执行,也是在各种不同环境中,最常使用的 协定。所以,如果你只是要连接执行 NetBSD 的电脑到家里其他的机器, 或是你想要将它整合到你公司或学校的网路,TCP/IP 是正确的选择。
IPv6 (TCP/IP 协定的版本 6,目前的版本是 IPv4) 仍在发展当中, 而 KAME 专案的 IPv6 程式码已经被整合到 NetBSD 中,并且开始发行在 NetBSD 1.5 release 中。
有关其他的协定,像是 DECNET,Novell 的 IPX/SPX 或是 Microsoft 的 NetBIOS,目前还未被 NetBSD 所支援。这两种协定不同于上述 的是,它们是专有的,不像其他的协定是被完整地定义在数种 RFC 和其他开放的标准中。
TCP/IP 可以被广泛地应用在各种不同的媒体上。其中被 NetBSD 所 支援的有 Ethernet (10/100/1000MBd), Arcnet, serial line, ATM, FDDI, Fiber Channel, USB, HIPPI, FireWire (IEEE 1394), Token Ring 等。
在一些情况下,你需要在序列线上使用 TCP/IP。
如果你的远端主机只能经由电话线连线,你可以使用数据机来 连接它。
在今日,几乎每一台电脑都具备序列埠,而连接用的缆线也是 相当便宜。
使用序列线连接的缺点是,它的传输速率比其他的方法都来得慢。 NetBSD 最大可以使用 115200 bit/s,但仍比其他方式,如: Ethernet 的最小值 10 Mbit/s 和 Arcnet 的 4 Mbit/s 都慢得多。
There are two possible protocols to connect a host running NetBSD to another host using a serial line (possibly over a phone-line): 想要使用序列线(可能是一条电话线)将一台跑著 NetBSD 的主机, 连接到另一台,有两种协定可以使用:
Serial Line IP (SLIP)
Point to Point Protocol (PPP)
我们需要依照实际情况来决定使用那一种协定。如果你使用拨接作为 IP 连线,最好使用 PPP,因为它提供了一些功能,如自动交涉 ip 位址和路径,这些如果用手动设定是相当麻烦的。如果你想要直接连线 到另一台机器上,则使用 SLIP,因为几乎每一种作业系统都支援它, 而且在固定位址和路径的情况下,它比较容易设定。
PPP 在直接连线的情况下,是比较难设定的,它容易因为在最初的 信号交换时间过久而中断;而 SLIP 则无此信号交换程序。
[RFC1331] and [RFC1332] describe PPP and TCP/IP over PPP. SLIP is defined in [RFC1055].
Ethernet 一般常用于建立区域网路 (LANs), 让有限范围内的机器连接在一起,像是办公室,公司或学校的计算机中心 等。Ethernet 是以 bus 作为基础的,有许多机器可以连接其中,而且 每一次的通讯都发生在两个节点之间,如果由超过两个以上的节点想要 交换资讯,则两者都必须在一段时间的暂停之后,重新启动通讯程序。 技术性的术语为 CSMA/CD (Carrier Sense w/ Multiple Access and Collision Detection)。
起初,Ethernet 硬体是由粗线(thick (yellow) cable)所构成, 需要去掉缆线一部分的外皮,并打入一个特殊的接头才能使用。 成功的例子叫做 10base5,使用 BNC 接头与 T 接头连接后,连到 bus 上的两个终端器(terminators)。在今日,ethernet 大部份是 在便宜的 bus 系统上使用双绞线,以及交换器(switches)或集线器 (hubs)。双绞线这类型的媒体名称为 - 10baseT 表示 10 Mbit/s 速率的网路,和 100baseT 表示 100 MBit/s 速率的网路。从资讯 交换的情形来看,又可分为全双工和半双工模式。
TCP/IP 在目前实行的版本(IPv4)上使用 4-byte (32-bit) 位址, 也叫做 IP-numbers (Internet-Protocol numbers),来为各个 主机定址。
TCP/IP 允许任意两台机器进行直接地沟通。为了执行这项功能, 在既定网路上的所有主机都必须有一个独特的 IP 位址。为了确保其 独特性,IP 位址都由一个主要的组织 InterNIC 来集中管理。他们 将一定范围的位址(网路位址),直接给那些想要参与网际网路的站台, 或是网际网路的提供者,进而将这些位址分别交给他们的顾客。
如果你的学校或公司有连接到网际网路,则它已经(至少)有一个网路位址 供它自己使用,通常不是直接由 InterNIC 分配的,大多是经由网际网路 服务提供者(ISP)所取得的。
如果你只是想要在家里执行你私有的网路,请看底下有关如何"建立" 自有 IP 位址的那一段落。但是,如果你要直接将你的机器连上 (真实的 :-)网际网路,你需要从区域网路管理者或提供者那里取得 你的 IP 位址。
IP addresses are usually written in "dotted quad"-notation - the four bytes are written down in decimal (most significant byte first), separated by dots. For example, 132.199.15.99 would be a valid address. Another way to write down IP-addresses would be as one 32-bit hex-word, e.g. 0x84c70f63. This is not as convenient as the dotted-quad, but quite useful at times, too. (See below!)
Being assigned a network means nothing else but setting some of the above-mentioned 32 address-bits to certain values. These bits that are used for identifying the network are called network-bits. The remaining bits can be used to address hosts on that network, therefore they are called host-bits.
In the above example, the network-address is 132.199.0.0 (host-bits are set to 0 in network-addresses), the host's address is 15.99 on that network.
How do you know that the host's address is 16 bit wide? Well, this is assigned by the provider from which you get your network-addresses. In the classless inter-domain routing (CIDR) used today, host fields are usually between as little as 2 to 16 bits wide, and the number of network-bits is written after the network address, seperated by a "/", e.g. 132.199.0.0/16 tells that the network in question has 16 network-bits. When talking about the "size" of a network, it's usual to only talk about it as "/16", "/24", etc.
Before CIDR was used, there used to be four classes of networks. Each one starts with a certain bit-pattern identifying it. Here are the four classes:
Class A starts with "0" as most significant bit. The next seven bits of a class A address identify the network, the remaining 24 bit can be used to address hosts. So, within one class A network there can be 224 hosts. It's not very likely that you (or your university, or company, or whatever) will get a whole class A address.
The CIDR notation for a class A network with it's eight network bits is an "/8".
Class B starts with "10" as most significant bits. The next 14 bits are used for the networks address, the remaining 16 bits can be used to address more than 65000 hosts. Class B addresses are very rarely given out today, they used to be common for companies and universities before IPv4 address space went scarce.
The CIDR notation for an class B network with it's 16 network bits is an "/16".
Returning to our above example, you can see that 132.199.15.99 (or 0x84c70f63, which is more appropriate here!) is on a class B network, as 0x84... = 1000... (base 2).
Therefore, the address 132.199.15.99 can be split into an network-address of 132.199.0.0 and an host-address of 15.99.
Class C is identified by the MSBs being "110", allowing only 256 (actually: only 254, see below) hosts on each of the 221 possible class C networks. Class C addresses are usually found at (small) companies.
The CIDR notation for an class C network with it's 24 network bits is an "/24".
There are also other addresses, starting with "111". Those are used for special purposes (e. g. multicast-addresses) and are not of interrest here.
Please note that the bits which are used for identifying the network-class are part of the network-address.
When seperating host-addresses from network-addresses, the "netmask" comes in handy. In this mask, all the network-bits are set to "1", the host-bits are "0". Thus, putting together IP-address and netmask with a locical AND-function, the network-address remains.
To continue our example, 255.255.0.0 is a possible netmask for 132.199.15.99. When applying this mask, the network-address 132.199.0.0 remains.
For addresses in CIDR notation, the number of network-bits given also says how many of the most significant bits of the address must be set to "1" to get the netmask for the corresponding network. For classfull addressing, every network-class has a fixed default netmask assigned:
Class A (/8): default-netmask: 255.0.0.0, first byte of address: 1-127
Class B (/16): default-netmask: 255.255.0.0, first byte of address: 128-191
Class C (/24): default-netmask: 255.255.255.0, first byte of address: 192-223
Another thing to mention here is the "broadcast-address". When sending to this address, all hosts on the corresponding network will receive the message sent. The broadcast address is characterized by having all host-bits set to "1".
Taking 132.199.15.99 with its netmask 255.255.0.0 again, the broadcast-address would result in 132.199.255.255.
You'll ask now: But what if I want a hosts address to be all bits "0" or "1"? Well, this doesn't work, as network- and broadcast-address must be present! Because of this, a class B (/16) network can contain at most 216-2 hosts, a class C (/24) network can hold no more than 28-2 = 254 hosts.
Besides all those categories of addresses, there's the special IP-address 127.0.0.1 which always refers to the "local" host, i. e. if you talk to 127.0.0.1 you'll talk to yourself without starting any network-activity. This is sometimes useful to use services installed on your own machine or to play around if you don't have other hosts to put on your network.
Let's put together the things we've introduced in this section:
IP-address: 32 bit-address, with network- and host-bits.
Network-address: IP-address with all host bits set to "0".
Netmask: 32-bit mask with "1" for network- and "0" for host-bits.
Broadcast: IP-address with all host bits set "1".
The local host's IP address is always 127.0.0.1.
After talking so much about netmasks, network-, host- and other addresses, I have to admit that this is not the whole truth.
Imagine the situation at your university, which usually has a class B (/16) address, allowing it to have up to 216 ~= 65534 hosts on that net. Maybe it would be a nice thing to have all those hosts on one single network, but it's simply not possible due to limitations in the transport media commonly used today.
For example, when using thinwire ethernet, the maximum length of the cable is 185 meters. Even with repeaters in between, which refresh the signals, this is not enough to cover all the locations where machines are located. Besides that, there is a maximum number of 1024 hosts on one ethernet wire, and you'll loose quite a bit of performance if you go to this limit.
So, are you hosed now? Having an address which allows more than 60000 hosts, but being bound to media which allows far less than that limit?
Well, of course not! :-)
The idea is to divide the "big" class B net into several smaller networks, commonly called sub-networks or simply subnets. Those subnets are only allowed to have, say, 254 hosts on them (i.e. you divide one big class B network into several class C networks!).
To do this, you adjust your netmask to have more network- and less host-bits on it. This is usually done on a byte-boundary, but you're not forced to do it there. So, commonly your netmask will not be 255.255.0.0 as supposed by a class B network, but it will be set to 255.255.255.0.
In CIDR notation, you now write a "/24" instead of the "/16" to show that 24 bits of the address are used for identifying the network and subnet, instead of the 16 that were used before.
This gives you one additional network-byte to assign to each (physical!) network. All the 254 hosts on that subnet can now talk directly to each other, and you can build 256 such class C nets. This should fit your needs.
To explain this better, let's continue our above example. Say our host 132.199.15.99 (I'll call him dusk from now; we'll talk about assigning hostnames later) has a netmask of 255.255.255.0 and thus is on the subnet 132.199.15.0/24. Let's furthermore introduce some more hosts so we have something to play around with, see Figure 9-1.
In the above network, dusk can talk directly to dawn, as they are both on the same subnet. (There are other hosts attached to the 132.199.15.0/24-subnet but they are not of importance for us now)
But what, if dusk wants to talk to a host on another subnet?
Well, the traffic will then go through one or more gateways (routers), which are attached to two subnets. Because of this, a router always has two different addresses, one for each of the subnets it is on. The router is functionally transparent, i. e. you don't have to address it to reach hosts on the "other" side. Instead, you address that host directly and the packets will be routed to it correctly.
Example. Let's say dusk wants to get some files from the local ftp-server. As dusk can't reach ftp directly (because it's on a different subnet), all its packets will be forwarded to it's "defaultrouter" rzi (132.199.15.1), which knows where to forward the packets to.
Dusk knows the address of it's defaultrouter in its network (rzi, 132.199.15.1), and it will forward any packets to it which are not on the same subnet, i.e. it will forward all IP-packets in which the third address-byte isn't 15.
The (default)router then gives the packets to the appropriate host, as it's also on the FTP-server's network.
In this example, all packets are forwarded to the 132.199.1.0/24-network, simply because it's the network's backbone, the most important part of the network, which carries all the traffic that passes between several subnets. Almost all other networks besides 132.199.15.0/24 are attached to the backbone in a similar manner.
But what, if we had hooked up another subnet to 132.199.15.0/24 instead of 132.199.1.0/24? Maybe something the situation displayed in Figure 9-2.
When we now want to reach a host which is located in the 132.199.16.0/24-subnet from dusk, it won't work routing it to rzi, but you'll have to send it directly to route2 (132.199.15.2). Dusk will have to know to forward those packets to route2 and send all the others to rzi.
When configuring dusk, you tell it to forward all packets for the 132.199.16.0/24-subnet to route2, and all others to rzi. Instead of specifying this default as 132.199.1.0/24, 132.199.2.0/24, etc., 0.0.0.0 can be used to set the default-route.
Returning to Figure 9-1, there's a similar problem when dawn wants to send to noon, which is connected to dusk via a serial line running. When looking at the IP-addresses, noon seems to be attached to the 132.199.15.0-network, but it isn't really. Instead, dusk is used as gateway, and dawn will have to send its packets to dusk, which will forward them to noon then. The way dusk is forced into accepting packets that aren't destined at it but for a different host (noon) instead is called "proxy arp".
The same goes when hosts from other subnets want to send to noon. They have to send their packets to dusk (possibly routed via rzi),
In the previous sections, when we talked about hosts, we referred to them by their IP-addresses. This was necessary to introduce the different kinds of addresses. When talking about hosts in general, it's more convenient to give them "names", as we did when talking about routing.
Most applications don't care whether you give them an IP address or an hostname. However, they'll use IP addresses internally, and there are several methods for them to map hostnames to IP addresses, each one with its own way of configuration. In this section we'll introduce the idea behind each method, in the next chapter, we'll talk about the configuration-part.
The mapping from hostnames (and domainnames) to IP-addresses is done by a piece of software called the "resolver". This is not an extra service, but some library routines which are linked to every application using networking-calls. The resolver will then try to resolve (hence the name ;-) the hostnames you give into IP addresses. See [RFC1034] and [RFC1035] for details on the resolver.
Hostnames are usually up to 10 characters long, and contain letters, numbers, dashes ("-") and underscores ("_"); case is ignorred.
Just as with networks and subnets, it's possible (and desirable) to group hosts into domains and subdomains. When getting your network-address, you usually also obtain a domainname by your provider. As with subnets, it's up to you to introduce subdomains. Other as with IP-addresses, (sub)domains are not directly related to (sub)nets; for example, one domain can contain hosts from several subnets.
Figure 9-1 shows this: Both subnets 132.199.1.0/24 and 132.199.15.0/24 (and others) are part of the subdomain "rz.uni-regensburg.de". The domain the University of Regensburg got from it's IP-provider is "uni-regensburg.de" (".de" is for Deutschland, Germany), the subdomain "rz" is for Rechenzentrum, computing center.
Hostnames, subdomain- and domainnames are separated by dots ("."). It's also possible to use more than one stage of subdomains, although this is not very common. An example would be fox_in.socs.uts.edu.au.
A hostname which includes the (sub)domain is also called a fully qualified domain name (FQDN). For example, the IP-address 132.199.15.99 belongs to the host with the FQDN dusk.rz.uni-regensburg.de.
Further above I told you that the IP-address 127.0.0.1 always belongs to the local host, regardless what's the "real" IP-address of the host. Therefore, 127.0.0.1 is always mapped to the name "localhost".
The three different ways to translate hostnames into IP addresses are: /etc/hosts, the Domain Name Service (DNS) and the Network Information Service (NIS).
The first and most simplest way to translate hostnames into IP-addresses is by using a table telling which IP address belongs to which hostname(s). This table is stored in the file /etc/hosts and has the following format:
IP-address hostname [nickname [...]]
Lines starting with a hash mark ("#") are treated as comments. The other lines contain one IP-address and the corresponding hostname(s).
It's not possible for a hostname to belong to several IP addresses, even if I made you think so when talking about routing. rzi for example has really two distinct names for each of its two addresses: rzi and rzia (but please don't ask me which name belongs to which address!).
Giving a host several nicknames can be convenient if you want to specify your favourite host providing a special service with that name, as is commonly done with FTP-servers. The first (leftmost) name is usually the real (canonical) name of the host.
Besides giving nicknames, it's also convenient to give a host's full name (including domain) as its canonical name, and using only its hostname (without domain) as a nickname.
Important: There must be an entry mapping localhost to 127.0.0.1!
/etc/hosts bears an inherent problem, especially in big networks: when one host is added or one hosts's address changes, all the /etc/hosts' on all machines have to be changed! This is not only time-consuming, it's also very likely that there will be some errors and inconsistencies, leading to problems.
Another appoach is to hold only one hostnames-table (-database) for a network, and make all the clients query that "nameserver". Updates will be made only on the nameserver.
This is the basic idea behind the Domain Name Service (DNS).
Usually, there's one nameserver for each domain (hence DNS), and every host (client) in that domain knows which domain it is in and which nameserver to query for its domain.
When the DNS gets a query about an host which is not in its domain, it will forward the query to a DNS which is either the DNS of the domain in question or knows which DNS to ask for the specified domain. If the DNS forwarded the query doesn't know how to handle it, it will forward that query again to a DNS one step higher. This is not ad infinitum, there are several "root"-servers, which know about any domain.
See Chapter 10 for details on DNS.
Yellow Pages (YP) was invited by Sun Microsystems. The name has been changed into Network Information Service (NIS) because YP was already a trademark of the british telecom. So, when I'll talk about NIS you'll know what I mean. ;-)
There are quite some configuration files on a unix-system, and often it's desired to maintain only one set of those files for a couple of hosts. Those hosts are grouped together in a NIS-domain (which has nothing to do with the domains built by using DNS!) und are usually contained in one workstation cluster.
Examples for the config-files shared among those hosts are /etc/passwd, /etc/group and - last but not least - /etc/hosts.
So, you can "abuse" NIS for getting a unique name-to-address-translation on all hosts throughout one (NIS-)domain.
There's only one drawback, which prevents NIS from actually being used for that translation: In contrast to the DNS, NIS provides no way to resolve hostnames which are not in the hosts-table. There's no hosts "one level up" which the NIS-server can query, and so the translation will fail! Suns NIS+ takes measures against that problem, but as NIS+ is only available on Solaris-systems, this is of little use for us now.
Don't get me wrong: NIS is a fine thing for managing e.g. user-information (/etc/passwd, ...) in workstation-clusters, it's simply not too useful for resolving hostnames.
The name resolving methods described above are what's used commonly today to resolve hostsnames into IP addresses, but they aren't the only ones. Basically, every database mechanism would do, but none is implemented in NetBSD. Let's have a quick look what you may encounter.
With NIS lacking hierarchy in data structures, NIS+ is intended to help out in that field. Tables can be setup in a way so that if a query cannot be answered by a domain's server, there can be another domain "above" that might be able to do so. E.g. you could choose to have a domain that lists all the hosts (users, groups, ...) that are valid in the whole company, one that defines the same for each division, etc. NIS+ is not used a lot today, even Sun went back to ship back NIS by default.
Last century, the X.500 standard was designed to accomodate both simple databases like /etc/hosts as well as comples, hierarchical systems as can be found e.g. in DNS today. X.500 wasn't really a success, mostly due to the fact that it tried to do too much at the same time. A cut-down version is available today as the Lightweight Directory Access Protocol (LDAP), which is becoming popular in the last years to manage data like users but also hosts and others in small to medium sized organisations.
According to experts, the Internet as we know it will face a serious problem in a few years. Due to it's rapid growth and the limitations in it's design, there will be a point at which no more free addresses are available for connecting new hosts. At that point, no more new web servers can be set up, no more users can sign up for accounts at ISPs, no more new machines can be setup to access the web or participate in online games - some people may call this a serious problem.
Several approaches have been made to solve the problem. A very popular one is to not assign a worldwide unique address to every users' machine, but rather to assign them "private" addresses, and hide several machines behind one official, globally unique address. This approach is called 'Network Address Translation' (NAT, also known as IP Masquerading). It has problems, as the machines hidden behind the global address can't be addressed, and as a result of this, opening connections to them - which is used in online gaming, peer to peer networking, etc. - is not possible. For a more in-depth discussion of the drawbacks of NAT, see [RFC3027].
A different approach to the problem of internet addresses getting scarce is to abandon the old Internet protocol with it's limited addressing capabilities, and use a new protocol that does not have these limitations. The protocol - or actually, a set of protocols - used by machines connected to form today's Internet is know as the TCP/IP (Transmission Control Protocol, Internet Protocol) suite, and version 4 currently in use has all the problems described above. Switching to a different protocol version that does not have these problems of course requires for a 'better' version to be available, which actually is. Version 6 of the Internet Protocol (IPv6) does fulfill any possible future demands on address space, and also addresses further features such as privacy, encryption, and better support of mobile computing.
Assuming a basic understanding of how today's IPv4 works, this text is intended as an introduction to the IPv6 protocol. The changes in address formats and name resolution are covered. With the background given here, Section 9.3.4 will show how to use IPv6 even if your ISP doesn't offer it by using a simple yet efficient transition mechanism called 6to4. The goal is to to get online with IPv6, giving example configuration for NetBSD.
When telling people to migrate from IPv4 to IPv6, the question you usually hear is "why?". There are actually a few good reasons to move to the new version:
Bigger address space
Support for mobile devices
Built-in security
The bigger address space that IPv6 offers is the most obvious enhancement it has over IPv4. While today's internet architecture is based on 32-bit wide addresses, the new version has 128 bit available for addressing. Thanks to the enlarged address space, work-arounds like NAT don't have to be used any more. This allows full, unconstrained IP connectivity for today's IP based machines as well as upcoming mobile devices like PDAs and cell phones will benefit from full IP access through GPRS and UMTS.
When mentioning mobile devices and IP, another important point to note is that some special protocol is needed to support mobility, and implementing this protocol - called "Mobile IP" - is one of the requirements for every IPv6 stack. Thus, if you have IPv6 going, you have support for roaming between different networks, with everyone being updated when you leave one network and enter the other one. Support for roaming is possible with IPv4 too, but there are a number of hoops that need to be jumped in order to get things working. With IPv6, there's no need for this, as support for mobility was one of the design requirements for IPv6. See [RFC3024] for some more information on the issues that need to be addressed with Mobile IP on IPv4.
Besides support for mobility, security was another requirement for the successor to today's Internet Protocol version. As a result, IPv6 protocol stacks are required to include IPsec. IPsec allows authentication, encryption and compression of any IP traffic. Unlike application level protocols like SSL or SSH, all IP traffic between two nodes can be handled, without adjusting any applications. The benefit of this is that all applications on a machine can benefit from encryption and authentication, and that policies can be set on a per-host (or even per-network) base, not per application/service. An introduction to IPsec with a roadmap to the documentation can be found in [RFC2411], the core protocol is described in [RFC2401].
After giving a brief overview of all the important features of IPv6, we'll go into the details of the basics of IPv6 here. A brief understanding of how IPv4 works is assumed, and the changes in IPv6 will be hilighted. Starting with IPv6 addresses and how they're split up we'll go into the various types of addresses there are, what became of broadcasts, then after discussing the IP layer go into changes for name resolving and what's new in DNS for IPv6.
An IPv4 address is a 32 bit value, that's usually written in "dotted quad" representation, where each "quad" represents a byte value between 0 and 255, for example:
127.0.0.1
This allows a theoretical number of 232 or ~4 billion hosts to be connected on the internet today. Due to grouping, not all addresses are available today.
IPv6 addresses use 128 bit, which results in 2128 theoretically addressable hosts. This allows for a Really Big number of machines to addressed, and it sure fits all of today's requirements plus all those nifty PDAs and cell phones with IP phones in the near future without any sweat. When writing IPv6 addresses, they are usually divided into groups of 16 bits written as four hex digits, and the groups are separated by colons. An example is:
fe80::2a0:d2ff:fea5:e9f5
This shows a special thing - a number of consecutive zeros can be abbreviated by a single "::" once in the IPv6 address. The above address is thus equivalent to fe80:0:00:000:2a0:d2ff:fea5:e9f5 - leading zeros within groups can be omitted.
To make addresses manageable, they are split in two parts, which are the bits identifying the network a machine is on, and the bits that identify a machine on a (sub)network. The bits are known as netbits and hostbits, and in both IPv4 and IPv6, the netbits are the "left", most significant bits of an IP address, and the host bits are the "right", least significant bits, as shown in Figure 9-3.
In IPv4, the border is drawn with the aid of the netmask, which can be used to mask all net/host bits. Typical examples are 255.255.0.0 that uses 16 bit for addressing the network, and 16 bit for the machine, or 255.255.255.0 which takes another 8 bit to allow addressing 256 subnets on e.g. a class B net.
When addressing switched from classful addressing to CIDR routing, the borders between net and host bits stopped being on 8 bit boundaries, and as a result the netmasks started looking ugly and not really manageable. As a replacement, the number of network bits is used for a given address, to denote the border, e.g.
10.0.0.0/24
is the same as a netmask of 255.255.255.0 (24 1-bits). The same scheme is used in IPv6:
2001:638:a01:2::/64
tells us that the address used here has the first (leftmost) 64 bits used as the network address, and the last (rightmost) 64 bits are used to identify the machine on the network. The network bits are commonly referred to as (network) "prefix", and the "prefixlen" here would be 64 bits.
Common addressing schemes found in IPv4 are the (old) class B and class C nets. With a class C network (/24), you get 24 bits assigned by your provider, and it leaves 8 bits to be assigned by you. If you want to add any subnetting to that, you end up with "uneven" netmasks that are a bit nifty to deal with. Easier for such cases are class B networks (/16), which only have 16 bits assigned by the provider, and that allow subnetting, i.e. splitting of the rightmost bits into two parts. One to address the on-site subnet, and one to address the hosts on that subnet. Usually, this is done on byte (8 bit) boundaries. Using a netmask of 255.255.255.0 (or a /24 prefix) allows flexible management even of bigger networks here. Of course there is the upper limit of 254 machines per subnet, and 256 subnets.
With 128 bits available for addressing in IPv6, the scheme commonly used is the same, only the fields are wider. Providers usually assign /48 networks, which leaves 16 bits for a subnetting and 64 hostbits.
Now while the space for network and subnets here is pretty much ok, using 64 bits for addressing hosts seems like a waste. It's unlikely that you will want to have several billion hosts on a single subnet, so what is the idea behind this?
The idea behind fixed width 64 bit wide host identifiers is that they aren't assigned manually as it's usually done for IPv4 nowadays. Instead, IPv6 host addresses are recommended (not mandatory!) to be built from so-called EUI64 addresses. EUI64 addresses are - as the name says - 64 bit wide, and derived from MAC addresses of the underlying network interface. E.g. for ethernet, the 6 byte (48 bit) MAC address is usually filled with the hex bits "fffe" in the middle and a bit is set to mark the address as unique (which is true for Ethernet), e.g. the MAC address
01:23:45:67:89:ab
results in the EUI64 address
03:23:45:ff:fe:67:89:ab
which again gives the host bits for the IPv6 address as
::0323:45ff:fe67:89ab
These host bits can now be used to automatically assign IPv6 addresses to hosts, which supports autoconfiguration of IPv6 hosts - all that's needed to get a complete IPv6 address is the first (net/subnet) bits, and IPv6 also offers a solution to assign them automatically.
When on a network of machines speaking IP, there's usually one router which acts as the gateway to outside networks. In IPv6 land, this router will send "router advertisement" information, which clients are expected to either receive during operation or to solicit upon system startup. The router advertisement information includes data on the router's address, and which address prefix it routes. With this information and the host-generated EUI64 address, a IPv6-host can calculate it's IP address, and there is no need for manual address assignment. Of course routers still need some configuration.
The router advertisement information they create are part of the Neighbor Discovery Protocol (NDP, see [RFC2461]), which is the successor to IPv4's ARP protocol. In contrast to ARP, NDP does not only do lookup of IPv6 addresses for MAC addresses (the neighbor solicitation/advertisement part), but also does a similar service for routers and the prefixes they serve, which is used for autoconfiguration of IPv6 hosts as described in the previous paragraph.
In IPv4, a host usually has one IP address per network interface or even per machine if the IP stack supports it. Only very rare applications like web servers result in machines having more than one IP address. In IPv6, this is different. For each interface, there is not only a globally unique IP address, but there are two other addresses that are of interest: The link local address, and the site local address. The link local address has a prefix of fe80::/64, and the host bits are built from the interface's EUI64 address. The link local address is used for contacting hosts and routers on the same network only, the addresses are not visible or reachable from different subnets. If wanted, there's the choice of either using global addresses (as assigned by a provider), or using site local addresses. Site local addresses are assigned the network address fec0::/10, and subnets and hosts can be addressed just as for provider-assigned networks. The only difference is, that the addresses will not be visible to outside machines, as these are on a different network, and their "site local" addresses are in a different physical net (if assigned at all). As with the 10/8 network in IPv4, site local addresses can be used, but don't have to. For IPv6 it's most common to have hosts assigned a link-local and a global IP address. Site local addresses are rather uncommon today, and are no substitute for globally unique adresses if global connectivity is required.
In IP land, there are three ways to talk to a host: unicast, broadcast and multicast. The most common one is by talking to it directly, using it's unicast address. In IPv4, the unicast address is the "normal" IP address assigned to a single host, with all address bits assigned. The broadcast address used to address all hosts in the same IP subnet has the network bits set to the network address, and all host bits set to "1" (which can be easily done using the netmask and some bit operations). Multicast addresses are used to reach a number of hosts in the same multicast group, which can be machines spread over the whole internet. Machines must join multicast groups explicitly to participate, and there are special IPv4 addresses used for multicast addresses, allocated from the 224/8 subnet. Multicast isn't used very much in IPv4, and only few applications like the MBone audio and video broadcast utilities use it.
In IPv6, unicast addresses are used the same as in IPv4, no surprise there - all the network and host bits are assigned to identify the target network and machine. Broadcasts are no longer available in IPv6 in the way they were in IPv4, this is where multicasting comes into play. Addresses in the ff::/8 network are reserved for multicast applications, and there are two special multicast addresses that supersede the broadcast addresses from IPv4. One is the "all routers" multicast address, the others is for "all hosts". The addresses are specific to the subnet, i.e. a router connected to two different subnets can address all hosts/routers on any of the subnets it's connected to. Addresses here are:
ff0X::1 for all hosts and
ff0X::2 for all routers,
where "X" is the scope ID of the link here, identifying the network. Usually this starts from "1" for the "node local" scope, "2" for the first link, etc. Note that it's perfectly ok for two network interfaces to be attached to one link, thus resulting in double bandwidth:
One use of the "all hosts" multicast is in the neighbor solicitation code of NDP, where any machine that wants to communicate with another machine sends out a request to the "all hosts" group, and the machine in question is expected to respond.
After talking a lot about addressing in IPv6, anyone still here will hope that there's a proper way to abstract all these long & ugly IPv6 addresses with some nice hostnames as one can do in IPv4, and of course there is.
Hostname to IP address resolving in IPv4 is usually done in one of three ways: using a simple table in /etc/hosts, by using the Network Information Service (NIS, formerly YP) or via the Domain Name System (DNS).
As of this writing, NIS/NIS+ over IPv6 is currently only available on Solaris 8, for both database contents and transport, using a RPCextension.
Having a simple address<->name map like /etc/hosts is supported in all IPv6 stacks. With the KAME implementation used in NetBSD, /etc/hosts contains IPv6 addresses as well as IPv4 addresses. A simple example is the "localhost" entry in the default NetBSD installation:
127.0.0.1 localhost ::1 localhost
For DNS, there are no fundamentally new concepts. IPv6 name resolving is done with AAAA records that - as the name implies - point to an entity that's four times the size of an A record. The AAAA record takes a hostname on the left side, just as A does, and on the right side there's an IPv6 address, e.g.
noon IN AAAA 3ffe:400:430:2:240:95ff:fe40:4385
For reverse resolving, IPv4 uses the in-addr.arpa zone, and below that it writes the bytes (in decimal) in reversed order, i.e. more significant bytes are more right. For IPv6 this is similar, only that hex digits representing 4 bits are used instead of decimal numbers, and the resource records are also under a different domain, ip6.int.
So to have the reverse resolving for the above host, you would put into your /etc/named.conf something like:
zone "0.3.4.0.0.0.4.0.e.f.f.3.IP6.INT" {
type master;
file "db.reverse";
}; and in the zone file db.reverse you put (besides the usual records like SOA and NS):
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.
The address is reversed here, and written down one hex digit after the other, starting with the least significant (rightmost) one, separating the hex digits with dots, as usual in zone files.
One thing to note when setting up DNS for IPv6 is to take care of the DNS software version in use. BIND 8.x does understand AAAA records, but it does not offer name resolving via IPv6. You need BIND 9.x for that. Beyond that, BIND 9.x supports a number of resource records that are currently being discussed but not officially introduced yet. The most noticeable one here is the A6 record which allows easier provider/prefix changing.
To sum up, this section talked about the technical differences between IPv4 and IPv6 for addressing and name resolving. Some details like IP header options, QoS and flows were deliberately left out to not make the this document more complex than necessary.
Before we dive into configuring various aspects of network setup, we want to walk through the necessary bits that have to or can be present in the kernel. See Chapter 7 for more details on compiling the kernel, we will concentrate on the configuration of the kernel here. We will take the i386/GENERIC config file as an example here. Config files for other platforms should contain similar information, the comments in the config files give additional hints. Besides the information given here, each kernel option is also documented in the options(4) manpage, and there is usually a manpage for each driver too, e.g. tlp(4).
# $NetBSD: chap-net.sgml,v 1.2 2002/02/06 14:19:28 jrf Exp $
The first line of each config file shows the version, which is 1.354.2.15 here. It can be used to compare against other versions via CVS, or when reporting bugs.
options NTP # NTP phase/frequency locked loop
If you want to run the Network Time Protocol (NTP), this option can be enabled for maximum precision. If the option is not present, NTP will still work. See ntpd(8) for more information.
file-system NFS # Network File System client
If you want to use another machine's harddisk via the Network File System (NFS), this option is needed. Section 9.3.2 gives more information on NFS.
options NFSSERVER # Network File System server
This option includes the server side of the NFS remote file sharing protocol. Enable if you want to allow other machines to use your harddisk. Section 9.3.2 contains more information on NFS.
#options GATEWAY # packet forwarding
If you want to setup a router that forwards packets between networks or network interfaces, setting this option is needed. If doesn't only switch on packet forwarding, but also increases some buffers. See options(4) for details.
options INET # IP + ICMP + TCP + UDP
This enables the TCP/IP code in the kernel. Even if you don't want/use networking, you will still need this for machine-internal communication of subsystems like the X Window System. See inet(4) for more details.
options INET6 # IPV6
If you want to use IPv6, this is your option. If you don't want IPv6, which is part of NetBSD since the 1.5 release, you can remove/comment out that option. See the inet6(4) manpage and Section 9.1.7 for more information on the next generation Internet protocol.
#options IPSEC # IP security
Includes support for the IPsec protocol, including key and policy management, authentication and compression. This option can be used without the previous option INET6, if you just want to use IPsec with IPv4, which is possible. See ipsec(4) for more information.
#options IPSEC_ESP # IP security (encryption part; define w/IPSEC)
This option is needed in addition to IPSEC if encryption is wanted in IPsec.
#options MROUTING # IP multicast routing
If multicast services like the MBone services should be routed, this option needs to be included. Note that the routing itself is controlled by the mrouted(8) daemon.
options NS # XNS
#options NSIP # XNS tunneling over IP
These options enables the Xerox Network Systems(tm) protocol family. It's not related to the TCP/IP protocol stack, and in rare use today. The ns(4) manpage has some details.
options ISO,TPIP # OSI
#options EON # OSI tunneling over IP
These options include the OSI protocol stack, that was said for a long time to be the future of networking. It's mostly history these days. :-) See the iso(4) manpage for more information.
options CCITT,LLC,HDLC # X.25
These options enable the X.25 protocol set for transmission of data over serial lines. It is/was used mostly in conjunction with the OSI protocols and in WAN networking.
options NETATALK # AppleTalk networking protocols
Include support for the AppleTalk protocol stack. Userland server programs are needed to make use of that. See pkgsrc/net/netatalk and pkgsrc/net/netatalk-asun for such packages. More information on the AppleTalk protocol and protocol stackk are available in the atalk(4) manpage.
options PPP_BSDCOMP # BSD-Compress compression support for PPP
options PPP_DEFLATE # Deflate compression support for PPP
options PPP_FILTER # Active filter support for PPP (requires bpf)
These options tune various aspects of the Point-to-Point protocol. The first two determine the compression algorithms used and available, while the third one enables code to filter some packets.
options PFIL_HOOKS # pfil(9) packet filter hooks
options IPFILTER_LOG # ipmon(8) log support
These options enable firewalling in NetBSD, using IPfilter. See the ipf(4) and ipf(8) manpages for more information on operation of IPfilter, and Section 9.3.1.1 for a configuration example.
# Compatibility with 4.2BSD implementation of TCP/IP. Not recommended.
#options TCP_COMPAT_42
This option is only needed if you have machines on the network that still run 4.2BSD or a network stack derived from it. If you've got one or more 4.2BSD-systems on your network, you've to pay attention to set the right broadcast-address, as 4.2BSD has a bug in its networking code, concerning the broadcast address. This bug forces you to set all host-bits in the broadcast-address to "0". The TCP_COMPAT_42 option helps you ensuring this.
options NFS_BOOT_DHCP,NFS_BOOT_BOOTPARAM
These options enable lookup of data via DHCP or the BOOTPARAM protocol if the kernel is told to use a NFS root file system. See the diskless(8) manpage for more information.
# Kernel root file system and dump configuration.
config netbsd root on ? type ?
#config netbsd root on sd0a type ffs
#config netbsd root on ? type nfs
These lines tell where the kernel looks for it's root file system, and which filesystem type it is expected to have. If you want to make a kernel that uses a NFS root filesystem via the tlp0 interface, you can do this with "root on tlp0 type nfs". If a ? is used instead of a device/type, the kernel tries to figure one out on it's own.
# ISA serial interfaces
com0 at isa? port 0x3f8 irq 4 # Standard PC serial ports
com1 at isa? port 0x2f8 irq 3
com2 at isa? port 0x3e8 irq 5
If you want to use PPP or SLIP, you will need some serial (com) interfaces. Others with attachment on USB, PCMCIA or PUC will do as well.
# Network Interfaces
This rather long list contains all sort of network drivers. Please pick the one that matches your hardware, according to the comments. For most drivers, there's also a manual page available, e.g. tlp(4), ne(4), etc.
# MII/PHY support
This section lists media independent interfaces for network cards. Pick one that matches your hardware. If in doubt, enable them all and see what the kernel picks. See the mii(4) manpage for more information.
# USB Ethernet adapters
aue* at uhub? port ? # ADMtek AN986 Pegasus based adapters
cue* at uhub? port ? # CATC USB-EL1201A based adapters
kue* at uhub? port ? # Kawasaki LSI KL5KUSB101B based adapters
USB-ethernet adapters only have about 2MBit/s bandwidth, but they are very convenient to use. Of course this needs other USB related options which we won't cover here, as well as the necessary hardware. See the corresponding manpages for more information.
# network pseudo-devices
pseudo-device bpfilter 8 # Berkeley packet filter
This pseudo-device allows sniffing packets of all sorts. It's needed for tcpdump, but also rarpd and some other applications that need to know about network traffic. See bpf(4) for more information.
pseudo-device ipfilter # IP filter (firewall) and NAT
This one enables the IPfilter's packet filtering kernel interface used for firewalling, NAT (IP Masquerading) etc. See ipf(4) and Section 9.3.1.1 for more information.
pseudo-device loop # network loopback
This is the "lo0" software loopback network device which is used by some programs these days, as well as for routing things. Should not be omited. See lo(4) for more details.
pseudo-device ppp 2 # Point-to-Point Protocol
If you want to use PPP either over a serial interface or ethernet (PPPoE), you will need this option. See ppp(4) for details on this interface.
pseudo-device sl 2 # Serial Line IP
Serial Line IP is a simple encapsulation for IP over (well :) serial lines. It does not include negotiation of IP addresses and other options, which is the reason that it's not in widespread use today any more. See sl(4).
pseudo-device strip 2 # Starmode Radio IP (Metricom)
If you happen to have one of the old Metricon Ricochet packet radio wireless network devices, use this pseudo-device to use it. See the strip(4) manpage for detailled information.
pseudo-device tun 2 # network tunneling over tty
This network device can be used to tunnel network packets to a device file, /dev/tun*. Packets routed to the tun0 interface can be read from /dev/tun0, and data written to /dev/tun0 will be sent out the tun0 network interface. This can be used to implement e.g. QoS routing in userland. See tun(4) for details.
pseudo-device gre 2 # generic L3 over IP tunnel
The GRE encapsulation can be used to tunnel arbitrary layer 3 packets over IP, e.g. to implement VPNs. See gre(4) for more.
pseudo-device ipip 2 # IP Encapsulation within IP (RFC 2003)
Another IP-in-IP encapsulation device, with a different encapsulation format. See the ipip(4) manpage for details.
pseudo-device gif 4 # IPv[46] over IPv[46] tunnel (RFC 1933)
Using the GIF interface allows to tunnel e.g. IPv6 over IPv4, which can be used to get IPv6 connectivity if no IPv6-capable uplink (ISP) is available. Other mixes of operations are possible, too. See the gif(4) manpage for some examples.
#pseudo-device faith 1 # IPv[46] tcp relay translation i/f
The faith interface captures IPv6 TCP traffic, for implementing userland IPv6-to-IPv4 TCP relays e.g. for protocol transitions. See the faith(4) manpage for more details on this device.
#pseudo-device stf 1 # 6to4 IPv6 over IPv4 encapsulation
This add a network device that can be used to tunnel IPv6 over IPv4 without setting up a configured tunnel before. The source address of outgoing packets contains the IPv4 address, which allows routing replies back via IPv4. See the stf(4) manpage and Section 9.3.4 for more details.
pseudo-device vlan # IEEE 802.1q encapsulation
This interface provides support for IEEE 802.1Q Virtual LANs, which allows tagging Ethernet frames with a "vlan" ID. Using properly configured switchens (that also have to support VLAN, of course), this can be used to build virtual LANs where one set of machines doesn't see traffic from the other (broadcast and other). The vlan(4) manpage tells more about this.
The following is a list of the files used to configure the network. The usage of these files, some of which have already been met the first chapters, will be described in the following sections.
Local hosts database file. Each line contains information regarding a known host and contains the internet address, the host's name and the aliases. Small networks can be configured using only the hosts file, without a name server.
This file specifies how the routines which provide access to the Internet Domain Name System should operate. Generally it contains the addresses of the name servers.
This file is used for the automatic configuration of the network card at boot.
Contains the IP address of the gateway.
Name service switch configuration file. It controls how a process looks up various databases containing information regarding hosts, users, groups, etc. Specifically, this file defines the order to look up the databases. For example, the line:
hosts: files dnsspecifies that the hosts database comes from two sources, files (the local /etc/hosts file) and DNS, (the Internet Domain Name System) and that the local files are searched before the DNS.
It is usually not necessary to modify this file.
Internet 连线有许多类型:这一段解释如何使用 modem 经由电话线 并利用 PPP 协定连接到 ISP,提供一个一般 的设定。为了要进行网路连线,必须执行以下步骤:
从 ISP 获得必要的资讯。
编辑 /etc/resolv.conf 并检查 /etc/nsswitch.conf。
建立 /etc/ppp 和 /etc/ppp/peers 目录。
建立连线的 script,chat 档和 pppd 的选项档。
建立使用者密码认证档。
从以上的列表来看,好像需要很多复杂的程序要做。实际上,这些 步骤是非常容易的:这只是修改,建立或简单地检查一些小的 文字档而已。以下的范例中,我们将假设 modem 连接到第二个 序列埠上 /dev/tty01 (COM2 in DOS.)。
/etc/resolv.conf 必须使用 ISP 所提供 的资讯来设定,特别是 DNS 位址。 此例中,两个 DNS 为 "194.109.123.2" 和 "191.200.4.52"。
Note: 最后一行 ("lookup file bind") 指出在名称不 出现在 /etc/hosts 时,才使用 位址伺服器。这一行被标注了,因为 NetBSD 1.4 以后 已经不再需要了;这类的资讯现在被定义在 /etc/nsswitch.conf。新的 Name Service Switch 改以存取程式所使用的资料库来寻找 基本的系统资讯。
现在有个 /etc/nsswitch.conf 档 的范例。
Example 9-2. nsswitch.conf
# /etc/nsswitch.conf group: compat group_compat: nis hosts: files dns netgroup: files [notfound=return] nis networks: files passwd: compat passwd_compat: nis
Note: 只有以 "hosts:" 为开头一行被修改;当要解析 主机名称时,本机上的 hosts 将会 在使用 DNS 之前被搜寻。
/etc/ppp 和 /etc/ppp/peers 目录将会包含有关 PPP 连线的设定档。在首次安装 NetBSD 后,它们并不存在 而必须被建立 (chmod 700.)
连线 script 将用来执行 pppd 指令; 它位于 /etc/ppp/peers 而通常具有 ISP 的 名称。例如,如果 ISP 的名称是 BigNet 而你连线到 ISP 的使用者名称是 alan,连线 script 的范例如下:
Example 9-3. 连线 script
# /etc/ppp/peers/bignet connect '/usr/sbin/chat -v -f /etc/ppp/peers/bignet.chat' noauth user alan remotename bignet.it
在先前的例子中,script 指明了 chat 档 来进行连线。相关的选项在 pppd(8) 线上手册中,有详细地描述。
Note: 如果你发生过连线的问题,加入以下两行到连线 script 中。
debug kdebug 4你将在系统进行连线时,获得执行运作时的讯息。 详细说明请看 pppd(8), syslog.conf(5)。
连线 script 呼叫 chat 应用程式来 处理实际上的连线 (modem 初始化,拨号, ...)。 chat 的参数也可以设定在连线 script 中,但最好放在另外的档案里。例如,拨接号码是 0299999999,chat script 的范例是:
Example 9-4. Chat 档
# /etc/ppp/peers/bignet.chat ABORT BUSY ABORT "NO CARRIER" ABORT "NO DIALTONE" '' ATDT0299999999 CONNECT ''
Note: 如果 chat 档有问题,你可以试著使用 cu 来进行手动拨接并检查你接收的的讯息。 请看 cu(1)。
经由两个系统的认证,可以用来识别相互的系统,在此练习中, 只假设被 ISP 认证,而没有认证 ISP,我们使用以下方法。
login
PAP/CHAP
大部分的 ISP 使用 PAP/CHAP 认证。
认证资料被储存在 /etc/ppp/pap-secrets for PAP 和 /etc/ppp/chap-secrets for CHAP。 并具有以下格式:
user * password
例如:
alan * pZY9o
Note: 为了安全性的考量, pap-secrets 和 chap-secrets 档的拥有者为 root 并且权限为 "600"。
这个认证的类型在今日并没有被广泛的使用;如果 ISP 使用 login 认证,user name 和 password 必须写在 chat 档而不是 PAP/CHAP 档,因为 chat 档模拟了一个交谈式的认证。在这个 情况里,必须为 chat 档设定适当的权限。
以下为 chat 档使用 login 认证的范例:
剩下唯一要做的事就是建立 pppd 的 选项档,即为 /etc/ppp/options (chmod 644)。
要了解这些选项的意义,请看 pppd(8) 线上手册。
在执行连线以前,做个快速的数据机测试是个好主意,来确认 数据机硬体上的连线和沟通的功能。可以使用 cu 进行测试,如以下的例子。
建立 /etc/uucp/port 并包含 以下这几行:
type modem port modem device /dev/tty01 speed 115200(将 /dev/tty01 换成正确的装置。)
键入 cu -p modem,开始传送命令给 数据机。例如:
# cu -p modem Connected. ATZ OK ~. Disconnected. #在先前的范例中,重置命令 (ATZ) 被送到数据机,而回应是 OK: 沟通正常。要离开 cu,在 . (dot) 后键入 ~ (tilde),像前例一样。
如果数据机不能运作,检查所连接的连接埠(例如,在 cu 中所使用的连接埠)。 缆线也常常会导致问题。
Note: 当你使用 cu 时,如果有讯息显示 "Permission denied",检查 /dev/tty## 装置的拥有者是谁: 他必须为 uucp。例如:
$ ls -l /dev/tty00 crw------- 1 uucp wheel 8, 0 Mar 22 20:39 /dev/tty00如果拥有者是 root,则会发生:
$ ls -l /dev/tty00 crw------- 1 root wheel 8, 0 Mar 22 20:39 /dev/tty00 $ cu -p modem cu: open (/dev/tty00): Permission denied cu: All matching ports in use
一切都准备就绪,使用以下指令执行:
# pppd call bignet
bignet 是以经设定在 连线 script 中的名称。要查看 pppd 的 连线讯息,使用以下指令:
# tail -f /var/log/messages
要中断连线,针对 pppd 执行 kill -HUP。
当连线正确地运作时,则我们可以撰写一些 script 来避免在 每一次进行连线时,都重复同样的指令。我们可以命名两个 script,例如,ppp-up 和 ppp-down。
ppp-up 用来连线到 ISP:
Example 9-7. ppp-up
#!/bin/sh
MODEM=tty01
POP=bignet
if [ -f /var/spool/lock/LCK..$MODEM ]; then
echo ppp is already running...
else
pppd call $POP
tail -f /var/log/messages
fi
ppp-down 用来中断连线:
Example 9-8. ppp-down
#!/bin/sh
MODEM=tty01
if [ -f /var/spool/lock/LCK..$MODEM ]; then
echo -f killing pppd...
kill -HUP `cat /var/spool/lock/LCK..$MODEM`
echo done
else
echo ppp is not active
fi
在执行 pppd 时,这两个 script 都 具有一些方便之处,它会在 /var/spool/lock 目录建立 LCK..tty01 档案。 这个档案包含了 pppd 的 pid。
两个 script 必须是可执行的:
# chmod u+x ppp-up ppp-down
网路功能是 Unix 和 NetBSD 的主要优势之一:网路具有强大的 功能又容易设定,而且也不贵,因为不需要购买额外的软体来进行通讯 的运作或是建立伺服器。Section 9.3.1 解释了如何设定 一台 NetBSD 机器来扮演网路中闸道器的角色:所有的连线使用 IPNAT 连接到闸道器。在建立网路之前,唯一要做的事 就是购买 NetBSD 支援的网路卡 (参考 INSTALL 可以 得到支援硬体的清单)。
首先,网路卡必须安装并连接到集线器,交换器或是另一张网路卡。 (请看 Figure 9-6)
下一步,检查网路卡是否被核心支援,可查看 dmesg 指令的输出。在以下的例子中,被核心支援的网路卡是 NE2000 相容卡:
...
ne0 at isa0 port 0x280-0x29f irq 9
ne0: NE2000 Ethernet
ne0: Ethernet address 00:c2:dd:c1:d1:21
...
如果卡没有被核心承认,检查它是否在核心设定档内并且卡的 IRQ 是否和核心期望的值相符合。例如,在核心设定档中,有一行 isa NE2000 的设定;核心预设卡的 IRQ 为 9。
...
ne0 at isa? port 0x280 irq 9 # NE[12]000 ethernet cards
...
如果卡的设定并不相同,它在开机时,将不能被侦测到。在此例中, 你以更改核心设定档并重新编译一个核心,或是改变卡的设定(通常 可经由设定磁片来设定,如果是老旧的卡,则使用 jumper)。
以下的指令显示网路卡目前的设定:
# ifconfig ne0
ne0: flags=8822<BROADCAST,NOTRAILERS,SIMPLEX,MULTICAST> mtu 1500 media: Ethernet 10base2
网路卡的软体设定是非常容易的。IP 位址 "192.168.1.1" (为内部的网路所保留的)被指派到这张卡上。
# ifconfig ne0 inet 192.168.1.1 netmask 0xffffff00
重复前项指令并得到不同的结果:
# ifconfig ne0
ne0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
media: Ethernet 10base2
inet 192.168.1.1 netmask 0xffffff00 broadcast 192.168.1.255
ifconfig 的输出现在被改变了:IP 位址被 印出来了而且有两个新的 flags,"UP" 和 "RUNNING"。如果介面不是 "UP",它将不能被 系统用来传送封包。
主机被指派了 IP 位址 192.168.1.1,这是被内部网路所保留的而不能 经由 Internet 到达的位址。设定已经完成了而必须被测试;如果有 另一台主机在网路上,可利用 ping 来测试。 例如,如果主机的位址是 192.168.1.2 :
# ping 192.168.1.2
PING ape (192.168.1.2): 56 data bytes
64 bytes from 192.168.1.2: icmp_seq=0 ttl=255 time=1.286 ms
64 bytes from 192.168.1.2: icmp_seq=1 ttl=255 time=0.649 ms
64 bytes from 192.168.1.2: icmp_seq=2 ttl=255 time=0.681 ms
64 bytes from 192.168.1.2: icmp_seq=3 ttl=255 time=0.656 ms
^C
----ape PING Statistics----
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.649/0.818/1.286/0.312 ms
但是现在的设定在下一次开机时会消失,必须重复进行一次网路卡 的设定。为了避免每次开机时重复设定网路卡,需要完成两件事: 第一,建立 /etc/ifconfig.ne0 档并包含 以下这行:
inet 192.168.1.1 netmask 0xffffff00
接著,在 /etc/rc.conf 中,设定以下选项
auto_ifconfig=YES
在下一次开机时,网路卡将会被自动地设定了。
/etc/hosts 是 IP 位址和别名的资料库: 它应该包含属于这个内部网路中的主机位址。例如:
Example 9-9. /etc/hosts
# $NetBSD: chap-net.sgml,v 1.2 2002/02/06 14:19:28 jrf Exp $ # # Host Database # This file should contain the addresses and aliases # for local hosts that share this file. # It is used only for "ifconfig" and other operations # before the nameserver is started. # # 127.0.0.1 localhost # # RFC 1918 specifies that these networks are "internal". # 10.0.0.0 10.255.255.255 # 172.16.0.0 172.31.255.255 # 192.168.0.0 192.168.255.255 192.168.1.1 ape.insetti.net ape 192.168.1.2 vespa.insetti.net vespa 192.168.1.0 insetti.net
/etc/nsswitch.conf 应该被修改像 Example 9-2 所解释的一样。
Note: 在此例中,/etc/ifconfig.ne0 被建立因为 被核心承认的网路卡为 ne0;如果你使用不 同的卡,置换适当的名字以取代 ne0。
摘要,设定网路卡必须执行以下的步骤:网路卡必须被安装并与其他 主机相连接。接著必须设定网路卡(使用 ifconfig) 并且,最后,/etc/hosts 和 /etc/nsswitch.conf 档必须被修改。 这种网路类型的管理非常简单,而且适合不太复杂的小型网路。
如果你需要在两台没有网路设备的 PC 之间传输资料,而将资料复制到 磁片上又是不太方便的时候,最简单的解决方案是:两台机器利用序列 缆线做网路连接 (a null modem cable.) 以下的段落描述一些设定。
最简单的例子就是两台机器都执行 NetBSD:使用 SLIP 协定连线是非常简单的。在第一台机器上 执行以下指令:
# slattach /dev/tty00 # ifconfig sl0 inet 192.168.1.1 192.168.1.2
在第二台机器上执行以下指令:
# slattach /dev/tty00 # ifconfig sl0 inet 192.168.1.2 192.168.1.1
现在你可以使用 ping 做测试;例如, 在第二台 PC 上执行:
# ping 192.168.1.1
如果一切正常,则现在在两台机器上已经具有网路连线了,而 ftp 和 telnet和其他相似的指令也能运用了。 机器的别名可写在 /etc/hosts 中。
在以上的例子中,两台 PC 都使用第一序列埠 (/dev/tty0)。如果和你使用的不同, 请置换成适当的装置。
IP 位址像 192.168.x.x 是被保留用在"内部" 网路上的。第一台 PC 的位址是 192.168.1.1 而第二台 则为 192.168.1.2。
要使用更快的传输,可以在slattach 指令中加上 -s 选项。
要使用 ftp 传输档案,必须先启动 inetd 和 ftpd。
Linux: 如果其中一台 PC 跑的是 Linux,则指令会有些不同 (只有在 Linux 机器上)。如果 Linux 机器的位址是 192.168.1.2,则需要以下指令:
# slattach -p slip -s 115200 /dev/ttyS0 & # ifconfig sl0 192.168.1.2 pointopoint 192.168.1.1 up # route add 192.168.1.1 dev sl0别忘了要加上 "&"。
NetBSD 和 Windows NT 经由序列 null modem 缆线做网路连线也是相当容易的。基本上需要做的事是,在 Windows NT 下建立"远端存取"连线并在 NetBSD 上启动 pppd。
在成为 root 后,在 /root 目录中建立 .ppprc 档并启动 pppd,参考以下范例。
connect '/usr/sbin/chat -v CLIENT CLIENTSERVER' local tty00 115200 crtscts lock noauth nodefaultroute :192.168.1.2
第一行的意思将在稍后解释;192.168.1.2 是被 NetBSD 指派 到 Windows NT 主机的位址;tty00 是 用作连线的序列埠(第一序列埠)。
在 NT 上,null modem 必须从控制台 (数据机图示)中安装而使用这个 modem 的 Remote Access 连线必须建立。在 Windows NT 4 底下 null modem driver 是 标准配备,但它并不是 100% 的 null modem:当连线建立时, NT 会传送字串 CLIENT 并期望接收到 CLIENTSERVER。这便是 .ppprc 中第一行的意义: 当连线建立时,chat 必须回答 NT, 否则连线将中断。
在远端存取连线的设定中,必须指明以下设定: 使用 null modem,电话号码 "1"(虽然不被使用), PPP 伺服器,并只打开 TCP/IP 协定,使用的 IP 位址和 namservers(此例中为 NetBSD)。选择硬体控制流量并设定为 115200 8N1。
现在一切就绪,准备连线。
使用 null modem 缆线连接两台机器的序列埠。
在 NetBSD 中执行 pppd。 要查看 pppd 的讯息: tail -f /var/log/messages。
在 Windows NT 中建立远端存取连线。
Windows 95 的设定和 Windows NT 相似:Windows 95 使用远端存取 而 NetBSD 使用 PPP server。大部分(如果不是全部) Windows 95 的版本都没有null modem 驱动程式,这将会使事情较为复杂。最简单的解决方案是,从 Internet 搜寻一个有效的 null modem 驱动程式 (它是个小 .INF 档) 并重复和 Windows NT 一样 相同的步骤。唯一的不同是,.ppprc 的第一行 (用来呼叫 chat的) 可以被移除。
如果你不能替 Windows 95 找到 null modem 驱动程式,我们 仍然可以进行:
建立远端存取连线,如 Section 9.2.5.2 所述, 但是要使用"标准的数据机"。
在 .ppprc 中,置换呼叫 chat 的那一行
connect '/usr/sbin/chat -v ATH OK AT OK ATE0V1 OK AT OK ATDT CONNECT'
建立连线,如Section 9.2.5.2 所述。
在这个方法中,当连线建立时,chat 会被 呼叫,用来模拟 Windows 95 认为的标准数据机,传回和 标准数据机一样的回答给 Windows 95。无论 Windows 95 传送 什么字串,chat 都传回 OK。
这一章(介绍 TCP/IP 网路)是由 Hubert Feyrer <hubert@feyrer.de> 贡献的。
这个字 IPNAT 是由以下字母的开头组成的 Internet Protocol Network Address Translation,可以进行内部网路 和真实网路 (Internet) 的连线工作。这是指只有一个 "真实的" IP,静态的或动态的属于一台跑著 IPNAT 的闸道器, 它也可以让内部网路上的主机,同时连线到 Internet。
一些 IPNAT 范例的使用可以在 /usr/share/examples/ipf 目录中找到:参考 BASIC.NAT 和 nat-setup。
以下设定的例子的详细描述在 Figure 9-6: host 1 可以利用 modem 拨接连接到 Internet 并且获得动态 IP 位址。host 2 和 host 3 不能直接与 Internet 沟通:IPNAT 将 会允许他们如此做:host 1 将扮演 hosts 2 and 3 的闸道器。
要使用 IPNAT 则在核心设定档中 "pseudo-device ipfilter" 选项必须打开。 要检查在目前核心中是否已经包含此选项:
# sysctl net.inet.ip.forwarding net.inet.ip.forwarding = 1
如果结果是 "1",如上述例子一般,则选项是打开的, 否则如果结果是 "0",则选项是关闭的。你可以做这两件事:
编译新核心,并加入 GATEWAY 选项为预设值。
使用以下指令在目前的核心中打开选项:
# sysctl -w net.inet.ip.forwarding=1
如果你将前项指令放入开机 script 中(例如, /etc/rc.local), 它将在下一次开机时自动地被执行。
net.inet.ip.forwarding=1
这一段剩馀的部份将解释如何建立 IPNAT 设定,并使它在进行 PPP 连线时被自动地启动。使用这个设定,在家庭网路中(例子) 的所有主机,都将能够经由闸道器连接到 Internet,甚至它们 并不使用 NetBSD。
首先,建立 /etc/ipnat.conf 档并 包含以下规则:
map ppp0 192.168.1.0/24 -> 0/32 proxy port ftp ftp/tcp map ppp0 192.168.1.0/24 -> 0/32 portmap tcp/udp 40000:60000 map ppp0 192.168.1.0/24 -> 0/32
192.168.1.1/24 是应该被映对的网路位址(此例中, 192.168.1.0/24 也是)。第一行的设定是选择性的:它使得 FTP 能经由闸道器运作。第二行设定用来修正 tcp 和 udp 封包; portmapping 是必要的,因为多对一的关系)。 第三行用来开启 ICMP, ping, 等。
建立 /etc/ppp/ip-up 档;它将在每次 进行 PPP 连线时被呼叫。
#!/bin/sh # /etc/ppp/ip-up /etc/rc.d/ipnat forcestart
建立 /etc/ppp/ip-down;它将在每次 PPP 进行 断线时被呼叫。
#!/bin/sh # /etc/ppp/ip-down /etc/rc.d/ipnat forcestop
ip-up 和 ip-down 都 必须是可执行的:
# chmod u+x ip-up ip-down
闸道器已经准备好了。
建立 /etc/resolv.conf 档并和 闸道器上的一样。
键入以下指令:
# route add default 192.168.1.1
192.168.1.1 是闸道器的位址。
当然,你不需要每次执行这个指令,最好设定 "defaultroute" 选项在 /etc/rc.conf 中或是写入闸道器的位址到 /etc/mygate 中: default route 将在系统初始化的时候,被自动地设定,并使用 /etc/mygate 的内容 (或 defaultroute 选项) 作为 route add default 指令的参数。
如果 client 机器不使用 NetBSD,设定将会不相同。 在 Windows PC 上,你需要适当地设定 TCP/IP 协定的闸道器为 NetBSD 闸道器 的 IP 位址。
这就是 client 机器所要做的事。
以下有用的指令可以用来诊断问题:
显示 routing table (类似 route show).
在 client 端显示封包到其他目的地的路径。
在闸道器上用来监督 TCP/IP 流量。
我们在网路上可以使用 NFS 来共享档案和目录。 从档案共享的观点来看,提供档案和目录存取的电脑称之为 server,而使用这些档案和目录的电脑称之为 client。一台电脑可同时成为 client 和 server。
要使用 client 和 server,在编译核心时必须加入适当的选项 (在核心设定档中通常很容易发现这些选项。请看 Section 9.2.1 可以获得与 NFS 相关的核心选项 的资讯)。
server 必需在 /etc/inetd.conf 中 打开它的 RPC 服务。
在 /etc/rc.conf 中,server 必须打开 inetd 和 portmap 常驻程式和 nfs_server 选项。
在 /etc/rc.conf 中,client 必须打开 inetd 和 nfs_client。
server 必须列出开放的目录在 /etc/exports 中并且执行 kill -HUP `cat /var/run/mountd.pid。
client 主机可以经由 NFS 存取远端的目录,如果:
server 主机开放了目录。
client 主机使用这个指令挂上远端的目录 mount server:/xx/yy /mnt
对远端的目录而言,mount 指令提供了丰富的 选项以供设定。
警告:我从 NetBSD mailing list 上挑选了较为复杂的范例,而我 还没有测试过;它应该可以为 NFS 的运作 提供一些意见。
以下的情况为:五台 client 机器 (cli1, ...,cli5) 共享了在 server (buzz.toys.org.) 上的一些目录。某些 server 上的目录 只向特定的 client 开放,其他的目录则开放给所有的 client。 所有的 client 从 server 上开机并且必须挂上目录。
从 server 上开放的目录为:
五个 root 目录分配给五台 client 机器。 每台 client 都有它自己的 root 目录。
五个 swap 目录分配给五台 swap 机器。
/usr 目录被所有的 client 主机共用。
/usr/src 目录被所有的 client 主机共用。
在 server 上存在以下的档案系统
/dev/ra0a on / /dev/ra0f on /usr /dev/ra1a on /usr/src /dev/ra2a on /export
每一台 client 都需要以下的档案系统
buzz:/export/cli?/root on / buzz:/export/common/usr on /usr buzz:/usr/src on /usr/src
server 的设定像这样:
# /etc/exports /usr/src -network 123.45.67.0 -mask 255.255.255.0 /export -alldirs -maproot=root -network 123.45.67.0 -mask 255.255.255.0
在 client 机器上,/etc/fstab 包含
buzz:/export/cli?/root / nfs rw buzz:/export/common/usr /usr nfs rw,nodev,nosuid buzz:/usr/src /usr/src rw,nodev,nosuid
每一台 client 机器都有它的号码,用以取代前例中 首行的 "?" 字元。
The problem with NFS (and other) mounts is, that you usually have to be root to make them, which can be rather inconvenient for users. Using amd you can set up a certain directory (I'll take /net), under which one can make any NFS-mount as a normal user, as long as the filesystem about to be accessed is actually exported by the NFS server.
To check if a certain server exports a filesystem, and which ones, use the showmount-command with the -e (export) switch:
% showmount -e wuarchive.wustl.edu Exports list on wuarchive.wustl.edu: /export/home onc.wustl.edu /export/local onc.wustl.edu /export/adm/log onc.wustl.edu /usr onc.wustl.edu / onc.wustl.edu /archive Everyone
If you then want to mount a directory to access anything below it (for example /archive/systems/unix/NetBSD), just change into that directory:
% cd /net/wuarchive.wustl.edu/archive/systems/unix/NetBSD
The filesystem will be mounted (by amd), and you can a access any files just as if the directory was mounted by the superuser of your system.
You can set up such a /net directory with the following steps (including basic amd configuration):
in /etc/rc.conf, set the following variable:
amd=yes
mkdir /amd
mkdir /net
Taking /usr/share/examples/amd/master, put the following into /etc/amd/master:
/net /etc/amd/net
Taking /usr/share/examples/amd/net as example, put the following into /etc/amd/net:
/defaults type:=host;rhost:=${key};fs:=${autodir}/${rhost}/root
* host==${key};type:=link;fs:=/ \
host!=${key};opts:=ro,soft,intr,nodev,nosuid,noconn
Reboot, or (re)start amd by hand:
# sh /etc/rc.d/amd restart
This section will concentrate on how to get network connectivity for IPv6 and - as that's still not easy to get native today - talk in length about the alternatives to native IPv6 connectivity as a transitional method until native IPv6 peers are available.
Finding an ISP that offers IPv6 natively needs quite some luck. What you need next is a router that will be able to handle the traffic. To date, not all router manufacturers offer IPv6 support for their machines, and even if they do, it's unlikely that they offer hardware accelerated IPv6 routing or switching. A rather cheap alternative to the router hardware commonly in use today is using a standard PC and configure it as a router, e.g. by using some Linux or BSD derived operating system like NetBSD, and use software like Zebra for handling the routing protocols. This solution is rather common today for sites that want IPv6 connectivity today. The drawbacks are that you need an ISP that supports IPv6, and that you need dedicated uplink only for IPv6.
If this is not an option for you, you can still get IPv6 connectivity by using tunnels. Instead of talking IPv6 on the wire, the IPv6 packets are encapsulated in IPv4 packets, as shown in Figure 9-7. Using existing IPv4 infrastructure, the encapsulated packets are sent to a IPv6-capable uplink that will then remove the encapsulation, and forward the IPv6 packets via native IPv6.
When using tunnels, there are two possibilities. One is to use a so-called "configured" tunnel, the other is called an "automatic" tunnel. A "configured" tunnel is one that required preparation from both ends of the tunnel, usually connected with some kind of registration to exchange setup information. An example for such a configured tunnel is the IPv6-over-IPv4 encapsulation described in [RFC1933], and that's implemented e.g. by the gif(4) device found in NetBSD.
An "automatic" tunnel consists of a public server that has some kind of IPv6 connectivity, e.g. via 6Bone. That server has made it's connectivity data public, and also runs a tunneling protocol that does not require an explicit registration of the sites using it as uplink. A well-used example of such a protocol is the 6to4 mechanism described in [RFC3056], and that is implemented in the stf(4) device found in NetBSD's. Another mechanism that does not require registration of IPv6-information is the 6over4 mechanism, which implements transporting of IPv6 over a multicast-enabled IPv4 network, instead of e.g. ethernet or FDDI. 6over4 is documented in [RFC2529]. It's main drawback is that you do need existing multicast infrastructure. If you don't have that, setting it up is about as much effort as setting up a configured IPv6 tunnel directly, so it's usually not worth bothering in that case.
6to4 is an easy way to get IPv6 connectivity for hosts that only have an IPv4 uplink, esp. if you have the background given in Section 9.1.7. It can be used with static as well as dynamically assigned IPv4 addresses, e.g. as found in modem dialup scenarios today. When using dynamic IPv4 addresses, a change of IP addresses will be a problem for incoming traffic, i.e. you can't run persistent servers.
Example configurations given in this section is for NetBSD 1.5.2.
The 6to4 IPv6 setup on your side doesn't consist of a single IPv6 address; Instead, you get a whole /48 network! The IPv6 addresses are derived from your (single) IPv4 address. The address prefix "2002:" is reserved for 6to4 based addresses (i.e. IPv6 addresses derived from IPv4 addresses). The next 32 bits are your IPv4 address. This results in a /48 network that you can use for your very own purpose. It leaves 16 bits space for 216 IPv6 subnets, which can take up to 264 nodes each. Figure 9-8 illustrates the building of your IPv6 address (range) from your IPv4 address.
Thanks to the 6to4 prefix and your worldwide unique IPv4 address, this address block is unique, and it's mapped to your machine carrying the IPv4 address in question.
In contrast to the configured "IPv6-over-IPv4 tunnel" setup, you do not have to register at a 6bone-gateway, which will then forward you any IPv6 traffic (encapsulated in IPv4). Instead, as your IPv6 address is derived from your IPv4 address, any answers can be sent through your nearest 6to4 gateway to you. De-encapsulation of the packet is done via a 6to4-capable network interface, which then forwards the resulting IPv6 package according to your routing setup (in case you have more than one machine connected on your 6to4 assigned network).
For sending out IPv6 packets, the 6to4-capable network interface will take the IPv6 packet, and encapsulate it into a IPv4 packet. You still need a 6bone-connected 6to4-gateway as uplink that will de-encapsulate your packets, and forward them on over the 6Bone. Figure 9-9 illustrates this.
In contrast to the "configured tunnel" setup, you usually can't setup packet filters to block 6to4-packets from unauthorized sources, as this is exactly how (and why) 6to4 works at all. As such, malicious users can send packets with invalid/hazardous IPv6 payload. If you don't already filter on your border gateways anyways, packets with the following characteristics should not be allowed as valid 6to4 packets, and some firewalling seems to be justified for them:
unspecified IPv4 source/destination address: 0.0.0.0/8
loopback address in outer (v4) source/destination: 127.0.0.0/8
IPv4 multicast in source/destination: 224.0.0.0/4
limited broadcasts: 255.0.0.0/8
subnet broadcast address as source/destination: depends on your IPv4 setup
The NetBSD stf(4) manual page documents some common configuration mistakes intercepted by default by the KAME stack as well as some further advice on filtering, but keep in mind that because of the requirement of these filters, 6to4 is not perfectly secure. Still, if forged 6to4 packets become a problem, you can use IPsec authentication to ensure the IPv6 packets are not modified.
In order to setup and configure IPv6 over 6to4, a few bits of configuration data must be known in advance. These are:
Your local IPv4 address. It can be determined using either the 'ifconfig -a' or 'netstat -i' commands on most Unix systems. If you use a NATing gateway or something, be sure to use the official, outside-visible address, not your private (10/8 or 192.168/16) one.
We will use 62.224.57.114 as the local IPv4 address in our example.
Your local IPv6 address, as derived from the IPv4 address. See Figure 9-8 on how to do that.
For our example, this is 2002:3ee0:3972:0001::1 (62.224.57.114 == 0x3ee03972, 0001::1 arbitrarily chosen).
The IPv6-address of the 6to4 uplink gateway you want to use. The IPv6 address will do, as it also contains the IPv4 address in the usual 6to4 translation.
We will use 2002:c25f:6cbf::1 (== 194.95.108.191 == 6to4.ipv6.fh-regensburg.de).
To process 6to4 packets, the operating system kernel needs to know about them. For that a driver has to be compiled in that knows about 6to4, and how to handle it.
For a NetBSD kernel, put the following into your kernel config file to prepare it for using IPv6 and 6to4, e.g. on NetBSD use:
options INET6 # IPv6 pseudo-device stf # 6to4 IPv6 over IPv4 encapsulation
Note that the stf(4) device is not enabled by default. Rebuild your kernel, then reboot your system to use the new kernel. Please consult Chapter 7 for further information on configuring, building and installing a new kernel!
This section describes the commands to setup 6to4. In short, the steps performed here are:
Configure interface
Set default route
Setup Router Advertisement, if wanted
The first step in setting up 6to4 is assigning an IPv6 address to the 6to4 interface. This is achieved with the ifconfig(8) command. Assuming the example configuration above, the command for NetBSD is:
# ifconfig stf0 inet6 2002:3ee0:3972:1::1 prefixlen 16 alias (local)
After configuring the 6to4 device with these commands, routing needs to be setup, to forward all IPv6 traffic to the 6to4 (uplink) gateway. The best way to do this is by setting a default route, the command to do so is, for NetBSD:
# route add -inet6 default 2002:cdb2:5ac2::1 (remote)
Note that NetBSD's stf(4) device determines the IPv4 address of the 6to4 uplink from the routing table. Using this feature, it is easy to setup your own 6to4 (uplink) gateway if you have a IPv6 uplink, e.g. via 6Bone.
After these commands, you are connected to the IPv6-enabled world - Congratulations! Assuming name resolution is still done via IPv4, you can now ping a IPv6-site like www.kame.net or www6.netbsd.org:
# /sbin/ping6 www.kame.net
As a final step in setting up IPv6 via 6to4, you will want to setup Router Advertisement if you have several hosts on your network. While it is possible to setup 6to4 on each node, doing so will result in very expensive routing from one node to the other - packets will be sent to the remote 6to4 gateway, which will then route the packets back to the neighbor node. Instead, setting up 6to4 on one machine and talking native IPv6 on-wire is the preferred method of handling things.
The first step to do so is to assign a IPv6-address to your ethernet. In the following example we will assume subnet "2" of the IPv6-net is used for the local ethernet and the MAC address of the ethernet interface is 12:34:56:78:9a:bc, i.e. your local gateway's ethernet interface's IP address will be 2002:3ee0:3972:2:1234:56ff:fe78:9abc. Assign this address to your ethernet interface, e.g.
ifconfig ne0 inet6 alias 2002:3ee0:3972:2:1234:56ff:fe78:9abc
Here, 'ne0' is an example for your ethernet card interface. This will most likely be different for your setup, depending on what kind of card is used.
Next thing that needs to be ensured for setting up the router is that it will actually forward packets from the local 6to4 device to the ethernet device and back. To enable IPv6 packet forwarding, set "ip6mode=router" in NetBSD's /etc/rc.conf, which will result in the "net.inet6.ip6.forwarding" sysctl being set to "1":
# sysctl -w net.inet6.ip6.forwarding=1
To setup router advertisement on BSD, the file /etc/rtadvd.conf needs to be checked. It allows configuration of many things, but usually the default config of not containing any data is ok. With that default, IPv6 addresses found on all of the router's network interfaces will be advertised.
After checking the router advertisement configuration is correct and IPv6 forwarding is turned on, the daemon handling it can be started. Under NetBSD, it is called 'rtadvd'. Start it up either manually (for testing it the first time) or via the system's startup scripts, and see all your local nodes automagically configure the advertised subnet address in addition to their already-existing link local address.
# rtadvd
So far, we have described how 6to4 works and how to set it up manually. For an automated way to make everything happen e.g. when going online, the '6to4' package is convenient. It will determine your IPv6 address from the IPv4 address you got assigned by your provider, then set things up that you are connected.
Steps to setup the pkgsrc/net/6to4 package are:
Install the package either by compiling it from pkgsrc, or by pkg_add'ing the 6to4-1.1nb1 package.
# cd /usr/pkgsrc/net/6to4 # make install
Make sure you have the stf(4) pseudo-device in your kernel, see above.
Configure the '6to4' package. Frist, copy /usr/pkg/etc/6to4.conf-example to /usr/pkg/etc/6to4.conf, then adjust the variables. Note that the file is in perl syntax.
# cd /usr/pkg/etc # cp 6to4.conf-example 6to4.conf # vi 6to4.conf
Please see the 6to4(8) manpage for an explanation of all the variables you can set in 6to4.conf. If you have diapup IP via PPP, and don't want to run Router Advertizing for other IPv6 machines on your home or office network, you don't need to configure anything. If you want to setup Router Advertising, you need to set the in_if to the internal (ethernet) interface, e.g.
$in_if="rtk0"; # Inside (ethernet) interface
Now dial up, then start the 6to4 command manually:
# /usr/pkg/sbin/6to4.pl start
After that, you should be connected, use ping6(8) etc. to see if everything works. If it does, you can put the following lines into your /etc/ppp/ip-up script to run the command each time you go online:
logger -p user.info -t ip-up Configuring 6to4 IPv6 /usr/pkg/sbin/6to4.pl stop /usr/pkg/sbin/6to4.pl start
If you want to route IPv6 for your LAN, you can instruct 6to4.pl to setup Router Advertising for you too:
# /usr/pkg/sbin/6to4 rtadvd-start
You can put that command into /etc/ppp/ip-up as well to make it permanent.
If you have changed /etc/ppp/ip-up to setup 6to4 automatically, you will most likely want to change /etc/ppp/ip-down too, to shut it down when you go offline. Here's what to put into /etc/ppp/ip-down:
logger -p user.info -t ip-down Shutting down 6to4 IPv6 /usr/pkg/sbin/6to4.pl rtadvd-stop /usr/pkg/sbin/6to4.pl stop
There are not many public 6to4 gateways available today, and from the few available, you will want to chose the one closest to you, netwise. A list of known working 6to4 gateways is available at http://www.kfu.com/~nsayer/6to4/. In tests, only 6to4.kfu.com and 6to4.ipv6.microsoft.com were found working. Cisco has another one that you have to register to before using it, see http://www.cisco.com/ipv6/.
There's also an experimental 6to4 server located in Germany, 6to4.ipv6.fh-regensburg.de. This server runs under NetBSD 1.5 and was setup using the configuration steps described above. The whole configuration of the machine can be seen at http://www.feyrer.de/IPv6/netstart.local.
Compared to where IPv4 is today, IPv6 is still in it's early steps. It is working, there are all sort of services and clients available, only the userbase is missing. It is hoped the information provided here helps people better understand what IPv6 is, and to start playing with it.
A few links should be mentioned here for interested parties:
An example script to setup 6to4 on BSD based machines is available at http://www.netbsd.org/packages/net/6to4/. The script determines your IPv6 address and sets up 6to4 and (if wanted) router advertising. It was designed to work in dialup setups with changing IPv4 addresses.
Given that there isn't a standard for IPv6 in Linux land today, there are different setup instructions for most distributions. The setup of IPv6 on Debian Linux can be found at http://people.debian.org/~csmall/ipv6/setup.html and http://www.mailgate.org/linux/linux.debian.ipv6/msg00137.html.
The BSD Unix implementations have their own IPv6 documentation each, interresting URLs are http://www.netbsd.org/Documentation/network/ipv6/ for NetBSD, http://www.freebsd.org/doc/en_US.ISO_8859-1/books/handbook/ipv6-implementation.html for FreeBSD and pages 61 and 62 of the BSD/OS Administrator's Guide at http://www.bsdi.com/products/internet/release-notes/rn42.pdf.
Projects working on implementing IPv6 protocol stacks for free Unix like operating systems are KAME for BSD and USAGI for Linux. Their web sites can be found at http://www.kame.net/ and http://www.linux-ipv6.org/. A list of host and router implementations can be found at http://playground.sun.com/pub/ipng/html/ipng-implementations.html.
Besides the official RFC archive at ftp://ftp.isi.edu/in-notes, information on IPv6 can be found at several web sites. First and foremost, the 6Bone's web page at http://www.6bone.net/ must be mentioned. 6Bone was started as the testbed for IPv6, and is now an important part of the IPv6-connected world. Other web pages that contain IPv6-related contents include http://www.ipv6.org/, http://playground.sun.com/pub/ipng/html/ and http://www.ipv6forum.com/. Most of these sites carry further links - be sure to have a look!