LPI Linux Certification in a Nutshell (61 page)

Read LPI Linux Certification in a Nutshell Online

Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger

Tags: #Reference:Computers

BOOK: LPI Linux Certification in a Nutshell
7.33Mb size Format: txt, pdf, ePub
A Standard Linux Network Configuration

A very common setup for a Linux system is to have a single
Ethernet interface and be a member of a network, as either a client, a
server, or both. Here are the network settings that must be configured
in order for a Linux system to communicate via TCP/IP over an Ethernet
network:

  • A compatible Ethernet card must be installed and recognized by
    the kernel. See information about the commands
    lsmod,
    lspci
    , and
    dmesg
    in previous
    chapters for more information about hardware troubleshooting.

  • An IP address and subnet mask must be assigned to the Ethernet
    interface (
    eth0
    ). These can be assigned
    manually (static values saved in a configuration file) or assigned
    from a DHCP server on the local subnet. On RPM-based systems such as
    CentOS, Red Hat, and Fedora Linux, the network configuration file is
    /etc/sysconfig/network-scripts/ifcfg-eth0
    .
    Values from this file are read by the startup script
    /etc/init.d/network
    , which in turn calls the
    command
    ifconfig
    with the appropriate
    values.

  • In order to communicate with other subnets, a default gateway
    route must be configured. This is the IP address of the device on
    the local network that will send your packets on to other networks.
    This may be a dedicated device, such as a router, or it may be a
    general-purpose computer (with multiple Ethernet cards) running
    routing software. A lower-end PC running Linux is often a good
    choice for a router in this instance. The default gateway route is
    defined in the file
    /etc/sysconfig/network.
    This value is read by the startup script
    /etc/init.d/network
    , which in turn calls the
    route
    command to set this as the default
    gateway route.

  • Finally, a default nameserver should be configured so
    applications can successfully resolve hostnames to IP addresses. As
    stated previously, this is defined in the file
    /etc/resolv.conf
    .

If all of these settings are in place, your Linux system should be
able to communicate successfully with other computers over a TCP/IP
network.

Name

ifconfig

Syntax
ifconfig
interface parameters
Description

Configure network interfaces.
ifconfig
is used to create and configure
network interfaces and their parameters, usually at boot time.
Without parameters, the interface and its configuration are
displayed. If
interface
is also
omitted, a list of all active interfaces and their configurations
is displayed.

Frequently used parameters
address

The interface’s IP address.

netmask
mask

The interface’s subnet mask.

up

Activate an interface (implied if
address
is specified).

down

Shut down the interface.

Example 1

Display all interfaces:

#
ifconfig
eth0 Link encap:Ethernet HWaddr 00:A0:24:D3:C7:21
inet addr:192.168.1.30 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1521805 errors:37 dropped:0 overruns:0 frame:37
TX packets:715468 errors:0 dropped:0 overruns:0 carrier:0
collisions:1955 txqueuelen:100
Interrupt:10 Base address:0xef00
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:3924 Metric:1
RX packets:366567 errors:0 dropped:0 overruns:0 frame:0
TX packets:366567 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
Example 2

Shut down
eth0
:

#
ifconfig eth0 down
#
ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:A0:24:D3:C7:21
inet addr:192.168.1.30 Bcast:192.168.1.255 Mask:255.255.255.0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:1521901 errors:37 dropped:0 overruns:0 frame:37
TX packets:715476 errors:0 dropped:0 overruns:0 carrier:0
collisions:1955 txqueuelen:100
Interrupt:10 Base address:0xef00

Note in the emphasized line the lack of the
UP
indicator, which is present in
Example 1. The missing
UP
indicates that the interface is down.

Example 3

Configure
eth0
from scratch:

#
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.25

Although this is a perfectly valid command, network
interfaces on Linux are rarely configured directly this way from
the command line. It is much more common to store the network
configuration options in a configuration file (often in the
directory
/etc/sysconfig/network-scripts
) and
use a script file in
/etc/init.d
to control
the network interfaces. For example, on RPM-based systems such as
CentOS, RedHat, or Fedora Linux, the configuration settings for
eth0
are stored in
/etc/sysconfig/network-scripts/ifcfg-eth0
and
the status of the network interfaces is changed by calling the
script
/etc/init.d/network
. The command
ifconfig
is most often used with no arguments
to list information about the available network interfaces.
However, it is useful to know this syntax, especially when you’re
working with different Linux distributions that store network
configurations in different places.

Name

ping

Syntax
ping [
options
]
destination
Description

Send an ICMP
ECHO_REQUEST
datagram to
destination
, expecting an ICMP
ECHO_RESPONSE
.
ping
is frequently used to test basic network connectivity. See
Chapter 19
for a more
complete description.

Name

route

Syntax
route [
options
]
route add [
options and keywords
]
target
route del [
options and keywords
]
target
Description

In the first form, display the IP routing table. In
the second and third forms, respectively, add or delete routes to
target
from the table.
target
can be a numeric IP address, a
resolvable name, or the keyword
default
. The
route
program is typically used to establish static routes to specific
networks or hosts (such as the default gateway) after an interface
is configured. On systems acting as routers, a potentially complex
routing scheme can be established initially, but this is beyond
the scope of the LPIC Level 1 Exams.

Frequently used options and keywords
-h

Display a usage message.

-n

Numeric mode; don’t resolve hostnames.

-v

Verbose output.

-C

Display the kernel routing cache.

-F

Display the kernel routing table (the default behavior
without
add
or
delete
keywords).

