Выбрать главу

The default route can be removed and added back in, pointing to a different gateway/router:

# route delete default

# route add default gw 172.16.97.253

# route

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

172.16.97.0 * 255.255.255.0 U 0 0 0 eth0

default 172.16.97.253 0.0.0.0 UG 0 0 0 eth0

When the wlan0 interface is configured, a new route is added for hosts directly accessible through that interface:

# ifconfig wlan0 192.168.9.37

# route

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

172.16.97.0 * 255.255.255.0 U 0 0 0 eth0

192.168.9.0 * 255.255.255.0 U 0 0 0 wlan0

default 172.16.97.253 0.0.0.0 UG 0 0 0 eth0

If other networks are available through additional gateways, these can be configured by using route with the -net and netmask arguments. For example, if your corporate network 10.x.x.x in London were accessible through the gateway 192.168.9.1 on your wireless network, you could configure the route with this command:

# route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.9.1

# route

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

172.16.97.0 * 255.255.255.0 U 0 0 0 eth0

192.168.9.0 * 255.255.255.0 U 0 0 0 wlan0

10.0.0.0 192.168.9.1 255.0.0.0 UG 0 0 0 wlan0

default 172.16.97.253 0.0.0.0 UG 0 0 0 eth0

3.2.1.3.3. DNS and hostnames

DNS resolution is controlled by the file /etc/resolv.conf , which looks something like this:

search fedorabook.com oreilly.com

nameserver 127.0.0.1

nameserver 216.183.93.224

There are three common option keywords used in this file:

search

A space- or tab-delimited list of domains to be searched when attempting to resolve a hostname without a domain component. In this example, if the DNS resolver were given the hostname bluesky , it would attempt to resolve the hostname bluesky.fedorabook.com , and if that failed, it would attempt to resolve bluesky.oreilly.com . There is a limit of six domains in the search list.

domain

A rarely used alternative to search that can specify only one domain. The domain and search options are mutually exclusive and cannot be used at the same time.

nameserver

The IP address of a nameserver available to resolve DNS queries. Listing multiple nameservers provides redundancy in case one of the servers is unavailable. In this example, the address for localhost (this computer) is given first, with a second nameserver entry providing the IP address of a remote nameserver as backup.

If the DNS settings are configured by DHCP, this file is overwritten automatically with the values provided by the DNS server. In that case, an additional comment line will appear at the top of the file:

; generated by /sbin/dhclient-script

To change the DNS configuration, simply edit this file with a text editor, adding or removing domains in the search line or adding or removing nameserver lines as necessary.

The /etc/hosts file contains a list of IP and hostname mappings. As initially set up by Anaconda (the Fedora installation system), the file will look like this:

# Do not remove the following line, or various programs

# that require network functionality will fail.

::1 bluesky.fedorabook.com localhost

The one entry in this file associates the system's name and the localhost alias with the loopback device (which may be expressed as ::1 in IPv6 notation, or 127.0.0.1 in IPv4 notation). This entry must exist in the file, or many system services will fail to operate.

You can add additional entries to /etc/hosts if you want to refer to local computers by name but don't want to go through the effort of setting up DNS (see Lab 7.3, "Configuring a Domain Name Server"). Simply place the IP address at the start of the line and then list the names and aliases for that host, separated by spaces or tabs:

# Do not remove the following line, or various programs

# that require network functionality will fail.

::1 bluesky.fedorabook.com localhost

172.16.97.60 darkday.fedorabook.com darkday frank

172.16.97.73 accounting.fedorabook.com accounting susan

172.16.97.207 samba.fedorabook.com

To change the system's hostname, edit the /etc/hosts file and change the entry for the loopback line (do not remove the localhost alias):

# Do not remove the following line, or various programs

# that require network functionality will fail.

::1 beige.fedorabook.com localhost

Then edit the HOSTNAME entry in /etc/sysconfig/network :

NETWORKING=yes

NETWORKING_IPV6=yes

HOSTNAME=beige.fedorabook.com

The change will take effect next time you boot. To make the change take effect immediately, use the hostname command:

# hostname beige.fedorabook.com

# hostname

beige.fedorabook.com

3.2.1.3.4. Configuring networking from the command line using DHCP

Fedora Core provides the dhclient program to configure network interfaces based on information received from Dynamic Host Configuration Protocol (DHCP) servers. Simply run this program as root , specifying the interface(s) that you wish to configure:

# dhclient wlan0

# ifconfig wlan0

wlan0 Link encap:Ethernet HWaddr 00:0C:2D:00:2B:DB

         inet addr:10.144.12.160 Bcast:10.144.255.255 Mask:255.255.0.0

         inet6 addr: fe80::20c:2dff:fe00:2bdb/64 Scope:Link

         UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1