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 they require 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’s the easiest to set up. After that, we’ll look at what additional information is needed to configure machines on example.net.
To configure a network, you must describe its configuration to the system. The system 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
(рис 17.1) Network setup menu
Choose the Ethernet board, xl0 You get a question about whether you want to use IPv6 configuration. In this book we doesn’t d discuss IPv6, so answer No. Next you 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
(рис 17.2) Network configuration menu
Specify the fully qualified local host name. When you tab to the Domain: field, the domain is filled in automatically. We have chosen to call this machine presto, and the domain is example.org. In other words, the full name of the machine is presto.example.org. Its IP address is 223.147.37.2. In this 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. If the name server isn’t running when this information is needed, we must specify all addresses in numeric form, as shown.
What happens if you don’t have a domain name? If you’re connecting to the global Internet, you should go out and get one-see page 318. But in the meantime, don’t fake it. Just leave the fields empty. If you’re not connecting to the Internet, of course, it doesn’t make much difference what name you choose.
As is usual for a class C network, the net mask is 255.255.255.0. You don’t need to fill in this information—if you leave this field without filling it in, sysinstall inserts it for you. Normally, as in this case, you wouldn’t need any additional options to ifconfig
sysinstall saves configuration 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. In the next section we’ll look at the commands it uses to perform this function.
Usually FreeBSD configures your network automatically when it boots. To do so, it uses the configuration files in/etc. So why do it manually? There are several reasons:
In this section, we’ll look at the manual way to do things first, and then we’ll see how to put it in the configuration files so that it gets done automatically next time. You can find a summary of the configuration files and their contents on page 551.
We saw that 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 even more 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, network mask.
Once we have understood these concepts, it’s relatively simple to use the ifconfig program to set them. For example, for the Ethernet interface on system gw, with IP address 223.147.37.5, we need to configure interface . The 255.255.255.0. That’sall we need to know:
# ifconfig dc0 inet 223.147.37.5 net mask 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
# ifconfig dc0 223.147.37.5
Note that this is different from what Linux requires. With Linux you must supply explicit net mask and
As we saw on page 290, it has become typical to / followed by the number of 1 bits set in the 255.255.255.240, which has 28 bits set, you could write:
# ifconfig dc0 223.147.37.5/28
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 255.255.255.255. With this information, we could configure the PPP interface on gw:
# ifconfig tun0 139.130.136.133 139.130.136.129 net mask 255.255.255.255
In fact, this is almost never necessary; in Chapter 20 we’ll see that the PPP software usually sets the configuration automatically.
The IP protocols require you to use an address to communicate with every system—even your own system. . Its name is lo0, and it has the address 127.0.0.1. It’s straightforward enough to configure:
# ifconfig lo0 127.0.0.1
In fact, though, you don’t even need to do this much work: the system automatically sets it up at
ifconfig doesn’t just set the configuration: you can also use it to check the configuration. It’s a good idea to do this after you change something:
$ ifconfig
dc0: flags=8843< UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST > mtu 1500
inet 223.147.37.5 net mask 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 net mask 0xff000000
tun0: flags=8051<UP, POINTOPOINT, RUNNING, MULTICAST > mtu 1500
inet 139.130.136.133 -- > 139.130.136.129 net mask 0xffffffff
ifconfig -a. to list the configuration of all interfaces, and FreeBSD still accepts it. Some commercial UNIX systems don’t understand even this fag.
There are a number of things to note here:
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 The system startup scripts
hostname is the name of the host. You should have set it when you installed the system (see page 87). You can also set it manually with the hostname command:
# hostname -s gw.example.org
Previously, FreeBSD also required you to set a variable network_interfaces, a list of the names of the interfaces to be configured. This variable now defaults to the value auto to specify that all interfaces should be configured. You only need to change it if you specifically want to exclude an interface from configuration.
For gw, we put the following information in /etc/rc.conf:
hostname=‘gw.example.org’ ifconfig_dc0=‘inet 223.147.37.5’
We don’t configure the tunO interface here; as we’ll see in Chapter 20, the PPP setup works differently.
Maintaining the DHCP, the Dynamic Host Configuration Protocol. DHCP enables a machine to get configuration information automatically from the network. The concept is expandable, but typically 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 two parts to DHCP: the client and the server.
To get a configuration, you run dhclient. In previous 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 ifconfig_dc0 variable:
ifconfig_dc0=DHCP
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's an example:
ddns-update-style ad-hoc;
# 100 Mb/s Ethernet
subnet 223.147.37.0 net mask 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:
223.147.37.90 to 223.147.37.110 (range keyword).The variables default-lease-time and max-lease-time, which are specified in seconds, determine how long it will be before a system checks its configuration. The values here represent one day and three days respectively.
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 specification for every system. For one machine it doesn’t makemuch 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’t allocate a static IP address. 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 dhcpd recognizes the network interface, not the machine, and if you swap the
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
# /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
We've looked at ifconfig works with
On inserting a
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:
/etc/defaults/rc.conf and /etc/rc.conf.removable interfaces exists and contains the name of the interface, xl0. If not, it continues.ifconfig_xl0 is NO, it exits.DHCP, it attempts to set up the interface with DHCP.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 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 /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
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, of course, but it’s good to put in every interface name that you would possibly use.
When you remove a devd invokes /etc/pccard_ether again. The actions are similar to the one it performs when the card is attached:
ifconfig_xl0 is set to DHCP, /etc/pccard_ether stops the dhclient process, which would otherwise loop forever.ifconfig_xl0 contains normal ifconfig parameters, /etc/pccard_ether removes any If you travel elsewhere with a
We saw in Chapter 16 that wireless cards have a few more tricks up their
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 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
devd_enable=YES ifconfig_wi0="192.168.27.4 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
ifconfig_wi0="192.168.27.4 ssid Example media autoselect media opt ibss-master channel 3 wepmode off"
At this point, we have configured the
Looking back at our example network on page 294, we'll reconsider a problem we
| Destination | Gateway | Net mask | Type | Interface |
|---|---|---|---|---|
| 127.0.0.1 | 127.0.0.1 | 255.0.0.0 | Host | lo0 |
| 223.147.37. | 255.255.255.0 | Direct | dc0 | |
| 139.130.136.129 | 139.130.136.133 | 255.255.255.255 | Host | tun0 |
| Default | 139.130.136.129 | 0.0.0.0 | Gateway | tun0 |
These decisions are the basis of routing. The implementation 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 gv.example.org. It looks very similar to the ifconfig output in the previous section:
loopback entry: it shows that the local host can be reached by the interface lo0, which is the name for the 255.255.255.0, this entry accounts for all addresses from 223.147.37.0 to 223.147.37.255.ifconfig and the 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 223.147.37.0.
The 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).
ifconfig listing. It specifies how to reach any address not already accounted 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. In the middle of the Internet, things are even more extreme. There may be dozens of interfaces, and the choice of a route for a particular address may be much more complicated. In such an environment, two problems occur:
FreeBSD comes with all the currently available routing software, primarily the daemon . An alternative in the Ports Collection is zebra.
All these daemons have one thing in common: you don't need them. At any rate, you don’t need them until you have at least two different connections to the Internet, and even then it’s not sure. As a result, we won’t discuss them here. If you do need to run routing daemons, read all about them in TCP/IP Network Administration, by Craig Hunt.
From our point of view, however, the
gateway that forwards data for this As we saw in the previous section, the routing software uses only addresses, and not the interface name. To add routes manually, we have to give the same information.
The program that adds routes manually is called route. We need it to add routes to systems other than those to which we are
To set up the freebie, presto, bumble and wait), we could write:
# route add default gw
During system startup, the script /etc/rc.network performs this operation automatically if you set the following variable in /etc/rc.conf:
default router="223.147.37.5" # Set to default gateway (or NO).
Note that we enter the address of the default router as an IP address, not a name. This command is executed before the name server is running. We can’t change the sequence in which we start the processes: depending on where our name server is, we may need to have the route in place to access the name server.
On system gw, the tunO interface:
#default router="139.130.136.129" # Set to default gateway (or NO). gateway enable="YES " # Set to YES if this host will be a gateway.
This is a PPP interface, so you don't need a default router entry; if you did, it would look like the commented-out entry above. Later we'll see how PPP sets the
We need to enable gateway functionality on this system, since it
At the ISP site, things are slightly more complicated than at example.org. Let’s look at the gateway machine free-gw.example.net. It has three connections, to the global Internet, to example.org and to another network, biguser.com (the network serviced by interface pppO). To add the routes requires something like the following commands:
# route add default 139.130.237.65 igw.example.net # route add -net 223.147.37.0 139.130.136.133 gw.example.org # route add -net 223.147.38.0 -iface ppp0 local ppp0 interface
The first line tells the system that the 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 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 pppO.
The procedure to add this information to /etc/rc.conf is similar to what we did for the interface addresses:
The variable static_routes contains a list of the
For each route, a variable corresponding to the route name specified in static_routes, with the text route_ route. It makes sense for them to be related to the domain name, but they don't have to. For example, we would have liked to have called our network freebie.org, but there's a good chance that this name has been taken, so we called it example.org instead. The old name live in the name of the route, route_freebie. In the case of biguser.com, we have called the route variable route_biguser.
We put the following entries into free-gw's /etc/rc.conf:
default router="139.130.237.65" # Set to default gateway (or NO). static_routes="freebie biguser" # list of static routes route_freebie="-net 223.147.37.0 139.130.237.129" route_biguser="-net 223.147.38.0 139.130.237.9"
You can show the netstat tool. Option -r shows the freebie you might see:
# net stat -r Routing tables Internet: Destination Gateway Flags Refs Use Netif Expire default gw UGSc 9 8732 rl0 localhost localhost UH 0 1255 lo0 223.147.37 link#2 UC 0 0 presto 0:0:c0:44:a5:68 UHLW 13 139702 rl0 1151 freebie 0:a0:24:37:d:2b UHLW 3 38698 lo0 wait 0:60:97:40:fb:e1 UHLW 6 1062 rl0 645 bumble 8:0:20:e:2c:98 UHLW 2 47 rl0 1195 gw 0:60:97:40:fb:e1 UHLW 6 1062 rl0 645 broadcast ff:ff:ff:ff:ff:ff UHLWb 2 5788 rl0
There’s 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.
The second column, the gateway, indicates the path to the destination. This field differs significantly even from older versions of UNIX. It can be the name of a host (for example, gw), a pointer to an interface (link#2, which means the second Internet interface; the output from ifconfig is in the same sequence), or an Ethernet address (8:0:20:e:2c:98). Older versions of UNIX do not use the last two forms.
We’ll look at the fags below. The most important ones to note are G (gateway) and H (host).
The fields Refs, Use and Expire are only of interest when you're running a
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
The default entry points to gw, as we would expect. The interface, rl0, is the interface by which gw can be reached.
You will also get some additional output for IPv6 ("Internet "). If you're not using IPv6, you can ignore it. If it gets on your nerves, you can limit your view to IPv4 by entering the command netstat -rfinet. The -f fag specifies which address family you're interested in, and inet specifies IPv4.
Compared to earlier versions of netstat, the current version displays many more fags. The following table gives you an overview.
| Flag | Name | Meaning |
|---|---|---|
| 1 | RTF_PROTO1 | Protocol specific routing flag 1 |
| 2 | RTF_PROTO2 | Protocol specific routing flag 2 |
| 3 | RTF_PROTO3 | Protocol specific routing flag 3 |
| B | RTF_BLACKHOLE | Just discard pkts (during updates) |
| b | RTF_BROADCAST | The route represents a |
| C | RTF_CLONING | Generate new routes on use |
| c | RTF_PRCLONING | Protocol-specified generate new routes on use |
| D | RTF_JDYNAMIC | Created dynamically (by redirect) |
| G | RTF_GATEWAY | Destination requires forwarding by |
| H | RTF_HOST | Host entry (net otherwise) |
| L | RTF_LLINFO | Valid protocol to link address translation |
| M | RTF_MODIFIED | Modified dynamically (by redirect) |
| R | RTF_REJECT | Host or net unreachable |
| S | RTF_STATIC | Manually added |
| U | RTF_UP | Route usable |
| W | RTF_WASCLONED | Route was generated as a result of cloning |
| X | RTF_XRESOLVE | External daemon translates proto to link address |
We saw above that when a system receives packet that is not intended for itself, it looks for a route to the destination. In fact, this is not always the case: by default, FreeBSD just silently drops the packet. This is
The rationale for this is that most systems are only connected to one network, and it doesn't make sense to have packet forwarding enabled. Earlier systems made this a kernel option, so that disabling packet forwarding also made the kernel fractionally smaller. In current versions of FreeBSD, the code is always there, even if it is disabled.
It’s straightforward enough to set up your machine as a router (or gateway): you can set it with the sysctl command:
# sysctl -w net.inet.ip.forwarding=1 net.inet.ip.forwarding: 0 -> 1
In /etc/rc.conf you can set this with the variable gateway_enable:
gateway_enable="YES " # Set to YES if this host will be a gateway.
In the course of this chapter, we've discussed a number of different configurations. In this section we'll free-gw.example.net, since it is the most complicated. You enter the following information in your /etc/rc.conf:
hostname="free-gw.exarrple. net "
ifconfig_rl0="inet 139.130.237.117"
The PPP interfaces are configured independently,so we won't look at them here, but we might need their addresses for 139.130.136.9, and the 139.130.136.129.
igw.example.net, with the address 139.130.237.65
defaultrouter="139.130.237.65" # Set to default gateway (or NO).
example.org and biguser.com. List them in the variable static_routes:
static_routes="freebie biguser" # Set to static route list
route_freebie="-net 223.147.37.0 139.130.136.133" route_biguser="-net 223.147.38.0 -iface ppp0"
gateway enable="YES " # Set to YES if this host will be a gateway.
Without the comments, this gives the following entries:
hostname="free-gw.example.net" ifconfig_rl0="inet 139.130.237.117" default router="139.130.237.65" # Set to default gateway (or NO). static_routes="freebie biguser" # Set to static route list route_freebie="-net 223.147.37.0 139.130.136.133" route_biguser="-net 223.147.38.0 -iface ppp0" gateway enable="YES " # Set to YES if this host will be a gateway.
For machine configured with DHCP, you might have:
hostname="andante.example.net" ifconfig_wi0=DHCP
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 they require 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’s the easiest to set up. After that, we’ll look at what additional information is needed to configure machines on example.net.
To configure a network, you must describe its configuration to the system. The system 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
(рис 17.1) Network setup menu
Choose the Ethernet board, xl0 You get a question about whether you want to use IPv6 configuration. In this book we doesn’t d discuss IPv6, so answer No. Next you 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
(рис 17.2) Network configuration menu
Specify the fully qualified local host name. When you tab to the Domain: field, the domain is filled in automatically. We have chosen to call this machine presto, and the domain is example.org. In other words, the full name of the machine is presto.example.org. Its IP address is 223.147.37.2. In this 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. If the name server isn’t running when this information is needed, we must specify all addresses in numeric form, as shown.
What happens if you don’t have a domain name? If you’re connecting to the global Internet, you should go out and get one-see page 318. But in the meantime, don’t fake it. Just leave the fields empty. If you’re not connecting to the Internet, of course, it doesn’t make much difference what name you choose.
As is usual for a class C network, the net mask is 255.255.255.0. You don’t need to fill in this information—if you leave this field without filling it in, sysinstall inserts it for you. Normally, as in this case, you wouldn’t need any additional options to ifconfig
sysinstall saves configuration 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. In the next section we’ll look at the commands it uses to perform this function.
Usually FreeBSD configures your network automatically when it boots. To do so, it uses the configuration files in/etc. So why do it manually? There are several reasons:
In this section, we’ll look at the manual way to do things first, and then we’ll see how to put it in the configuration files so that it gets done automatically next time. You can find a summary of the configuration files and their contents on page 551.
We saw that 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 even more 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, network mask.
Once we have understood these concepts, it’s relatively simple to use the ifconfig program to set them. For example, for the Ethernet interface on system gw, with IP address 223.147.37.5, we need to configure interface . The 255.255.255.0. That’sall we need to know:
# ifconfig dc0 inet 223.147.37.5 net mask 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
# ifconfig dc0 223.147.37.5
Note that this is different from what Linux requires. With Linux you must supply explicit net mask and
As we saw on page 290, it has become typical to / followed by the number of 1 bits set in the 255.255.255.240, which has 28 bits set, you could write:
# ifconfig dc0 223.147.37.5/28
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 255.255.255.255. With this information, we could configure the PPP interface on gw:
# ifconfig tun0 139.130.136.133 139.130.136.129 net mask 255.255.255.255
In fact, this is almost never necessary; in Chapter 20 we’ll see that the PPP software usually sets the configuration automatically.
The IP protocols require you to use an address to communicate with every system—even your own system. . Its name is lo0, and it has the address 127.0.0.1. It’s straightforward enough to configure:
# ifconfig lo0 127.0.0.1
In fact, though, you don’t even need to do this much work: the system automatically sets it up at
ifconfig doesn’t just set the configuration: you can also use it to check the configuration. It’s a good idea to do this after you change something:
$ ifconfig
dc0: flags=8843< UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST > mtu 1500
inet 223.147.37.5 net mask 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 net mask 0xff000000
tun0: flags=8051<UP, POINTOPOINT, RUNNING, MULTICAST > mtu 1500
inet 139.130.136.133 -- > 139.130.136.129 net mask 0xffffffff
ifconfig -a. to list the configuration of all interfaces, and FreeBSD still accepts it. Some commercial UNIX systems don’t understand even this fag.
There are a number of things to note here:
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 The system startup scripts
hostname is the name of the host. You should have set it when you installed the system (see page 87). You can also set it manually with the hostname command:
# hostname -s gw.example.org
Previously, FreeBSD also required you to set a variable network_interfaces, a list of the names of the interfaces to be configured. This variable now defaults to the value auto to specify that all interfaces should be configured. You only need to change it if you specifically want to exclude an interface from configuration.
For gw, we put the following information in /etc/rc.conf:
hostname=‘gw.example.org’ ifconfig_dc0=‘inet 223.147.37.5’
We don’t configure the tunO interface here; as we’ll see in Chapter 20, the PPP setup works differently.
Maintaining the DHCP, the Dynamic Host Configuration Protocol. DHCP enables a machine to get configuration information automatically from the network. The concept is expandable, but typically 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 two parts to DHCP: the client and the server.
To get a configuration, you run dhclient. In previous 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 ifconfig_dc0 variable:
ifconfig_dc0=DHCP
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's an example:
ddns-update-style ad-hoc;
# 100 Mb/s Ethernet
subnet 223.147.37.0 net mask 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:
223.147.37.90 to 223.147.37.110 (range keyword).The variables default-lease-time and max-lease-time, which are specified in seconds, determine how long it will be before a system checks its configuration. The values here represent one day and three days respectively.
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 specification for every system. For one machine it doesn’t makemuch 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’t allocate a static IP address. 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 dhcpd recognizes the network interface, not the machine, and if you swap the
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
# /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
We've looked at ifconfig works with
On inserting a
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:
/etc/defaults/rc.conf and /etc/rc.conf.removable interfaces exists and contains the name of the interface, xl0. If not, it continues.ifconfig_xl0 is NO, it exits.DHCP, it attempts to set up the interface with DHCP.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 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 /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
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, of course, but it’s good to put in every interface name that you would possibly use.
When you remove a devd invokes /etc/pccard_ether again. The actions are similar to the one it performs when the card is attached:
ifconfig_xl0 is set to DHCP, /etc/pccard_ether stops the dhclient process, which would otherwise loop forever.ifconfig_xl0 contains normal ifconfig parameters, /etc/pccard_ether removes any If you travel elsewhere with a
We saw in Chapter 16 that wireless cards have a few more tricks up their
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 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
devd_enable=YES ifconfig_wi0="192.168.27.4 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
ifconfig_wi0="192.168.27.4 ssid Example media autoselect media opt ibss-master channel 3 wepmode off"
At this point, we have configured the
Looking back at our example network on page 294, we'll reconsider a problem we
| Destination | Gateway | Net mask | Type | Interface |
|---|---|---|---|---|
| 127.0.0.1 | 127.0.0.1 | 255.0.0.0 | Host | lo0 |
| 223.147.37. | 255.255.255.0 | Direct | dc0 | |
| 139.130.136.129 | 139.130.136.133 | 255.255.255.255 | Host | tun0 |
| Default | 139.130.136.129 | 0.0.0.0 | Gateway | tun0 |
These decisions are the basis of routing. The implementation 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 gv.example.org. It looks very similar to the ifconfig output in the previous section:
loopback entry: it shows that the local host can be reached by the interface lo0, which is the name for the 255.255.255.0, this entry accounts for all addresses from 223.147.37.0 to 223.147.37.255.ifconfig and the 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 223.147.37.0.
The 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).
ifconfig listing. It specifies how to reach any address not already accounted 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. In the middle of the Internet, things are even more extreme. There may be dozens of interfaces, and the choice of a route for a particular address may be much more complicated. In such an environment, two problems occur:
FreeBSD comes with all the currently available routing software, primarily the daemon . An alternative in the Ports Collection is zebra.
All these daemons have one thing in common: you don't need them. At any rate, you don’t need them until you have at least two different connections to the Internet, and even then it’s not sure. As a result, we won’t discuss them here. If you do need to run routing daemons, read all about them in TCP/IP Network Administration, by Craig Hunt.
From our point of view, however, the
gateway that forwards data for this As we saw in the previous section, the routing software uses only addresses, and not the interface name. To add routes manually, we have to give the same information.
The program that adds routes manually is called route. We need it to add routes to systems other than those to which we are
To set up the freebie, presto, bumble and wait), we could write:
# route add default gw
During system startup, the script /etc/rc.network performs this operation automatically if you set the following variable in /etc/rc.conf:
default router="223.147.37.5" # Set to default gateway (or NO).
Note that we enter the address of the default router as an IP address, not a name. This command is executed before the name server is running. We can’t change the sequence in which we start the processes: depending on where our name server is, we may need to have the route in place to access the name server.
On system gw, the tunO interface:
#default router="139.130.136.129" # Set to default gateway (or NO). gateway enable="YES " # Set to YES if this host will be a gateway.
This is a PPP interface, so you don't need a default router entry; if you did, it would look like the commented-out entry above. Later we'll see how PPP sets the
We need to enable gateway functionality on this system, since it
At the ISP site, things are slightly more complicated than at example.org. Let’s look at the gateway machine free-gw.example.net. It has three connections, to the global Internet, to example.org and to another network, biguser.com (the network serviced by interface pppO). To add the routes requires something like the following commands:
# route add default 139.130.237.65 igw.example.net # route add -net 223.147.37.0 139.130.136.133 gw.example.org # route add -net 223.147.38.0 -iface ppp0 local ppp0 interface
The first line tells the system that the 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 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 pppO.
The procedure to add this information to /etc/rc.conf is similar to what we did for the interface addresses:
The variable static_routes contains a list of the
For each route, a variable corresponding to the route name specified in static_routes, with the text route_ route. It makes sense for them to be related to the domain name, but they don't have to. For example, we would have liked to have called our network freebie.org, but there's a good chance that this name has been taken, so we called it example.org instead. The old name live in the name of the route, route_freebie. In the case of biguser.com, we have called the route variable route_biguser.
We put the following entries into free-gw's /etc/rc.conf:
default router="139.130.237.65" # Set to default gateway (or NO). static_routes="freebie biguser" # list of static routes route_freebie="-net 223.147.37.0 139.130.237.129" route_biguser="-net 223.147.38.0 139.130.237.9"
You can show the netstat tool. Option -r shows the freebie you might see:
# net stat -r Routing tables Internet: Destination Gateway Flags Refs Use Netif Expire default gw UGSc 9 8732 rl0 localhost localhost UH 0 1255 lo0 223.147.37 link#2 UC 0 0 presto 0:0:c0:44:a5:68 UHLW 13 139702 rl0 1151 freebie 0:a0:24:37:d:2b UHLW 3 38698 lo0 wait 0:60:97:40:fb:e1 UHLW 6 1062 rl0 645 bumble 8:0:20:e:2c:98 UHLW 2 47 rl0 1195 gw 0:60:97:40:fb:e1 UHLW 6 1062 rl0 645 broadcast ff:ff:ff:ff:ff:ff UHLWb 2 5788 rl0
There’s 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.
The second column, the gateway, indicates the path to the destination. This field differs significantly even from older versions of UNIX. It can be the name of a host (for example, gw), a pointer to an interface (link#2, which means the second Internet interface; the output from ifconfig is in the same sequence), or an Ethernet address (8:0:20:e:2c:98). Older versions of UNIX do not use the last two forms.
We’ll look at the fags below. The most important ones to note are G (gateway) and H (host).
The fields Refs, Use and Expire are only of interest when you're running a
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
The default entry points to gw, as we would expect. The interface, rl0, is the interface by which gw can be reached.
You will also get some additional output for IPv6 ("Internet "). If you're not using IPv6, you can ignore it. If it gets on your nerves, you can limit your view to IPv4 by entering the command netstat -rfinet. The -f fag specifies which address family you're interested in, and inet specifies IPv4.
Compared to earlier versions of netstat, the current version displays many more fags. The following table gives you an overview.
| Flag | Name | Meaning |
|---|---|---|
| 1 | RTF_PROTO1 | Protocol specific routing flag 1 |
| 2 | RTF_PROTO2 | Protocol specific routing flag 2 |
| 3 | RTF_PROTO3 | Protocol specific routing flag 3 |
| B | RTF_BLACKHOLE | Just discard pkts (during updates) |
| b | RTF_BROADCAST | The route represents a |
| C | RTF_CLONING | Generate new routes on use |
| c | RTF_PRCLONING | Protocol-specified generate new routes on use |
| D | RTF_JDYNAMIC | Created dynamically (by redirect) |
| G | RTF_GATEWAY | Destination requires forwarding by |
| H | RTF_HOST | Host entry (net otherwise) |
| L | RTF_LLINFO | Valid protocol to link address translation |
| M | RTF_MODIFIED | Modified dynamically (by redirect) |
| R | RTF_REJECT | Host or net unreachable |
| S | RTF_STATIC | Manually added |
| U | RTF_UP | Route usable |
| W | RTF_WASCLONED | Route was generated as a result of cloning |
| X | RTF_XRESOLVE | External daemon translates proto to link address |
We saw above that when a system receives packet that is not intended for itself, it looks for a route to the destination. In fact, this is not always the case: by default, FreeBSD just silently drops the packet. This is
The rationale for this is that most systems are only connected to one network, and it doesn't make sense to have packet forwarding enabled. Earlier systems made this a kernel option, so that disabling packet forwarding also made the kernel fractionally smaller. In current versions of FreeBSD, the code is always there, even if it is disabled.
It’s straightforward enough to set up your machine as a router (or gateway): you can set it with the sysctl command:
# sysctl -w net.inet.ip.forwarding=1 net.inet.ip.forwarding: 0 -> 1
In /etc/rc.conf you can set this with the variable gateway_enable:
gateway_enable="YES " # Set to YES if this host will be a gateway.
In the course of this chapter, we've discussed a number of different configurations. In this section we'll free-gw.example.net, since it is the most complicated. You enter the following information in your /etc/rc.conf:
hostname="free-gw.exarrple. net "
ifconfig_rl0="inet 139.130.237.117"
The PPP interfaces are configured independently,so we won't look at them here, but we might need their addresses for 139.130.136.9, and the 139.130.136.129.
igw.example.net, with the address 139.130.237.65
defaultrouter="139.130.237.65" # Set to default gateway (or NO).
example.org and biguser.com. List them in the variable static_routes:
static_routes="freebie biguser" # Set to static route list
route_freebie="-net 223.147.37.0 139.130.136.133" route_biguser="-net 223.147.38.0 -iface ppp0"
gateway enable="YES " # Set to YES if this host will be a gateway.
Without the comments, this gives the following entries:
hostname="free-gw.example.net" ifconfig_rl0="inet 139.130.237.117" default router="139.130.237.65" # Set to default gateway (or NO). static_routes="freebie biguser" # Set to static route list route_freebie="-net 223.147.37.0 139.130.136.133" route_biguser="-net 223.147.38.0 -iface ppp0" gateway enable="YES " # Set to YES if this host will be a gateway.
For machine configured with DHCP, you might have:
hostname="andante.example.net" ifconfig_wi0=DHCP
Для получения официальных документов о завершении программы дополнительного профессионального образования (удостоверения о повышении квалификации, дипломов о профессиональной переподготовке и MBA) необходимо предоставить:
Внимание! Вы можете не заказывать доставку бумажной версии официального документы, а скачать его в электронном виде и распечатать самостоятельно. Информация о выданном документе в течение 1 месяца загружается в Федеральную информационную систему «Федеральный реестр сведений о документах об образовании и (или) о квалификации, документах об обучении» - ФИС ФРДО.
Доступ на новый сайт осуществляется с использованием адреса электронной почты, который был указан вами при регистрации на "старом". Мы постарались перенести все ваши данные с прежнего ресурса, однако не исключена вероятность потери части информации.
При возникновении проблемы со входом, воспользуйтесь функцией сброса пароля
Если вы обнаружите несоответствия, пожалуйста, сообщите нам.