Tài liệu Chapter-17-Configuring the local network pdf

18 427 0
Tài liệu Chapter-17-Configuring the local network pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

2Apr il 2003, 17:00:47 The Complete FreeBSD (netsetup.mm), page 297 17 Configuring the local network In this chapter: • Networ k configuration with sysinstall • Manual networ k configuration • Automatic configuration with DHCP • Configur ing PC Card networ king cards • Setting up wireless networ king • Routing • ISP’sroute setup • Looking at the routing tables • Packetforwarding • Configuration summar y In this chapter: • Networ k configuration with sysinstall • Manual networ k configuration • Automatic configuration with DHCP • Configur ing PC Card networ king cards • Setting up wireless networ king • Routing • ISP’sroute setup • Looking at the routing tables • Packetforwarding • Configuration summar y In Chapter 16 we looked at the basic concepts surrounding BSD networking. In this chapter and the following two, we’ll look at what we need to do to configure a network, first manually,then automatically.Configuring PPP is still a whole lot more difficult than configuring an Ethernet, and theyrequire more prerequisites, so we’ll dedicate Chapter 20, to that issue. In this chapter,we’ll first look at example.org in the reference network on page 294, since it’sthe easiest to set up. After that, we’ll look at what additional information is needed to configure machines on example.net. Network configuration with sysinstall To configure a network, you must describe its configuration to the system. The system initialization routines that we discussed on page 524 include a significant portion that sets up the network environment. In addition, the system contains a number of standard IP configuration files that define your system’sviewofthe network. If you didn’tconfigure the network when you installed your system, you can still do it now. Log in as root and start sysinstall.Select the Index,then Network Interfaces.You will see the menu of Figure 17-1, which is the same as in Figure 6-4 on page 97. On a standard 80x25 display it requires scrolling to see the entire menu. The only real network board on this list is xl0,the Ethernet board. The others are standard hardware that can also be used as network interfaces. netsetup.mm,v v4.15 (2003/04/02 06:50:16) 297 Networ k configuration with sysinstall 298 2April 2003, 17:00:47 The Complete FreeBSD ( /tools/tmac.Mn), page 298 Figure17-1: Network setup menu Choose the Ethernet board, xl0 Youget a question about whether you want to use IPv6 configuration. This book we doesn’tdiscuss IPv6, so answer No.Nextyou get a question about DHCP configuration. We discuss DHCP configuration on page 302. If you already have a DHCP server set up, you may prefer to answer Yes to this question, which is all you need to do. If you answer No,the next menu asks us to set the internet parameters. Figure 17-2 shows the network configuration menu after filling in the values. Figure17-2: Network configuration menu netsetup.mm,v v4.15 (2003/04/02 06:50:16) 299 Chapter 17: Configuring the local networ k 2April 2003, 17:00:47 The Complete FreeBSD ( /tools/tmac.Mn), page 299 Specify the fully qualified local host name. When you tab to the Domain: field, the domain is filled in automatically.Wehav e chosen to call this machine presto,and the domain is example.org.Inother words, the full name of the machine is presto.exam- ple.org.Its IP address is 223.147.37.2.Inthis configuration, all access to the outside world goes via gw.example.org,which has the IP address 223.147.37.5.The name server is located on the same host, presto.example.org.Ifthe name server isn’trunning when this information is needed, we must specify all addresses in numeric form, as shown. What happens if you don’thav e adomain name? If you’re connecting to the global Internet, you should go out and get one—see page 318. But in the meantime, don’tfake it. Just leave the fields empty.Ifyou’re not connecting to the Internet, of course, it doesn’tmakemuch difference what name you choose. As is usual for a class C network, the net mask is 255.255.255.0.You don’tneed to fill in this information—if you leave this field without filling it in, sysinstall inserts it for you. Normally,asinthis case, you wouldn’tneed anyadditional options to ifconfig. sysinstall savesconfiguration information in /etc/rc.conf.When the system starts, the startup scripts use this information to configure the network. It also optionally starts the interface immediately.Inthe next section we’ll look at the commands it uses to perform this function. Manual network configuration Usually FreeBSD configures your network automatically when it boots. To doso, it uses the configuration files in /etc.Sowhy doitmanually? There are several reasons: • It makes it easier to create and maintain the configuration files if you knowwhat’s going on behind the scenes. • It makes it easier to modify something ‘‘on the fly.’’You don’thav e to reboot just because you have changed your network configuration. • With this information, you can edit the configuration files directly rather than use the menu interface, which savesalot of time. We spend a lot of time discussing this point on the FreeBSD mailing lists. One thing’sfor sure: neither method of configuration is perfect. Both menu-based and text-file–based configuration schemes offer you ample opportunity to shoot yourself in the foot. But at the moment, the configuration file system is easier to check if you understand what’sgoing on.That’sthe reason for the rest of this chapter. In this section, we’ll look at the manual way to do things first, and then we’ll see howto put it in the configuration files so that it gets done automatically next time. Youcan find asummary of the configuration files and their contents on page 545. netsetup.mm,v v4.15 (2003/04/02 06:50:16) Manual networ k configuration 300 2April 2003, 17:00:47 The Complete FreeBSD ( /tools/tmac.Mn), page 300 Describing your network In Table 16-7 on page 294, we sawthat systems connect to networks via network interfaces.The kernel detects the interfaces automatically when it starts, but you still need to tell it what interfaces are connected to which networks, and evenmore importantly,which address your system has on each network. In addition, if the network is a broadcast network, such as an Ethernet, you need to specify a range of addresses that can be reached directly on that network. As we sawonpage 290, we perform this selection with the network mask. Ethernet interfaces Once we have understood these concepts, it’srelatively simple to use the ifconfig program to set them. Forexample, for the Ethernet interface on system gw,with IP address 223.147.37.5,weneed to configure interface dc0.The network mask is the standard value for a class C network, 255.255.255.0.That’sall we need to know: # ifconfig dc0 inet 223.147.37.5 netmask 255.255.255.0 up In fact, this is more than you usually need. The inet tells the interface to use Internet protocol Version 4 (the default), and up tells it to bring it up (which it does anyway). In addition, this is a class C network address, so the net mask defaults to 255.255.255.0. As a result, you can abbreviate this to: # ifconfig dc0 223.147.37.5 Note that this is different from what Linux requires. With Linux you must supply explicit netmask and broadcast address specifications. As we sawonpage 290, it has become typical to abbreviate net masks to the character / followed by the number of 1 bits set in the network mask. ifconfig understands this usage, so if you wanted to set a non-standard network mask of, say, 255.255.255.240, which has 28 bits set, you could write: # ifconfig dc0 223.147.37.5/28 Point-to-point interfaces With a point-to-point interface, the software currently requires you to specify the IP address of the other end of the link as well. As we shall see in Chapter 20, there is no good reason to do this, but ifconfig insists on it. In addition, we need the network mask for a non-broadcast medium. The value is obvious: 1 you can reach exactly one address at the other end, so it must be 255.255.255.255.With this information, we could configure the PPP interface on gw: 1. Well, you’dthink it was obvious. We’ll see on page 345 that some people think it should be something else. netsetup.mm,v v4.15 (2003/04/02 06:50:16) 301 Chapter 17: Configuring the local networ k 2April 2003, 17:00:47 The Complete FreeBSD ( /tools/tmac.Mn), page 301 # ifconfig tun0 139.130.136.133 139.130.136.129 netmask 255.255.255.255 In fact, this is almost nevernecessary; in Chapter 20 we’ll see that the PPP software usually sets the configuration automatically. The loopbackinterface The IP protocols require you to use an address to communicate with every system—even your own system. Theoretically,you could communicate with your system via the an Ethernet interface, but this is relatively slow: the data would have togothrough the network stack. Instead, there is a special interface for communicating with other processes in the same system, the loopbackinterface.Its name is lo0,and it has the address 127.0.0.1.It’sstraightforward enough to configure: # ifconfig lo0 127.0.0.1 In fact, though, you don’tevenneed to do this much work: the system automatically sets it up at boot time. Checking the interface configuration ifconfig doesn’tjust set the configuration: you can also use it to check the configuration. It’sagood idea to do this after you change something: $ ifconfig dc0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 inet 223.147.37.5 netmask 0xffffff00 broadcast 223.147.37.255 inet6 fe80::280:c6ff:fef9:d3fa%dc0 prefixlen 64 scopeid 0x1 ether 00:80:c6:f9:d3:fa media: Ethernet autoselect (100baseTX <full-duplex>) status: active lp0: flags=8810<POINTOPOINT,SIMPLEX,MULTICAST> mtu 1500 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 inet 127.0.0.1 netmask 0xff000000 tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1500 inet 139.130.136.133 --> 139.130.136.129 netmask 0xffffffff Other BSD systems require you to write ifconfig -a.tolist the configuration of all interfaces, and FreeBSD still accepts it. Some other UNIX systems, particularly System V,don’tunderstand even this flag. There are a number of things to note here: • The dc0 interface has both an IPv4 address (inet)and a corresponding IPv6 address (inet6). It also specifies the Ethernet address (ether 00:80:c6:f9:d3:fa). It is capable of negotiating 10 Mb/s, 100 Mb/s half duplexand 100 Mb/s full duplex. It’s connected to a switch, so it’scurrently running 100 Mb/s full duplex. • The interface lp0 is the the PLIP interface for connections via the parallel port. It is not configured (in other words, it has not been set up for operation). netsetup.mm,v v4.15 (2003/04/02 06:50:16) Manual networ k configuration 302 2April 2003, 17:00:47 The Complete FreeBSD ( /tools/tmac.Mn), page 302 • We’v e already seen the loopback interface lo0. • There is also a tun0 interface for PPP. The configuration files The system startup scripts summarize this configuration information in a number of configuration variables.See Chapter 29 for more details. At the moment, the following variables are of interest to us: • hostname is the name of the host. Youshould have set it when you installed the system (see page 87). Youcan also set it manually with the hostname command: # hostname -s gw.example.org • Foreach interface, a variable of the form ifconfig_interface contains the parameters to be passed to ifconfig to configure that interface. Previously,FreeBSD also required you to set a variable network_interfaces,alist of the names of the interfaces to be configured. This variable nowdefaults to the value auto to specify that all interfaces should be configured. Youonly need to change it if you specifically want to exclude an interface from configuration. For gw,weput the following information in /etc/rc.conf : hostname="gw.example.org" ifconfig_dc0="inet 223.147.37.5" We don’tconfigure the tun0 interface here; as we’ll see in Chapter 20, the PPP setup works differently. Automatic configuration with DHCP Maintaining the network configurations for a number of machines can be a pain, especially if they’re laptops that come and go. There’sanalternative for larger networks: use DHCP,the Dynamic Host Configuration Protocol.DHCP enables a machine to get configuration information automatically from the network. The concept is expandable, buttypically you get an IP address and net mask and the names of the default name servers and routers. In terms of the configuration we’ve seen so far,this replaces running the ifconfig and route programs, and also the file /etc/resolv.conf,which describes the locations of name servers. We’ll look at it on page 366. There are twoparts to DHCP: the client and the server. netsetup.mm,v v4.15 (2003/04/02 06:50:16) 303 Chapter 17: Configuring the local networ k 2April 2003, 17:00:47 The Complete FreeBSD ( /tools/tmac.Mn), page 303 DHCP client To get a configuration, you run dhclient.Inprevious releases of FreeBSD, dhclient printed out information about the addresses it received. In Release 5, it does not print anything. Simply start it with the name of the interface: # dhclient dc0 To assign an address automatically at boot time, put the special value DHCP in the ifconfig_dc0 variable: ifconfig_dc0=DHCP DHCP server DHCP requires a server.The server is not included as part of the base system; instead, install the net/isc-dhcp3 port: # cd /usr/ports/net/isc-dhcp3 # make install To configure dhcpd,edit the configuration file /usr/local/etc/isc-dhcpd.conf.Here’san example: ddns-update-style ad-hoc; #100 Mb/s Ethernet subnet 223.147.37.0 netmask 255.255.255.0 { range 223.147.37.90 223.147.37.110; option domain-name-servers freebie.example.com, presto.example.com; option domain-name "example.com"; option routers gw.example.com; option subnet-mask 255.255.255.0; option broadcast-address 223.147.37.255; default-lease-time 86400; max-lease-time 259200; use-host-decl-names on; use the specified name as host name host andante { hardware ethernet 0:50:da:cf:7:35; } } This configuration file tells dhcpd: • To dynamically allocate IP addresses in the range 223.147.37.90 to 223.147.37.110 (range keyword). • That the domain name servers are freebie.example.com and andante.example.com. We’lllook at domain name servers in Chapter 21. • The net mask and the broadcast address. The variables default-lease-time and max-lease-time,which are specified in seconds, determine howlong it will be before a system checks its configuration. The values here represent one day and three days respectively. netsetup.mm,v v4.15 (2003/04/02 06:50:16) Automatic configuration with DHCP 304 2April 2003, 17:00:47 The Complete FreeBSD ( /tools/tmac.Mn), page 304 use-host-decl-names tells dhcpd to use the name on the host line as the host name of the system. Otherwise you would need an additional option host-name specifica- tion for every system. Forone machine it doesn’tmakemuch difference, but if you have twenty such machines, you’ll notice the difference. One of the problems with dhcpd is that by default it doesn’tallocate a static IP address. Theoretically you could attach a laptop to the same DHCP server and get a different address every time, but in fact dhcpd does its best to keep the same address, and sometimes you may find it impossible to change its mind. In this configuration file, though, we have explicitly told dhcpd about andante,which is recognized by its Ethernet address. This works relatively well for fixed machines, but there’saproblem with laptops and PC Card: dhcpd recognizes the network interface, not the machine, and if you swap the interface card, the IP address movestothe newmachine. Star ting dhcpd The dhcpd port installs a sample startup file in the directory /usr/local/etc/rc.d.It’s called isc-dhcpd.sh.sample,aname which ensures that it won’tget executed. This file doesn’tnormally require anyconfiguration; simply copyittoisc-dhcpd.sh in the same directory.This enables the system startup to find it and start dhcpd. To start dhcpd during normal system operation, just run this same script: # /usr/local/etc/rc.d/isc-dhcpd.sh start Mar 14 15:45:09 freebie dhcpd: Internet Software Consortium DHCP Server V3.0rc10 Mar 14 15:45:09 freebie dhcpd: Copyright 1995-2001 Internet Software Consortium. Mar 14 15:45:09 freebie dhcpd: All rights reserved. Mar 14 15:45:09 freebie dhcpd: For info, please visit http://www.isc.org/products/DHCP Mar 14 15:45:09 freebie dhcpd: Wrote 0 deleted host decls to leases file. Mar 14 15:45:09 freebie dhcpd: Wrote 0 new dynamic host decls to leases file. Mar 14 15:45:09 freebie dhcpd: Wrote 14 leases to leases file. Mar 14 15:45:09 freebie dhcpd: Listening on BPF/xl0/00:50:da:cf:07:35/223.147.37.0/24 Mar 14 15:45:09 freebie dhcpd: Sending on BPF/xl0/00:50:da:cf:07:35/223.147.37.0/24 Mar 14 15:45:09 freebie dhcpd: Sending on Socket/fallback/fallback-net When you change the configuration file /usr/local/etc/isc-dhcpd.conf,you must restart dhcpd: # /usr/local/etc/rc.d/isc-dhcpd.sh restart Configuring PC Cardnetworking cards We’v e looked at PC Card devices on page 159, but there are some special issues involved in configuring networking cards. Of course, ifconfig works with PC Card networking cards in exactly the same way as it does with PCI and ISA cards, but you can’tconfigure them in the same manner at startup, because theymight not yet be present. netsetup.mm,v v4.15 (2003/04/02 06:50:16) 305 Chapter 17: Configuring the local networ k 2April 2003, 17:00:47 The Complete FreeBSD ( /tools/tmac.Mn), page 305 On inserting a PC Card device, you will see something likethis on the console: Manufacturer ID: 01015751 Product version: 5.0 Product name: 3Com Corporation | 3CCFE575BT | LAN Cardbus Card | 001 | Functions: Network Adaptor, Memory CIS reading done cardbus0: Resource not specified in CIS: id=14, size=80 cardbus0: Resource not specified in CIS: id=18, size=80 xl0: <3Com 3c575B Fast Etherlink XL> port 0x1080-0x10bf mem 0x88002400-0x8800247 f,0x88002480-0x880024ff irq 11 at device 0.0 on cardbus0 xl0: Ethernet address: 00:10:4b:f8:fd:20 miibus0: <MII bus> on xl0 tdkphy0: <TDK 78Q2120 media interface> on miibus0 tdkphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto After this, ifconfig shows: $ ifconfig xl0 xl0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500 ether 00:10:4b:f8:fd:20 media: Ethernet autoselect (100baseTX <full-duplex>) The card is there, but it’snot configured. FreeBSD uses the devd daemon to perform userland configuration after a card has been attached. We’v e already looked at devd on page 159. When devd establishes that the card is a networking card, it calls /etc/pccard_ether to configure it. In the following, we’ll see how /etc/pccard_ether configures our xl0 interface. It performs the following steps: • It reads the configuration from /etc/defaults/rc.conf and /etc/rc.conf. • If the interface is already up, it exits. • If a file /etc/start_if.xl0 exists, it executes it. After doing so, it continues. • It checks whether the variable removable_interfaces exists and contains the name of the interface, xl0.Ifnot, it continues. • If the value of ifconfig_xl0 is NO, it exits. • If the value of ifconfig_xl0 is DHCP,itattempts to set up the interface with DHCP. • Otherwise it performs the ifconfig commands specified in the variable ifcon- fig_xl0. That’salot of choice. What do you use when? That depends on what you want to do. The first thing to note is that nothing happens unless your interface name is in the variable removable_interfaces,and the variable ifconfig_xl0 exists. The question is, what do you put in ifconfig_xl0? In principle, it’sthe same as with other network cards: either IP address and other options, or DHCP.The third alternative isimportant, though. Let’sconsider the case where you want to start a number of services when the system is connected. Youmight want to run ntpdate,then start ntpd and rwhod,and you may want to mount some NFS file systems. Youcan do all this at startup with normal network cards, but /etc/pccard_ether isn’tcleverenough to do all that. Instead, create a file called netsetup.mm,v v4.15 (2003/04/02 06:50:16) Configur ing PC Card networ king cards 306 2April 2003, 17:00:47 The Complete FreeBSD ( /tools/tmac.Mn), page 306 /etc/start_if.xl0 and give itthe following contents: dhclient xl0 ntpdate freebie killall ntpd ntpd & killall rwhod rwhod & mount -t nfs -a Don’tforget to start DHCP or otherwise set the IP address, because this method bypasses the standard startups. In addition, you put this in /etc/rc.conf : devd_enable=YES ifconfig_xl0=NO removable_interfaces="wi0 xe0 xl0" The values in the last line only need to include xl0,ofcourse, but it’sgood to put in every interface name that you would possibly use. Detaching network cards When you remove a network card, devd invokes /etc/pccard_ether again. The actions are similar to the one it performs when the card is attached: • If a file /etc/stop_if.xl0 exists, it is executed. • If the variable ifconfig_xl0 is set to DHCP, /etc/pccard_ether stops the dhclient process, which would otherwise loop forever. • If ifconfig_xl0 contains normal ifconfig parameters, /etc/pccard_ether removes anystatic routes for that interface. If you travelelsewhere with a laptop and suspend the system, makesure you unmount anyNFS file systems first. Youcan’tdoitonce you’re no longer connected to the network, and it’spossible that things will hang trying to access NFS-mounted files. Setting up wireless networking We saw inChapter 16 that wireless cards have a few more tricks up their sleevesthan conventional Ethernets. To set them up correctly,you need to know: • Does the network you are joining accept connections with a blank SSID? If not, what is its SSID? • What mode are you running in? Is it BSS mode, IBSS mode, or Lucent demo ad- hoc? netsetup.mm,v v4.15 (2003/04/02 06:50:16) [...]... emphasizes the difference between the output of ifconfig and the routing table ifconfig shows the address of the interface, the address needed to reach our system For the Ethernet interface, it’s 223.147.37.5 The routing table shows the addresses that can be reached from this system, so it shows the base address of the Ethernet, 223.147.37.0 netsetup.mm,v v4.15 (2003/04/02 06:50:16) 2 April 2003, 17:00:47 The. .. routing protocol See the man page netstat(1) for more details • Netif is the name of the interface by which the gateway can be reached In the case of a link, this is the interface, so the Netif field is empty • The order of the entries is not important The system searches the table for a best fit, not a first fit • The default entry points to gw, as we would expect The interface, rl0, is the interface by which... (netsetup.mm), page 309 309 Chapter 17: Configuring the local networkThe third entry represents the PPP interface It is a host entry, like the loopback entry This entry allows access to the other end of the PPP link only, so the net mask is set to 255.255.255.255 (only one system) • Finally, the fourth entry is the big difference It doesn’t have a counterpart in the ifconfig listing It specifies how to reach... for—just about the whole Internet In this case, it refers to the other end address of the PPP link And that’s all there is to it! Well, sort of In our example configuration, we’re hidden in one corner of the Internet, and there’s only one way out to the rest of the network Things look different when you are connected to more than one network On page 310 we’ll look at the differences we need for the ISP example.net... it shows that the local host can be reached by the interface lo0, which is the name for the loopback interface on all UNIX systems Although this entry specifies a single host, the net mask allows for 16,276,778 hosts The other addresses aren’t used • The second entry is for the local Ethernet In this case, we have a direct connection, so we don’t need to specify a gateway address Due to the net mask... igw.example.net gw.example.org local ppp0 interface The first line tells the system that the default route is via gw.example.org The second shows that the network with the base IP address 223.147.37.0 (example.org) can be reached via the gateway address 139.130.136.133, which is the remote end of the PPP netsetup.mm,v v4.15 (2003/04/02 06:50:16) 2 April 2003, 17:00:47 The Complete FreeBSD (netsetup.mm),... about them in TCP/IP Network Administration, by Craig Hunt From our point of view, however, the routing protocols have one particular significance: the system expects the routing table to be updated automatically As a result, it is designed to use the information supplied by the routing protocols to perform the update This information consists of two parts: • The address and netmask of the network (in other... rl0 rl0 1151 645 1195 645 There’s a lot to notice about this information: • The first column is the name of a host or a network to which packets can be sent, or the keyword default netsetup.mm,v v4.15 (2003/04/02 06:50:16) 2 April 2003, 17:00:47 The Complete FreeBSD (netsetup.mm), page 312 Looking at the routing tables 312 • The second column, the gateway, indicates the path to the destination This field... 17: Configuring the local network link connected via ppp3 In the case of biguser.com, we don’t know the address of the remote end; possibly it changes every time it’s connected As a result, we specify the name of the interface instead: we know it’s always connected via ppp0 The procedure to add this information to /etc/rc.conf is similar to what we did for the interface addresses: • The variable static_routes... performs them with the aid of a routing table, which tells the system which addresses are available where We’ve already seen the net mask in Chapter 16, on page 290 We’ll see that it also plays a significant role in the routing decision Table 17-1 shows a symbolic view of the routing table for gw.example.org It looks very similar to the ifconfig output in the previous section: • The first entry is the loopback . • The address and netmask of the network (in other words, the address range). • The address of the gateway that forwards data for this address range. The. -iface ppp0 local ppp0 interface The first line tells the system that the default route is via gw.example.org .The second shows that the network with the base

Ngày đăng: 11/12/2013, 00:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan