這一章 (介紹 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!