Опубликован: 06.08.2012 | Уровень: специалист | Доступ: платный
Лекция 17:

Configuring the local network

< Лекция 16 || Лекция 17: 12345 || Лекция 18 >
Starting dhcpd

The dhcpd port installs a sample startup file in the directory /usr/local/etc/rc.d. It's called isc-dhcpd.sh.sample, a name which ensures that it won't get executed. This file doesn't normally require any configuration; simply copy it to isc-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/
Mar  14  15:45:09  freebie dhcpd: Sending on BPF/xl0/00:50:da:cf:07:35/
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 Card networking cards

We've 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’t configure them in the same manner at startup, because they might not yet be present.

On inserting a PC Card device, you will see something like this on the console:

Manufacturer ID: 01015751
Product version: 5.0
Product name: 3Com Corporation | 3CCFE575BT | LAN Card bus 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 Ether link 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’s not configured. FreeBSD uses the devd daemon to perform user land configuration after a card has been attached. We've 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 xlO 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/startjf.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. If not, it continues.
  • If the value of ifconfig_xl0 is NO, it exits.
  • If the value of ifconfig_xl0 is DHCP, it attempts to set up the interface with DHCP.
  • Otherwise it performs the ifconfig commands specified in the variable if config_xl0.

That's a lot 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’s the same as with other network cards: either IP address and other options, or DHCP. The third alternative is important, though. Let’s consider the case where you want to start a number of services when the system is connected. You might want to run ntpdate, then start ntpd and rwhod, and you may want to mount some NFS file systems. You can do all this at startup with normal network cards, but /etc/pccard_ether isn't clever enough to do all that. Instead, create a file called /etc/startjf.xl0 and give it the following contents:

dhclient xl0
ntpdate freebie
killall ntpd
ntpd &
killall rwhod
rwhod &
mount –t nfs -a

Don’t forget 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:

removable interfaces="wi0 xe0 xl0"

The values in the last line only need to include xl0, of course, but it’s good 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 any static routes for that interface.

If you travel elsewhere with a laptop and suspend the system, make sure you unmount any NFS file systems first. You can't do it once you're no longer connected to the network, and it’s possible that things will hang trying to access NFS-mounted files.

Setting up wireless networking

We saw in "Networks and the Internet" that wireless cards have a few more tricks up their sleeves than 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?
  • If you're running in IBSS or Lucent demo ad-hoc mode, you'll need to know the frequency(channel) on which the network is running.
  • If you're running in IBSS mode, do you already have an IBSS, or is your machine
  • going to be the IBSS?
  • Are you worried about power consumption? If you're running in BSS mode, you can significantly reduce the power consumption of the card by turning on power save mode, but it can slow some things down.
  • Are you using WEP? If so, what’s the key?

Each of these translates into an ifconfig command. Here are some typical examples:

ifconfig wi0 ssid Example                       join Example network
ifconfig wi0 media autoselect media opt -adhoc  set BSS mode
ifconfig wi0 channel 3                          select channel 3 (if not in BSS mode)
ifconfig wi0 wepmode on                         turn encryption on (if using WEP)
ifconfig wi0 wepkey 0x42726f6b21                encryption key (for WEP)

When setting media options, you must also select the media, even if it is unchanged; thus the media autoselect in the example above.

You have a choice of where to put these specifications. For example, if you were connecting to the Example network, which is IBSS, you could put this in your /etc/rc.conf

ifconfig_wi0=" ssid Example media autoselect media opt adhoc \
channel 3 wepmode on wepkey 0x42726f6b21 removable interfaces="wi0 xe0 xl0"

You don't need to do anything special to become an IBSS master in an IBSS network: if there is no master already, and your card supports it, your system will become the IBSS master.

If, on the other hand, you were connecting to a non-encrypted network, you would not need the WEP key, and you might enter:

ifconfig_wi0=" ssid Example media autoselect media opt ibss-master channel 3 wepmode off"

What we can do now

At this point, we have configured the link layer. We can communicate with directly connected machines. To communicate with machines that are not directly connected, we need to set up routing. We'll look at that next.

< Лекция 16 || Лекция 17: 12345 || Лекция 18 >
Бехзод Сайфуллаев
Бехзод Сайфуллаев
Узбекистан, Бухара, Бухарский институт высоких технологий, 2013
Василь Остапенко
Василь Остапенко