-host

Specify that
target
is a
single host. Mutually exclusive with
-net
.

-net

Specify that
target
is a
network. Mutually exclusive with
-host
.

gw
gateway

IP packets for
target
are
routed through the gateway, which must be reachable.

netmask
mask

Specify the
mask
of
the route to be added. Often, the netmask is not required,
because it can be determined to be class A, B, or C,
depending on the
target
address.

When used to display routes, the following routing table
columns are printed:

Destination

The destination network or host.

Gateway

The gateway address. If no gateway is set for
the route, an asterisk (
*
) is displayed by default.

Genmask

The netmask for the destination.
255.255.255.255 is used for a host, and 0.0.0.0 is used for
the default route.

Route status flags
!
Reject route.
D
Dynamically installed by daemon or redirect.
G
Use gateway.
H
Target is a host.
M
Modified from routing daemon or redirect.
R
Reinstate route for dynamic routing.
U
Route is up.
Metric

The distance in hops to the target.

Ref

Number of references to this route. This is displayed
for compatibility with other route commands, but is not used
in the Linux kernel.

Use

A count of lookups for the route. Depending on the use
of
-F
and
-C
, the
Use
is either route cache
misses (
-F
) or hits
(
-C
).

Iface

The interface to which packets for this route
are sent.

Example 1

Display the current routing table for a workstation:

#
route
Kernel IP routing table
Destination Gateway Genmask Flags Met Ref Use Iface
192.168.1.30 * 255.255.255.255 UH 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
10.0.0.0 - 255.0.0.0 ! 0 - 0 -
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
default gate 0.0.0.0 UG 0 0 0 eth0

In this example, the route to the local host 192.168.1.30
uses interface
eth0
. Note the mask
255.255.255.255 is used for host routes. The route to the local
subnet 192.168.1.0 (with corresponding class C mask 255.255.255.0)
is also through
eth0
. The route to 10.0.0.0
is rejected, as indicated by the
!
flag. The class A loopback network
route uses device
lo
. The last route shows
the
default gateway
route, which is
used when no others match. This default uses
eth0
to send data to router
gate
. The mask 0.0.0.0 is used for the
default route.

Example 2

Display the current routing cache; the Metric (
M
) and Reference (
R
) columns are abbreviated here:

#
route -C
Kernel IP routing cache
Source Destination Gateway Flg M R Use Iface
smp 192.168.1.255 192.168.1.255 bl 0 0 1 eth0
192.168.1.102 192.168.1.255 192.168.1.255 ibl 0 0 0 lo
192.168.1.102 smp smp il 0 0 1 lo
192.168.1.50 smp smp il 0 0 224 lo
smp 192.168.1.102 192.168.1.102 0 1 0 eth0
smp ns1.mynet.com gate 0 0 2 eth0
smp 192.168.1.50 192.168.1.50 0 1 0 eth0
localhost localhost localhost l 0 0 15 lo
ns1.mynet.com smp smp l 0 0 6 lo
smp ns1.mynet.com gate 0 0 6 eth0
Example 3

Add the default gateway 192.168.1.1 via
eth0
:

#
route add default gw 192.168.1.1 eth0
Name

dhcpd

Syntax
dhcpd [
options
] [
interface
[...]]
Description

Launch the
DHCP server daemon.
dhcpd
requires that both its configuration file
(
/etc/dhcpd.conf
) and its lease logfile
(which by default is
/var/state/dhcp/dhcpd.leases
, although many
distributions use
/var/lib/dhcp/dhcpd.leases
)
exist. The daemon puts itself in the background and returns
control to the calling shell.

Frequently used options
-cf
config-file

Use
config-file
instead of
the default
/etc/dhcpd.conf
.

-lf
lease-file

Use
lease-file
instead of
the default to store lease information.

-q

Use quiet mode. This option suppresses the default
copyright message, keeping logfiles a little cleaner.

interface

By default,
dhcpd
will attempt to
listen for requests on every network interface that is
configured up. It can be limited to specific network
interfaces by including one or more interface names on the
command line.

A full and detailed description of the configuration file
syntax can be found in the
dhcpd.conf
manpage. When
dhcpd
runs, it sends output,
including information on each transaction, to
syslogd
. For example, this series of four log
entries in
/var/log/messages
shows a
successful exchange between
dhcpd
and a
requesting DHCP client:

Apr 24 02:27:00 rh62 dhcpd: DHCPDISCOVER
from 00:60:97:93:f6:8a via eth0
Apr 24 02:27:00 rh62 dhcpd: DHCPOFFER
on 192.168.1.200 to 00:60:97:93:f6:8a via eth0
Apr 24 02:27:01 rh62 dhcpd: DHCPREQUEST
for 192.168.1.200 from 00:60:97:93:f6:8a via eth0
Apr 24 02:27:01 rh62 dhcpd: DHCPACK
on 192.168.1.200 to 00:60:97:93:f6:8a via eth0

On the Exam

For the LPI Level 1 Exams, you should be familiar with
both the manual and automatic network interface configuration,
and how interfaces can be started, stopped, and
configured.

Other books

Atonement of Blood by Peter Tremayne
Falling to Pieces by Jamie Canosa
Breaking Out by Gayle Parness
A Voice in the Night by Andrea Camilleri
Riverbreeze: Part 1 by Ellen E. Johnson
The Zombie Gang #2 by Tilley, Justin, Mcnair, Mike
Surrender to Temptation by Walters, Ednah