Read LPI Linux Certification in a Nutshell Online
Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger
Tags: #Reference:Computers
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.
ifconfig
ifconfiginterface parameters
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. Ifinterface
is also
omitted, a list of all active interfaces and their configurations
is displayed.
address
The interface’s IP address.
netmask
mask
The interface’s subnet mask.
up
Activate an interface (implied ifaddress
is specified).
down
Shut down the interface.
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
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 theUP
indicator, which is present in
Example 1. The missingUP
indicates that the interface is down.
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.
ping
ping [options
]destination
Send an ICMPECHO_REQUEST
datagram todestination
, expecting an ICMPECHO_RESPONSE
.
ping
is frequently used to test basic network connectivity. See
Chapter 19
for a more
complete description.
route
route [options
]
route add [options and keywords
]target
route del [options and keywords
]target
In the first form, display the IP routing table. In
the second and third forms, respectively, add or delete routes totarget
from the table.target
can be a numeric IP address, a
resolvable name, or the keyworddefault
. 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.
Display a usage message.
Numeric mode; don’t resolve hostnames.
Verbose output.
Display the kernel routing cache.
Display the kernel routing table (the default behavior
without
add
or
delete
keywords).
Specify thattarget
is a
single host. Mutually exclusive with
-net
.
Specify thattarget
is a
network. Mutually exclusive with
-host
.
gateway
IP packets fortarget
are
routed through the gateway, which must be reachable.
mask
Specify themask
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 thetarget
address.
When used to display routes, the following routing table
columns are printed:
The destination network or host.
The gateway address. If no gateway is set for
the route, an asterisk (*
) is displayed by default.
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.
!
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.
The distance in hops to the target.
Number of references to this route. This is displayed
for compatibility with other route commands, but is not used
in the Linux kernel.
A count of lookups for the route. Depending on the use
of
-F
and
-C
, theUse
is either route cache
misses (
-F
) or hits
(
-C
).
The interface to which packets for this route
are sent.
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.
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
Add the default gateway 192.168.1.1 via
eth0
:
#route add default gw 192.168.1.1 eth0
dhcpd
dhcpd [options
] [interface
[...]]
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.
config-file
Useconfig-file
instead of
the default
/etc/dhcpd.conf
.
lease-file
Uselease-file
instead of
the default to store lease information.
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.