LinuxAdministration
LinuxAdministration
administration
PID_00290379
The assignment and creation of this UOC Learning Resource have been coordinated
by the lecturer: Josep Jorba Esteve
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and
no Back-Cover Texts. The terms of the license can be consulted in http://www.gnu.org/licenses/fdl-1.3.html.
GNUFDL • PID_00290379 Linux administration
Contents
Introduction............................................................................................... 7
Objectives..................................................................................................... 8
3. System status....................................................................................... 31
3.1. Booting the system ..................................................................... 31
3.2. /proc directory .............................................................................. 32
3.3. Kernel: /sys directory ................................................................... 33
3.4. Udev: /dev device management .................................................. 34
3.5. Processes ...................................................................................... 36
3.6. System logs .................................................................................. 37
3.7. Memory ....................................................................................... 39
3.8. Disks ............................................................................................ 40
4. Energy management......................................................................... 44
5. File system............................................................................................ 45
5.1. Mount points .............................................................................. 46
7. Print servers........................................................................................ 53
7.1. CUPS ............................................................................................ 53
Activities...................................................................................................... 137
Bibliography............................................................................................... 138
GNUFDL • PID_00290379 7 Linux administration
Introduction
One of the first tasks the administrator will have to deal with will be the
management of the local resources present in the system to be managed.
This module will cover some of these basic administration tasks, concerning
network and disks, and security and services.
This will be done by getting an overview of the current state of the system
using the different procedures and commands that the administrator can use
to evaluate the different parts of the system. This will allow administrative
decisions to be made if performance failures, gaps or lack of resources are
detected.
Finally, the main issues related to security will be analyzed and aspects of both
local and network security will be seen, and it will end with the deployment of
services (web and proxies) to analyze the potential of the GNU/Linux systems
in these aspects.
GNUFDL • PID_00290379 8 Linux administration
Objectives
Most�important�concepts:
• Network administration
• Local security
The GNU/Linux system administrator has to deal with a large number of tasks
on a daily basis. In general, in the *Nix (Unix/Linux) philosophy, there is not
usually a single tool for each task or a single way of doing things, and it is
common for *Nix systems to provide numerous more or less simple tools to
deal with the different tasks.
Below we will analyze a set of tools that are essential for keeping the system
up to date, which are the package management tools. The software provided
by each GNU/Linux distribution, or subsequently incorporated, is organized
into units called packages, which include the files of a given software, plus
the steps necessary for installation preparation (dependencies), subsequent
configuration, or, if applicable, the upgrade or uninstallation of a given
package. Each distribution has a different strategy (depending on the branch
from which they are derived) and usually consists of a management software
GNUFDL • PID_00290379 10 Linux administration
In any distribution, packages are the basic element for new software
installation, upgrade, or removal of unused software.
In the content of the distribution (ISO images), the packages are usually
grouped by categories such as:
e)�Other�categories.
GNUFDL • PID_00290379 11 Linux administration
These should not be confused with the groupings that are made of the
repositories since these are usually more specific, such as Debian, which
establishes the following categories (only some of them): Administration
Utilities, Databases, Development, Documentation, Editors, Education,
Gnome, GNU R, Graphics, Networks, Web Servers, JavaScript, Kernels, etc.
2)� Installation: unpacking the content and copying the files to their final
locations, either absolute (they will have a fixed position) or, if allowed,
relocated to other directories.
Depending on the types of packages, these steps are usually mostly automatic
(this is the case for RPM and DEB). A set of steps may also need to be done
manually (such as for TGZ packages), depending on the tools the distribution
provides.
Next, two of the most classic packages will be discussed; each distribution
typically has one as standard but generally includes utilities to work with the
other common formats. A description will also be made of a series of proposals
for “universal” packaging systems that can be used generically by more than
one distribution.
Table 1
rpm -i http://remote_site/directory/package.rpm
will allow us to download the package from the URL/directory website (or ftp) and
proceed with the package installation.
• Deletion: erase the package from the RPM system (-e or --erase). If there
are dependencies, they may need to be removed first.
GNUFDL • PID_00290379 13 Linux administration
Care should be taken about the source of the packages, and only use known
and reliable package sources, either from the distribution developer itself, or
from trusted and community-recognized sites. A digital “signature” of these is
usually offered with the packages so that they can be verified for authenticity;
Hash md5, sha128/256/512 functions are often used to verify that the package
has not been altered, and other systems, such as GPG (Gnu version of PGP),
to verify the authenticity of the package developer. There are also different
generic RPM package repositories on the Internet, where they are available
for different distributions that use or allow the RPM format or RPM package
browsers, such as https://www.rpmfind.net/.
For secure package use, repositories digitally sign packages (e.g., with the
above-mentioned GPG). This allows ensuring (if signatures are available) that
the packages come from the reliable source since each supplier (repository)
includes PGP signature files with the key for their site. Normally for the official
repositories of the distribution they are already installed, but there are no
third-party signatures that must be installed with a file downloaded from the
developer. To do this, we must execute: rpm --import GPG-KEY-FILE
Where GPP-KEY-FILE is the GPG key file or the file URL that will also be
accompanied by a hash (usually md5) to check its integrity. To know the
existing signatures in the system, rpm -qa | grep ^gpg-pubkey can be
executed.
For a specific rpm package, it can be checked whether it has a signature and
which one has been used by running rpm –checksig -y package.rpm and
to verify that a package is correct based on the available signatures, it can be
checked with: rpm -K <package.rpm>
RPM is the default Red Hat format (and derived distributions), so it has full
support and updates. In Debian (and derived distributions) the DEB format
is used (see below), but the rpm command also exists although the alien
command is recommended to convert a .rpm packet to .deb and then install
it with the Debian package manager (dpkg).
In the case of Red Hat (and derived distributions) it is common to use the
yum command, which allows the installation and management of packages
in rpm systems and the automatic management of dependencies between
packages, facilitating access to multiple different repositories indicated in the
/etc/yum.conf file, or in different files with .repo extension in /etc/yum.repos.d.
RPM-based systems include a new package management system called dnf
(meaning Dandified YUM) that is considered the yum substitute and default
manager for some distributions such as Fedora 22+, CentOS8+, and RHEL8.
Table 2
Order Description
yum provices <file> Search for packages that provide the file.
• Documented APIs (which did not happen with YUM), and independence
from Python versions.
All of this has meant a change and inclusion of independent libraries to resolve
dependencies (libsolv and hawkey), metadata and repository management
(librepo), and package group management (libcomps) by providing well-defined
APIs, based on a number of external libraries, which can be improved
GNUFDL • PID_00290379 15 Linux administration
The configuration of the DNF system is done through the /etc/dnf/dnf.conf file Note
and all the repos description files (*.repo) found at /etc/yum.repos.d. On the
CLI differences between DNF
other hand, cached system files can be found at /var/cache/dnf. and YUM can be found at:
http://dnf.readthedocs.io/en/
latest/ cli_vs_yum.html.
1.3. Debian: DEB packages
Debian incorporates interactive tools (in text mode) such as tasksel, which
allow choosing large sets of packages grouped by the type of task: packages
for X, for development, for documentation, etc., or as dselect which makes
it easy to navigate through the entire list of available packages (an extensive
list) and choose those that we want to install or uninstall. In fact, these are
only APT mid-level software manager front-ends (equivalent to YUM in RPM-
based distributions).
Where “official” sources are indicated for Debian specifying the type of source
(web in this case), the site, the version of the distribution and categories of the
software to be searched (free, or contributions from third parties or non-free or
commercial licence). Software packages are available for different versions of
the Debian distribution and are identified with stable, testing, and unstable.
The use of one or the other determines the type of distribution (after changing
GNUFDL • PID_00290379 16 Linux administration
Once software sources are configured, the main command to manage them is
apt-get (although some administrators prefer apt that does not provide as
much information as the first one) and allows installing, updating, or deleting
from an individual package, until the entire distribution is updated.
apt-get update
3) To update the distribution, we could update the list of packages and then
upgrade it:
apt-get update
apt-get upgrade
apt-get dist-upgrade
The APT system also allows a secure mode (SecureAPT) based on a hash (md5)
and packet signature (by GPG). If signatures are not available during the
download, apt-get reports it and generates a list with the unsigned packages,
leaving the decision to the administrator whether to install them anyway. For
a list of available trusted sources, we can run:
# apt-key list
The gpg keys of the official Debian sites are distributed in a package and to
install them:
Obviously considering that we have sources.list with the official sites. The
default distribution keys are already installed and only those from other sites
should be installed if considered reliable by running apt-key add key
_file or also with:
Other more specific tasks can only be performed by dpkg, for example, getting
the file list of a given package already installed:
dpkg -L package
dpkg -l
dpkg -S file
This particular one works for installed packages; apt-file also allows the
same but for packages that have not been installed yet. Finally, some graphical
tools for APT, such as synaptic (or in text mode, such as those already
mentioned: aptitude or dselect), should also be mentioned.
• In most cases, root privileges are required to install the packages (via sudo
or su).
different features that try to solve the aforementioned issues with some
particularities: Snap is used in both server packages and desktop applications,
while Flatpak (and its relationship with Gnome, although it may be used in
other window environments) is intended for running applications in user
sessions. In the case of Snap, there is the concept of centralized repository
(Snap Store or Ubuntu myApps, or other names, depending on the destination
platform) controlled by Canonical, while in Flatpak there is no such concept,
only multiple repositories to add for having sources of different packages.
AppImage is intended so that a user can download the developer app and test/
use it without having to worry about anything else and so that the developer
can make an app without worrying about multiple distributions.
1.5. Snap
It has been active as from Ubuntu 16.04 LTS and later versions and is used
to a lesser extent in other distributions, with the most downloaded snaps by
distribution being the following: Arch Linux/spotify, CentOS/wekan, Debian/
spotify, Fedora/spotify, Manjar/vlc.
For its use in the distribution, the snapd package (or similar name, depending
on the distribution) must be installed, which includes the snap command for
package management. If we want to create packages, we will also need the
snapcraft package (and on Ubuntu multipass, required for creating isolated
environments)
Table 3
Order Description
snap find [package] To search for available packages, either by name or by part of it. It
can be combined with grep to find other words associated with the
package in its comments.
snap list [--all] To list packages installed on the system. It can be combined with
grep to find a certain package/word of the installed packages. [--
all] to list the disabled ones as well.
Packages are in the /snap directory, and depending on the type, if they are
graphically executed, they are added to the system menus, or if they are CLI
executable, they will be called from the shell with names similar to the package
name. We can always browse the directories:
Each snap is a read-only image of the squashfs file system and to access the
files within these images, snapd mounts the images, one for each installed
version of snap, within /snap. This list of loop devices includes the snaps that
have been installed and they are part of the normal operation of snapd, so no
attempt should be made to delete them. If we want to delete them, we simply
will execute snap remove package and the app, and the corresponding loop
device will be deleted. An important maintenance that can be done to recover
disk space is to remove the snaps that are disabled since there is a new version;
they are listed with snap list --all and deleted with
sudo snap remove --revision=revision_ID name_snap.
1.6. Flatpak
2) Install from the repository the necessary runtime that will provide all the
required dependencies for the applications in the repository.
3) This allows to see with different options, which packages are available,
install them and run the installed applications.
This summary box shows some of the commands that can be used:
Table 4
Order Description
flatpak remote-add --gpg-import=keygpg repo urlrepo Add a repo repository identified by a keygpg
(previously downloaded), and located at URL urlrepo.
flatpak install repo runtime version Install runtime from the repository with the specific version
number version.
flatpak remote-ls repo --app List the applications available in the repo.
flatpak install repo stable application Install the application in its stable version from the repo repository.
As discussed in Snap, Flatpak also has a number of issues pending with security
models (especially for X Window graphics applications). This part is expected
to be fixed as the X Window Server is replaced by alternatives such as Wayland
or Mir (for Ubuntu and Snap).
Some distributions, such as OpenSuSE, have their own tools such as YaST, or in
the Gnome and KDE desktop environments, they usually have the concept of
“Control Panel”, which allow managing both the visual aspect of the graphical
interfaces and treating some parameters of the system devices (there are also
proprietary software examples, such as cPanel or Plesk, among others, or
linked to Cloud providers, such as SPanel).
It should be noted, in this section, that the Red Hat distribution and its
derivatives have different utilities for different administration functions (see
the administration menu), or commands such as system-config-xxxxx for
different functionalities but which have progressively been replaced by the
concept of a desktop environment control panel (whether the Gnome or KDE
configuration, for example) with functionalities similar to these utilities. The
following figure shows this approximation in the Gnome control panel on
Ubuntu 20.04LTS control panel.
GNUFDL • PID_00290379 23 Linux administration
Figure 1
In the limited space of this unit, not all those tools that can provide benefits
for administration can be discussed, but some of the tools that can be
considered basic will be cited:
• The� editors: required for any configuration task. In text mode, the
choice is the vi editor (although there are alternatives, such as joe,
nano) that is found in all distributions through an improvement
called vim (VI iMproved). This editor allows coloured syntax in various
languages, fast movement and effectiveness but its detractors say that
its work modes are unfriendly and the keyboard shortcuts are not
the usual ones; however, once we learn to work with it, it is highly
efficient and recommendable. And in graphical mode, Sublime, Atom, or
VisualStudioCode are recommended, although they are professional editors
GNUFDL • PID_00290379 24 Linux administration
This section contains some unique aspects of the distributions of both the
Red Hat/Centos/Rocky/Fedora branch and the Debian/Ubuntu/Mint branch,
which are two of the large branches of distribution, as mentioned by [Soy]:
• Using� the� grub� boot� loader (GNU utility). Unlike older versions of
most distributions, which used to use lilo, current distributions use
grub (Grand Unified Bootloader). It has a text mode setting (typically
/boot/grub/grub.conf) but is modified via scripts in /etc/grub.d (or /etc/
defaults/grub* or /etc/defaults/grub.d in Debian/Ubuntu) and also supports
modification at booting. Most current distributions have already migrated
to GRUB2, which includes a more modular configuration system, as well
as expanded Linux kernel parameter support, and improved support for
various operating systems.
that run when a user opens a shell; /etc/sysconfig, configuration data for
various aspects and services of the system (RHEL branch); /etc/cron, various
directories specifying jobs to be done periodically (via crontab); /etc/pam.d,
where PAM (Pluggable Authentication Modules) are a set of libraries that
allows the administrator to configure how users authenticate so this task
should not be done by applications; /etc/logrotate.d, configuration of the
rotation of log files (usually in /var/log) for different services and that
indicate when a new version must be made, deleted, compressed, etc.
dpkg-reconfigure locales
that allows choosing the regional language and character set settings that will
be available, or
dpkg-reconfigure tzdata
• The services and boot system have traditionally been managed by SyVinit
which is based on a daemon (init) and a set of scripts in /etc/init.d and start
and stop execution scripts of each level managed by /etc/rc.X. Currently,
most distributions have migrated to a new concurrent service boot system,
based on a different philosophy that makes it safer and more efficient,
called systemd (and which will be seen in the next section).
GNUFDL • PID_00290379 26 Linux administration
The main design objectives were to be able to express dependencies between Note
daemons to run them concurrently (whenever possible) in the interest of
The Boycott systemd site
efficiency (reduced boot time) and to improve blockages due to defective collected much of these
configurations. The design and integration of systemd has not been free from criticisms of systemd and
some of the discussions or
community criticism, basically because it is an attempt to gather a large more arguments against and
alternatives to systemd can still
number of functionalities in a single environment (in the opposite direction of be found.
the UNIX philosophy, of small, interconnected tools, each performing specific
and well-defined tasks).
• Unit� files: where the initialization instructions for each daemon are
collected in a configuration file (called a “unit file”). There are different
types such as: service, socket, device, mount, automount, swap, target, path,
timer, snapshot, slice and scope.
• Core�components:
– systemd, the main daemon of the systemd system acting as a service
manager for GNU/Linux.
Some graphical frontends are also available for managing services, and
consulting the available units, such as systemd-ui (for Gnome environments,
also known as systemadm) and systems-kcm (for KDE environments).
The files are in (in reverse order of importance if there are equal files in
different directories):
Table 5
For the management of system services, service units (.service) are used, which
are used for purposes similar to the old service files present in /etc/init.d/.
systemd is basically managed with the systemctl command and parameters
such as start, stop, restart, enable, disable, status, is-enabled to manage the
services.
will provide the status of all services (or service type units in systemd
terminology).
lists the name of the service with its full name and information on whether it
is active or not. For a particular service it can be done with:
systemctl get-default
For the different machine shutdown and restart options, the following options
are available: halt, power off, reboot, suspend, hibernate.
One particularity of systemd is that it can also act on remote machines via
ssh connection, for example, a command can be executed with:
Or detailed information (to be expanded below) can also be obtained from the
PID of the process involved by examining the corresponding journal (logs):
journalctl -b PID_ID
Systemd considers many possibilities, depending on the units used and the
multiple components available and which will be discussed in subsequent
sections. An interesting source of detailed systemd documentation is that
developed by ComputerNetworkingNotes in systemctl, services, targets, unit
files and units types & states.
GNUFDL • PID_00290379 31 Linux administration
3. System status
One of the main daily tasks of the administrator (root) will be to verify the
correct operation of the system and to monitor the existence of possible errors
or saturation of the machine resources (memory, disks, etc.). This section will
detail the basic methods for examining the system status at a given time and
taking the necessary actions to prevent further problems.
• Uptime�command: indicates for how long the system has been active.
GNUFDL • PID_00290379 32 Linux administration
At booting time, a series of virtual file systems are also generated, which allow
us to access information about the boot process, and the dynamic state of
the system, from both the user space and the kernel space, and its various
components. Among the virtual file systems used, we must highlight:
The kernel, during its booting, creates the virtual file system procfs and
mounts it in /proc, where it will save most of the system information. The /proc
directory is deployed on memory and is not saved on disk and data in files/
directories can be either static (not modified during OS execution) or dynamic
(created/destroyed/modified during execution). Because its structure depends
on the activity of the kernel, the files/contents may change in different
executions/versions of the kernel.
In the /proc we will be able to find the images of the running processes,
along with the information that the kernel manages about them and each
process will have a directory with PID of the process (/proc/<pidprocess>) that
will include the files that represent their status. This information will be the
primary source for debugging programs, or for the system’s own commands,
such as ps or top, or htop to view the status of running processes. A set
of system commands query the dynamic system information from /proc and
some specifics found in the procps package.
GNUFDL • PID_00290379 33 Linux administration
In addition, the global status files of the system can be found in /proc, a
summary of which is shown below:
Table 6
File Description
The sys virtual file system makes the device and driver information visible
in the user space (this information is available to the kernel) so that other
APIs or applications can easily access device information (or its drivers). It is
often used layered as the udev service for dynamic device monitoring and
configuration.
/sys contains a tree data structure of the devices and drivers and is then
accessed via the sysfs file system (whose structure can vary among different
versions). When the kernel detects a device, a directory is created in sysfs and
the parent/child relationship is reflected with subdirectories under /sys/devices/
(reflecting the physical layer and its identifiers). Symbolic links are placed in
the /sys/bus subdirectory, reflecting how the devices belong to the different
physical buses of the system and in /sys/class the devices grouped are displayed
according to their class, such as network, while /sys/block/ contains the block
devices.
GNUFDL • PID_00290379 34 Linux administration
Some of the information provided by /sys can also be found on /proc, but
gradually, in the different versions of kernels, it is expected that device
information will be migrated from /proc to /sys to centralize all its information.
Unlike traditional systems, where the device nodes, present in the /dev
directory, were considered as a static set of files, the udev system dynamically
provides the nodes for the devices present in the system.
Udev is the device manager for the Linux kernel (which replaces previous ones
such as hotplug and devfsd). This service (now included in systemd), manages
the device nodes in the /dev directory, as well as the events generated in user
space, due to the new insertion/deletion of hardware devices. Among other
features, udev supports:
• Execution in user space, thus avoiding the need for the kernel to name
devices by allowing the use of specific device names from the device
properties.
Historically, in the /dev directory are the system device files (nodes) so that
a program in user space can access a hardware device or a function of it. For
example, the device file /dev/sda is traditionally used to represent the first disk
of the system (SATA bus) and the name sda corresponds to a pair of numbers
called the major and minor of the device, and which are those used by the
kernel to determine which hardware device it is using. Each of the major and
minor numbers is assigned a name that corresponds to the device type as can
be seen in the kernel information.
• Name�in�the�kernel.
If the above steps cannot provide a name, the one available in the kernel will
be used.
The udev system, whose information typically resides at /lib/udev and /etc/
udev (there may also be a /run/udev at runtime), among others, includes a
number of rules for the naming and the actions to take on devices in /lib/udev/
rules.d (default rules) or /etc/udev/rules.d (managed by the administrator and
take precedence over the default rules).
If udev needs to load a driver, it will use the modalias to load the correct
driver that will be found from the information of the modules that ends up
creating (via depmod when installing new modules) the corresponding file in
/lib/modules/`uname -r`/module.alias.
GNUFDL • PID_00290379 36 Linux administration
3.5. Processes
Among the processes that are running at a given time, we can find 3 types:
The most useful commands for managing processes are listed below:
• ps: most used command for versatility and information, list processes,
time, process identifier, status, resources and command line used. It
supports different parameters/syntax and options between the most used
ps -edaf or in BSD ps aux syntax (see man ps).
• kill (killall): it allows deleting processes in the first case by the PID,
and in the second case by the name or other parameters. kill sends
signals to the process such as kill -9 PID_ID of the_process (9
corresponds to SIGKILL) or killall firefox where it will delete all the
processes of the user who executes it and which are called firefox. See also
skill possibilities, for example, to delete all processes for a user with skill
-STOP -u user_name.
• Suspend an interactive process: this can be done with Crtl-z which will
return the control to the terminal and then resume it with the fg
command.
• Change the execution priority of a process: through the nice and renice
commands we can modify the priorities of the process and change the
access they have to the resources.
Both the kernel and many of the service daemons, as well as different GNU/ Note
Linux applications or subsystems, can generate messages that are saved in files
There are several log managers
as a trace of their operation and that will also serve to detect errors, or critical depending on the distribution
situations. These logs are essential in many cases for administration tasks and used; the classic UNIX and
GNU/Linux system is initially
often take a lot of administration time to process and analyze their contents. Syslogd, but progressively the
rsyslog and Journald systems
(part of systemd) have begun
to be used as alternatives, or in
conjunction with syslogd.
Most logs are stored in the /var/log directory, although some
applications may modify this behaviour. Most of the logs of the system
itself are in this directory and are usually set to /etc/syslog.conf or /etc/
rsyslog.conf (depending on the daemon that manages them).
The daemon syslogd (or its alternatives such as rsyslog or journald), which is
responsible for receiving the messages that are sent by the kernel and other
service daemons and sends them to a log file (usually /var/log/messages but
it can be configured at /etc/syslog.conf). The configuration allows redirecting
the messages to different files depending on the daemon that produces them
and/or also classify them by importance (priority level): alarm, warning, error,
critical, etc.
tail -f /var/log/syslog
which will show any changes to the device that may appear in the file.
Other useful commands for extracting information from the system are:
GNUFDL • PID_00290379 38 Linux administration
• logger: allows inserting messages into the log system such as logger
“Checkpoint at `date`” which then with tail /var/log/syslog we can
see as Apr 24 10:48:28 aopcrs adminp: Checkpoint at Sun 24 Apr 10:48:28
CEST 2022
With regard to the other daemon that has been mentioned (journald), included
in the systemd, it has aroused many criticisms since it uses binary formats
to save the logs (unlike the previous ones that are in text mode), but it has
gained importance in the distributions that support systemd (or in some it is
a combined method between both daemons (see for example man systemd-
journald or man rsylogd in Ubuntu for example and systemctl status
rsyslog or systemctl status systemd-journald).
# journalctl
With systemctl status systemd-journald we can see where the logs are
being saved (for example, in Ubuntu in /run/log/journal/...) and which will be
processed by journalctl. The configuration file is in this case at /etc/systemd/
journald.conf. There are different parameters for journalctl, among the most
interesting ones, we have:
• journalctl -f: The process becomes active and will display the next
messages as they are generated by the terminal.
3.7. Memory
Regarding the system memory, it should be noted that it is divided into two:
physical memory and virtual memory. Normally (unless specific servers), large
amounts of physical memory will not be available and it is advisable to use
virtual memory (called swap memory) that will be implemented on the disk.
This memory (swap) can be implemented as a file in the file system, although
it is usually defined as a partition dedicated to this purpose (swap partition),
created during the installation of the system and of the ‘Linux Swap’ type.
• ps: it allows knowing which processes are running and with the
percentage and memory used options.
• free: information about the global state of physical memory and virtual
memory.
• vmstat: information about the status of virtual memory, and its use.
• /etc/fstab file: the swap partition (if any) appears, also with fdisk -l we
can find out its size or consult /proc/swaps.
3.8. Disks
To know the available disks (or storage devices) we can look at the system boot
information (with the dmesg command or in the file/var/log/messages), where
devices such as /dev/hdx are detected for IDE devices (currently in disuse) or
SATA/SCSIs with /dev/sdx type devices. Other devices, such as USB-connected
hard drives, solid-state drives (usually called pendrives), removable drives,
external CD-ROMs, are often devices with some type of scsi emulation, so they
will also look like /dev/sdx type devices. It should be noted that the different
layers of hardware+software in the operating system hide the disk technology
that can be magnetic (mechanical) or solid state (electronic only) and called
SSD (Solid State Disk). The latter are increasingly encompassing market share
GNUFDL • PID_00290379 41 Linux administration
Any storage device will present a series of partitions of its space and
typically a disk with the classic MBR format supports a maximum of
four physical partitions, or more if they are logical (multiple partitions
of this type can be placed on a physical one). Each partition can contain
different filesystems, either from the same operating system or from
different ones.
The classic partition format (developed in the 1980s), has a structure called
MBR (Master Boot Record), and is a special type of boot sector (512 or
more bytes in the first sector of the disk), which saves the disk partitions as
organized, as well as containing code (loader) that allows the disk to boot on
an operating system resident in any of the partitions, starting at the request
of the BIOS.
MBR has some important limitations, but the two main ones are that it
supports only 4 physical partitions called primary (or 3 primary ones and
an extended one that can accommodate 128 logical partitions) and a disk
capacity limitation of 2TB. Because of these limitations, the current disk
partitioning scheme is migrating to the GPT (GUID Partition Table) scheme
that does not have these limitations. New versions of BIOS such as EFI and
UEFI support GPT, in addition to allowing access to disks larger than 2TB, but
there are some manufacturers that have made various modifications to the
MBR scheme to support the two schemes and support GPT as well.
# fdisk -l /dev/sda
Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: XX.YY HARDDISK
Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes
GNUFDL • PID_00290379 42 Linux administration
5GiB MBR disk with three partitions (identified by the number added to the
device name), where we can see a boot partition (Boot column with *) Linux
type, an extended partition, and within a swap logical partition (we can see
that sda2 and sda5 share the same start/end sector although the swap has 2
bytes less (for alignment reasons) than the extended one. Similar information
can be found in /proc/partitions.
During booting, the system mounts the default partitions and there may be
others that can be mounted on-demand or automatically mounted when a
device is available (e.g., USB drives). The most important commands and files
for obtaining information from disks in addition to those mentioned are:
There are also a number of files that the administrator will need to review
(and delete if necessary) which may include: core files (these are large files
with images from the memory of programs that have caused an error),
among which we can mention: email system (in /var/spool/mail or in the user
directory), browser caches or other applications (usually in the user directory)
and HOME directories of the users themselves (in general).
GNUFDL • PID_00290379 44 Linux administration
4. Energy management
As a special case of control devices similar to udev, but not integrated into it,
is the management of energy-related devices (and in some distributions also
the disks). These components are integrated into the freedesktop.org initiative,
which aims to develop interoperable technologies for developing desktop
environments. Various desktop environment projects, such as GNOME, KDE
and Xfce, collaborate with freedesktop.org (also known as X Desktop Group
or XDG) to develop methodologies and techniques that add value to the
developments of these environments.
5. File system
Apart from the main/filesystem and its possible splits into extra disk partitions
(/usr /var /tmp /home), the partitions of other operating systems can be accessed
in GNU/Linux if they exist (and that one or the other is selected at boot time).
Sometimes, it is interesting to be able to access these files in read or write and
there is no problem for Linux to access Windows partitions and files (either
FAT or NTFS) and they are accessed through FUSE (module integrated in the
kernel that allows access to the files in user space).
removable devices). According to the FHS standard, /mnt should be used for
temporary mount of file systems, while /media is used to mount removable
devices.
The filesystem type can be: msdos (fat), vfat (fat32), ntfs, iso9660 (for cdrom),
ext4, xfs, among others.
The device is the corresponding input in the directory /dev to the location of
the device (the IDEs -obsolete- /dev/hdmn, where ‘m’ is a,b,c,d and ‘n’ is the
partition number, the SCSIs with /dev/sdmn, where ‘m’ is a,b,c,d... and ‘n’ the
partition number.
For example:
mounts the second partition of the first device (C drive:Windows), NTFS type
in /mnt/win.
umount /mnt/cdrom
umount /mnt/win
For removable media, USB/CD/DVD type, eject can be used for media
removal.
Note that all files/directories are given reduced access control lists in 3 groups
(owner, group, rest) and with rwx permissions (read, run, write including
deletion) so there will be 9 bits left as rwxrwxrwx, where the first 3 correspond
to the owner, the second ones to the group and the rest to users who do not
own or belong to the group. For a directory, x denotes the permission to be
able to enter that directory (with the cd command, for example). To modify
GNUFDL • PID_00290379 48 Linux administration
the rights/property over a directory or file, it can be done with: chown (change
owner of the files, only the root can do it), chgrp (change owner group of
the files, only the root can do it), chmod (change specific permissions (rwx)
of the files).
GNUFDL • PID_00290379 49 Linux administration
• User� accounts: accounts for any machine user who can perform any
activity on their HOME and in some directories such as /tmp but in the
rest he/she will only be able to look and in some such as /var this activity
will even be restricted.
• Special� services� accounts: lp, wheel, www-data... accounts that are not
used by people, but by system services (usually to not use the root for
managing these services), and normally as shell they have /bin/false in the
file /etc/passwd to prevent them from being interactive accounts.
The user will be created with an identifier known as a name or login (or user
identifier), a password, and an associated personal directory (the account). As
a name, the initial of the name and the last name are generally used, all in
lowercase, although it is an unwritten rule. System user information (local,
unless external directory systems such as YP/NIS or LDAP are used, which will
be seen later).
All of these files are organized by lines, each of which identifies a user or group
(depending on the file). On each line there are several fields separated by the
character “:” and it is important to know what information they contain. All
of this information can be found in the introduction module.
When a user enters the system, after the user/password has been validated,
they are placed in their HOME directory and the order interpreter (shell)
set to /etc/passwd is executed on the line corresponding to the user (field 7)
GNUFDL • PID_00290379 51 Linux administration
and can begin to execute orders or work interactively with the system. Only
the system root (or users in its group) have permission to manipulate the
information of the other users and groups, register them, unsubscribe them,
etc. (some orders, such as chfn, will allow users to change their information if
it is configured that it can be done). Each order for handling users has several
different parameters for managing user information and/or fields mentioned
above.
• adduser: adds a new user to the system. The way the user is created
(if no additional information is specified) can be configured in the /etc/
adduser.conf file. It supports a different set of options to specify the home
directory, the shell to use, etc. It is recommended to use this command
and not useradd.
• usermod: with this order, most of the fields found in the passwd and
shadow file can be modified, such as the home directory, shell, password
expiration, etc.
• deluser: deletes a user from the system, and deletes all their files
according to the parameters indicated (allowing even a backup), etc.
The default settings to be used with this order are specified in the /etc/
deluser.conf file.
• whoami: it is used for knowing which user we are identified with (it may
seem like a nonsense question, but it is a common question when working
with different users or as root) and it will display the current user identifier.
GNUFDL • PID_00290379 52 Linux administration
• groups: used to know which groups the user belongs to and it will display
user and group ID.
It is also interesting that the current user can ‘become’ another user without
exiting the current session via the login or su command (useful action
when it is necessary to run/access information as another system user if their
password is available) or changing groups with the newgrp order. This last
order should only be used when it does not belong to the group in question
and its password is known (which must be activated in the /etc/gshadow file). If
only the permissions of a given group are needed to execute an order enabled
for this group, the sg command can be used.
There is a directory (usually /etc/skel), where we find the files included when
a new account is created and they will be the ones that initially configure the
user session (environment variables, keyboard, alias, etc.). The administrator
must adapt these files according to what their users need as an initial session
(each user can then modify them according to their needs).
If the user wants to change the password in NIS systems, instead of the passwd
command, the yppasswd command must be used which will change it in the
database and propagate it to all clients in the NIS domain. These concepts will
be expanded in the network services section.
GNUFDL • PID_00290379 53 Linux administration
7. Print servers
There are two classic printing systems: LPD (Line Printer Daemon) of the BSD-
UNIX branch and System V Line Printer (or LPR), common in different UNIX.
GNU/Linux has originally integrated both systems, either primarily by using
LPD and emulating LPR or depending on the distribution integrating one or
the other by default.
LPD is a fairly old system (dated back to the origins of the mid-1980s BSD
branch) and is often lacking support for modern devices as it was not intended
for current printers. To solve this problem, LPD is combined with Ghostscript,
which is an environment that produces output in postscript format for a
very wide range of printers with drivers. This software is also combined with
filtering software that eventually defines, depending on the file to be printed,
the most suitable for the task to be performed. The process with LPR is very
similar.
While these print servers are functional, they offer little flexibility and
a complex setup task for quality prints. To solve these problems, the
CUPS project was developed with the aim of unifying criteria, making the
configuration process (for printers and printing service) simple, flexible and
of good quality. Nowadays, CUPS has become the de facto standard for GNU/
Linux and, although LPD and LPR are still included for compatibility, they are
not commonly used.
7.1. CUPS
CUPS is a new print system architecture that features a support layer for BSD
LPD and allows it to interact with servers of this type. It also supports a new
printing protocol called IPP (based on http), but only available when the client
and the server are CUPS type and it also uses a type of drivers called PPD that
identify printer capabilities and properties.
GNUFDL • PID_00290379 54 Linux administration
It should be noted that CUPS is designed for both clients and the server
to operate under the same environment; if clients use LPD, a compatibility
daemon called cups-lpd (in packages such as cupsys-bsd) must be installed. In
this case, CUPS will accept jobs, from an LPD system, but it will not control
the access.
Figure 3
And it is displayed as shown in the following figure from the client (for
example Libre Office):
GNUFDL • PID_00290379 55 Linux administration
Figure 4
GNUFDL • PID_00290379 56 Linux administration
Typical RAID levels are (although in some cases the nomenclature may depend
on each manufacturer):
• RAID�5: splitting is used at the block level, distributing parity across all
disks. It is widely used, due to the simple parity scheme, and because
this calculation is easily implemented by hardware, with good features.
RAID 5 will require a minimum of 3 disks to be deployed and only
allows one disk to fail (the failure of a second disk causes complete data
loss). The maximum number of disks in a RAID 5 redundancy group is
theoretically unlimited, but in practice it is common to limit the number
of drives as the drawbacks of using larger redundancy groups are a higher
probability of simultaneous failure of two disks, a longer reconstruction
time, and a higher probability of finding an unrecoverable sector during a
reconstruction. One alternative that provides dual parity protection, thus
allowing for more disks per group, is RAID 6.
• RAID� 6: it was not part of the original levels and it extends the RAID5
level by adding another parity block, so it divides the data at the block
level and distributes the two parity blocks between all members of the set.
An algorithm based on Reed-Solomon code is used for parity calculation
and therefore RAID6 is a special case of this with only two codes (2 parity
blocks). RAID 6 provides protection against dual disk failure and failure
when a disk is being rebuilt and a minimum of 4 disks are required to
deploy it.
• RAID� 5E� and� RAID� 6E: this is how RAID 5 and RAID 6 variants that
include backup drives are referred to. These disks can be connected and
ready (hot spare) or on standby (standby spare). In this ‘E’ classification,
backup disks are available for any of the drives and do not result in any
performance improvement, but reconstruction time (for hot spare disks)
and management tasks are minimized when failures occur. A backup disk
is not actually part of the assembly until a disk fails and the assembly is
rebuilt over the backup disk.
Nested�RAIDs:
level used can be rebuilt thanks to the other copy, but if disks are to be
added, they must be added to all RAID 0 groups.
• RAID improves system uptime, as some of the levels allow the disks to
fail and the system to remain consistent, and depending on the hardware,
even the problematic hardware can be changed without the need to shut
down the system, a particularly important issue in critical systems.
• RAID does not protect data; obviously, destruction by other means (virus,
general malfunction, or natural disasters) is unprotected and it is vital to
have backup copies.
• Some schemes speed up reading operations, but on the other hand, they
penalize writing operations (RAID 5 case for parity calculation to write). If
the use is basically writing, we will need to look for which schemes do not
penalize them (some cases, such as RAID 0.1, or some RAID 10 modalities
are equivalent to writing on a single disk, or even increase performance).
• Information transfer is not facilitated; it’s quite easy to move data without
RAID, by simply moving the drive from one system to another. In the case
of RAID, it is almost impossible (unless the same hardware controller is
available) to move one disk array to another system.
The command used to create and manage RAIDs in Gnu/Linux is called mdadm
and below are some examples regarding SCSI disks:
where a linear array is generated from the /dev/sda1 and /dev/sdb1 partitions,
creating the new /dev/md0 device on which the archiving system can already
be created and mounted:
For a RAID0 or RAID1 we simply change the level to raid0 or raid1. With mdadm
--detail /dev/md0 we can check the parameters of the newly created array
and we can check the input in /proc/mdstat to determine the active arrays,
as well as their parameters. mdadm has options to examine and manage the
different RAID arrays software created (see man mdadm) and it should be
noted that RAID arrays by software are not automatically recognized at boot
time (as with RAID hardware), as they actually depend on the construction
with mdadm. For the definition of an array software to be persistent, it must
be recorded in the configuration file /etc/mdadm/mdadm.conf (location may
depend on distribution) through:
To configure a RAID5 with three SATA disks and one partition per disk, we
must:
• Prepare the disks: with fdisk creating an ‘fd’ type partition (Linux Raid
autodetect) over each one.
• To add a new drive: mdadm --add /dev/md0 /dev/sde1 (this drive will
remain as a spare), mdadm --grow /dev/md0 --raid-devices=4 (to
move the spare drive to active) and then the file system must be resized
with resize2fs /dev/md0 size
GNUFDL • PID_00290379 61 Linux administration
• Mark a disk with errors and remove it: mdadm --fail /dev/md0 /dev/
sde1; mdadm --remove /dev/md0 /dev/sde1
• Monitor the array (be careful with this command as it can be a massive
source of emails if it is not configured correctly): mdadm --monitor --
scan --mail=[email address] --delay=1800 &
2) Snapshots of the file system making it easy to create a new device that
is a snapshot at the time of a LV situation. We can, for example, create the
snapshot, mount it, test various new software operations or configuration, or
other items, and if it does not work as expected, return the original volume
to its state before testing.
To perform these types of jobs, there are several options for planning and
executing tasks:
• nohup: this is the simplest case used by users as it allows them to perform a
non-interactive task and it is maintained even if the user exits the session.
10 3 * * * root task1
20 3 * * 7 root task2
30 3 1 * * root task3
where a series of tasks to be done are being scheduled: every day (“*” indicates
“any”), weekly (the seventh day of the week), or monthly (the first of each
month). The tasks would be executed by the crontab command, but the cron
system assumes that the machine is always on. If not, it is best to use anacron,
which checks if the action was not performed when it should have been done,
and executes it. In this example, task1 will run every day at 3:10, task2 on the
7th day of each week at 3:20, and task3 on the 1st of each month at 3:30.
There may also be some files, cron.allow, cron.deny, to limit who can place jobs
(or not) in cron, and using the crontab command, a user can define jobs in
the same format as above and which will be saved in /var/spool/cron/crontabs.
In some cases, there is also a /etc/cron.d directory where jobs can be placed and
which is treated as an extension of the /etc/crontab file. In some versions, the
GNUFDL • PID_00290379 65 Linux administration
Among them, the most direct one is the change of IP protocol that will be in
its version 6 (IPv6) and that will force all systems to be changed to operators
and users to support this new connection protocol. The other significant
concept in communication environments is the Internet of Things which will
soon change society as it is known (by the number and diversity of devices
connected to the Internet).
Beyond these challenges, this section will discuss the current TCP/IP-based
communication structure and protocols, which is the base protocol used on
the Internet.
Nowadays, the most common use of TCP/IP for the user is the remote
connection to other computers (SSH), the use of remote files (NFS), or
their transfer (HTTP, Hypertext Transfer Protocol) among others. The most
important traditional TCP/IP services (and which nowadays still exist or have
evolved) are:
c)� Mail: this service allows sending messages to users on other computers.
This mode of communication has become a vital element in users’ lives and it
allows emails to be sent to a central server so that they can then be retrieved
through specific programs (clients) or read through a web connection.
The advancement of technology and the low cost of computers have allowed
certain services can be offered already configured over certain computers
working on a client-server model. A server is a system that provides a specific
service for the rest of the network. A client is another computer that uses this
service. All of these services are generally offered over TCP/IP:
There is another alternative protocol called ICMP that is used for error/control
messages or to extract information about a network.
From the physical point of view (OSI model layer 1), the most widely used
hardware for local networks (LAN, local area network) is known as Ethernet. Its
advantages are its low cost, acceptable speeds (from 10 to 10,000 Megabit/s -
that is, 10 Gbit per second in the latter case), and ease of installation. Although
there were different ways of connecting, the ones used nowadays are twisted
pair and optical fibre.
We can also view configured devices and all (dynamic) status and
configuration information on /proc/net and view all instant packet
information sent and received and their status for each interface on /proc/net/
dev.
• Node: a node (host) is a machine that connects to the network (in a broad
sense, a node can be a computer, tablet, phone, printer, disk cabinets, etc.),
i.e., an active and distinguishable element in the network that claims or
provides some service and/or shares information.
• Host�name: Each node must also have a unique name on the network.
They can be just names or use a hierarchical domain naming scheme.
Names must be a maximum of 32 characters between a-zA-Z0-9.-, and
contain no spaces or #, starting with an alphabetic character.
by the institution. A rule that governs these names is the FQDN (Fully
Qualified Domain Name) that includes a computer name and the
domain name associated with that computer. For example, if we have
a host named ‘remix’ and the domain is ‘nteum.cat’, the FQDN will
be ‘remix.nteum.cat’. On some networks where DNS is not available or
accessible, the /etc/hosts file (which must be on all devices in the network)
can be used and will meet the same objective, or the mDNS service
(e.g., avahi) that implements the so called zero-configuration networking
(zeroconf) for DNS/DNS-SD multicast configuration can be installed. This
service allows programs to publish and discover services and hosts over a
local network. In an opening policy, the ICANN has regulated the request/
inclusion of new generic higher order domains (called gTLDs) oriented by
sectors, for example, cities (.barcelona, .miami...), food (.beer, .coffee...),
geocultural, music and art, education, computer science, etc.
11.4.1. IPv4
The IP address in IPv4 has two fields: the left one represents the network ID
and the right one represents the node ID. With this in mind, the 4 numbers
between 0-255, or four bytes, each byte is either part of the network or the
node. The network part is assigned by the ICANN and the node part is assigned
by the institution or provider.
There are some constraints: 0 (for example, 0.0.0.0) in the network field is
reserved for default routing and 127 (for example, 127.0.0.1) is reserved for
self-referral (local loopback or local host), 0 in the node part refers to this
network (for example, 192.168.0.0) and 255 is reserved for broadcast (the same
packet is sent to all host in the network) (for example, 198.162.255.255).
Some address ranges have been reserved so that they do not correspond to
public networks. These addresses belong to private networks and messages will
not be routed over the Internet, which is commonly known as the Intranet.
These are:
A concept associated with an IP address is the mask, which will then allow
defining subnets and automatically route packets between these subnets. To
do this, it is necessary to define a network mask that will be the significant bits
of the subnet and that will allow to define whether two IPs are within the same
network or not. For example, in a given static IPv4 address (e.g., 192.168.1.30),
the network mask 255.255.255.0 (i.e., 11111111111111111111111100000000
in binary representation) indicates that the first 24 bits of the IP address
correspond to the network address and the other 8 are machine-specific.
In IPv6, and since they are 128 bits, only the number of 1s (notation that is
also used in IPv4) will be expressed, to facilitate its reading. In the example
above, for IPv4 it would be 24 and generally would be 192.168.1.30/24 and
in IPv6, for example, for the address fe80:0db8::0470:0534 the mask could be
expressed as fe80:0db8:::0470:0534/96, where it indicates that for this address,
the first 96 bits correspond to the network.
11.4.2. IPv6
IPv6 address types can be identified by taking into account the ranges defined
by the first few bits of each address (the value specified after the bar is the
mask equivalent to the number of bits not considered for that address):
• ::1/128. It represents the loopback address that a node can use to send
packets to itself (corresponds to 127.0.0.1 of IPv4). It cannot be assigned
to any physical interface.
• fe80::/10. The local link prefix specifies that the address is only valid on
the local physical link.
• fec0::. The local prefix (site-local prefix) specifies that the address is only
valid within a local organization. RFC 3879 has made it obsolete and it
must be replaced by Local IPv6 Unicast addresses.
If the address is a built-in IPv4 address, the last 32 bits can be written
in decimal base as ::ffff:192.168.1.1 or ::ffff:c0a8:0101, not to be confused
with ::192.168.89.9 or ::c0a8:0101. The format ::ffff:1.2.3.4 is called the
mapped IPv4 address, and the format ::1.2.3.4, is called the compatible IPv4
address.
IPv4 addresses can be easily transformed into the IPv6 format. For example, if
the IPv4 decimal address is 158.109.64.1 (in hexadecimal, 0x9e6d4001), it can
be converted as 0000:0000:0000:0000:0000:0000:9e6d:4001 or ::9e6d:4001.
In this case, we can use the IPv4 mixed supported notation which would
be ::158.109.64.1. This type of supported IPv4 address is hardly being used,
although the standards have not made it obsolete.
When we want to identify a range of addresses that can be made by the first
bits, this number of bits is added after the bar character“/”. For example,
fe80:0db8::0674:9966/96 would be equivalent to fe80:0db8:: and also to
fe80:0db8::0470:0534/96
IPv6 addresses are represented in DNS using AAAA records (also called quad-
A records, as they are four times the length of A records for IPv4) specified by
RFC 3363 (there is another view called A6, but while it is more generic, it is
also more complex and can further complicate the transition between ipv4
and ipv6).
The one who defines which packets are going to one side or another will
be the host that meets the router role and will interconnect several network
segments/networks with each other. The router is generally known as a
gateway and is used as the host that helps reach the outside (e.g., Internet)
from the local network. To obtain the subnet identifier, a logical AND
operation must be performed between the mask and the IP, which will give
the IP of the subnet.
For example, let it be an institution that has a class B network with number
172.17.0.0, and its netmask is 255.255.0.0. Internally, this network is made
up of small networks (one per floor of the building, for example). Thus,
the address range is reassigned on 20 subnets 172.17.1.0 to 172.17.20.0. The
point connecting all these subnets (backbone) has its own range/address, for
example 172.17.1.0. These subnets share the same network IP, while the third
is used to identify each of the subnets within it.
The second concept, routing, represents how messages are sent over subnets.
For example, there are three departments with Ethernet subnets:
To route the messages between the computers of the three networks, three
gateways will be required that will each have two network interfaces to switch
between Ethernet and FFDI. These will be:
When messages are sent between sales machines, there is no need to exit
to the gateway as the TCP/IP protocol will find the machine directly. The
problem is when the Sales0 machine wants to send a message to HHRR3. The
message must flow through the two respective gateways. When Sales0 “sees”
that HHRR3 is in another network, it sends the packet to its SalesGW gateway,
which in turn will send it to HRGW and which in turn will send it to HHRR3.
The advantage of subnets is obvious, as traffic between all Sales machines,
for example, will not affect client or human resource machines (although it
means a more complex and expensive approach to designing, and building
the network).
IP uses a table for routing packets between different networks and in which
there is a default routing associated with the 0.0.0.0 network. All addresses
matching this, as none of the 32 bits are required, are sent to the default
gateway towards the indicated network. On SalesGW, for example, the table
could be:
Table 7
The '-' means that the machine is directly connected and does not require
routing. The procedure to identify whether this is performed or not is carried
out through a very simple operation with two logical ANDs (subnet AND mask
and origin AND mask) and a comparison between the two results. If they are
the same, there is no routing, if they are different, the packet must be sent to
the machine defined as gateway in each network so that it can forward the
message.
Instead, if sent from 172.17.2.4 to 172.17.6.6, it can be seen that there will
be a routing through 172.17.2.1 with an interface change (cable to fibre) to
172.17.1.1 and from it to 172.17.1.2 with another interface change (fibre to
cable) and then to 172.17.6.6.
GNUFDL • PID_00290379 79 Linux administration
The default routing will be used when no rule satisfies the match. In the event
that two rules match, the one that does so more accurately, that is, the one
that has the least zeros, will be used. The ip route command can be used
to build routing tables, but if more complex rules (or automatic routing) are
required, routing protocols such as RIP, EGP, or BGP can be used.
• Node IP
• Network mask IP
• Gateway IP (on the same node network)
• DNS IP
In this section, we will see in a little more detail what was already mentioned
in the Linux introduction module about the configuration of the network
(Ethernet) and the Wi-Fi network.
From this point on, the network interface can be configured, which involves
two steps: assigning the network address to the device and initializing the
network parameters to the system. The command used for this is the ip. An
example would be:
GNUFDL • PID_00290379 80 Linux administration
In the Debian branch, the ifdown/ifup commands can be used, although the
corresponding package (apt install ifupdown) must be installed, which
allows the devices to be easily activated and deactivated independently by
using the /etc/network/interfaces file to obtain all the necessary parameters (see
man interfaces for its syntax).
In GNU/Linux there are different ways to configure the network so that the
administrator should not have to enter the configuration parameters in each
boot. One of the simplest ways is through the commands mentioned above
(ifup, ifdown) that take their information from the /etc/network/interfaces
file. To modify the network parameters of the eno1 interface, we can do the
following:
• ifdown eno1. Stops all network services. We can also run systemctl
stop networking.
• ifup eno1. This command allows to start the network services on eno1
(or systemctl networking start).
Consider that we want to configure over Debian an eno1 interface that has a
fixed IP address of 192.168.0.123 and with 192.168.0.1 as a gateway. We edit
/etc/network/interfaces to include a section such as:
auto eno1
iface eno1 inet static
address 192.168.0.123
netmask 255.255.255.0
gateway 192.168.0.1
auto eno1
iface eno1 inet static
GNUFDL • PID_00290379 81 Linux administration
address 192.168.0.123
netmask 255.255.255.0
gateway 192.168.0.1
dns-search nteum.cat
dns-nameservers 8.8.8.8 8.8.4.4
Instead of auto eno1, we can also use, for example, the allow-hotplug
eno1 sentence, which indicates the interface that can be activated with ifup
--allow=hotplug eno1. Lines starting with allow- are used to identify
interfaces that could be activated by different subsystems (allow-auto and
auto are synonyms).
Remember that if the machine has multiple network interfaces, the previous
section can be repeated with the corresponding device, but the last three lines
(gateway, dns-search and dns-nameservers) should only be there once, as they
are common for all interfaces.
After activating the interface, the arguments of the dns-search and dns-
nameservers options are included in /etc/resolv.conf. The nteum.cat argument
of the dns-search option corresponds to the resolv.conf search option argument
and the 8.8.8.8 and 8.8.4.4 arguments for the dns-nameservers option
correspond to the name-server options arguments at resolv.conf. If the
resolvconf package is not installed, the /etc/resolv.conf file can be manually
modified (and if the /etc/network/interfaces is installed and not used to
configure DNS, the files found in /etc/resolvconf.d can be modified).
Expand with the manual sheet how local addresses (with localhost domain or
localhost.localdomain) and those indicated in /etc/hosts are resolved.
GNUFDL • PID_00290379 82 Linux administration
auto eno1
iface eno1 inet dhcp
The ip command (from the iproute2 package and replacing the traditional
ifconfig) allows configuring devices, establishing tunnels, routing rules, etc.
Below are a series of examples for network configuration for the ip command:
Another way to configure the network (recommended for users with mobility
and standard configurations) is through the Network�Manager (NM) package.
This package consists of a graphical interface (nm-connection-editor) for the
configuration of network devices (and it can coexist with the configurations
in /etc/network/interfaces) or can be configured through the files, taking
into account that the interfaces we want the NM to manage in /etc/
network/interfaces must be disabled. NM will not manage interfaces defined
in /etc/network/interfaces as long as /etc/NetworkManager/NetworkManager.conf
contains:
[main]
plugins=ifupdown,keyfile
[ifupdown]
managed=false
However, if we have a laptop computer that is used at different sites (e.g., home
and work) and we need different configurations for each site network, we can
use the logical interface definitions. Two logical interfaces, such as home and
work (instead of eno1 as previously done), must be defined first:
In this way, the physical eno1 interface can be activated for the home network
with ifup eno1=home and to reconfigure it for the work with ifdown eno1;
ifup eno1=work. The mechanism is very powerful and can be expanded
through configuration based on a series of conditions, using a mapping
section. The syntax of a mapping section is as follows:
mapping pattern
script name_script
[map script]
The script called in the mapping section will be executed with the name
of the physical interface as argument and with the content of all map lines
in the section. Before finalizing, the script will display the result of the
transformation by the standard output. For example, the following mapping
section will cause ifup to activate the eno1 interface as the logical home
interface:
mapping eno1
script /usr/local/sbin/echo-home
where /usr/local/sbin/echo-house is:
#!/bin/sh
echo home
This can be helpful if we have, for example, two different network cards (one
for home and one for work). If the ifupdown package is installed, the /usr/share/
doc/ifupdown/examples/ directory contains a transformation script that can be
used to select a logical interface, based on the MAC (Media Access Controller)
address. The script must first be installed in an appropriate directory with:
/etc/network/interfaces:
mapping eno1
script /usr/local/sbin/get-mac-address.sh
map 02:23:45:3C:45:3C house
map 00:A3:03:63:26:93 work
through a module called ipv6). Basic tools such as ping and traceroute have
their IPv6, ping6 and traceroute6 equivalents. At the basic level, with the
/etc/network/interfaces file, an IPv6 network is configured similarly to IPv4 (it
must be verified in advance that the available router supports IPv6 that relays
data to the global IPv6 network):
IPv6 subnets typically have a 64-bit network mask, which means there are 264
different addresses within the subnet and allows a SLAAC (Stateless Address
Autoconfiguration) method to select an address based on the MAC address
of the network interface. By default, if SLAAC is enabled on the network, the
kernel will find IPv6 routers automatically and configure network interfaces.
Red Hat and its derivatives (Centos, Rocky, Fedora,...) use a different file
structure for network configuration: /etc/sysconfig/network. For example, for
static network configuration:
NETWORKING=yes
HOSTNAME=my-hostname
Hostname defined by cmd hostname
FORWARD_IPV4=true
True for NAT firewall gateways and routers. False for any other case
GATEWAY="XXX.XXX.XXX.YYY"
Default gateway IP address.
NISDOMAIN=NIS-DOMAIN
DEVICE=eno1
BOOTPROTO=static
BROADCAST=172.16.1.255
IPADDR=172.16.1.2
NETMASK=255.255.255.0
NETWORK=172.16.1.0
ONBOOT= yes We will activate the network on the boot
TYPE=Ethernet
HWADDR=08:00:12:34:56:78
GATEWAY=172.16.1.1
IPV6INIT=no
USERCTL=no
PEERDNS=yes
DEVICE=eno1
ONBOOT=yes
BOOTPROTO=dhcp
GNUFDL • PID_00290379 87 Linux administration
The basic configuration of a Wi-Fi network has already been discussed in the
Introduction to Linux module, so this section will only give some additional
aspects about it. The configuration of Wi-Fi interfaces basically uses the
wireless-tools package (in addition to the iproute2 package and the ip
command). This package uses the iwconfig command to configure a wireless
interface, but it can also be done through the /etc/network/interfaces (some
distributions include the iw package, which is equivalent to iproute2, and
will replace wireless-tools; Debian, for example, includes both).
As a use case, it will be shown how to load the drivers of an Intel Pro/Wireless
2200BG card as a general method, but in current kernels these drivers are
already included in the kernel, so it is not necessary to perform these previous
steps although it serves as an example. Typically, the software that controls the
cards is divided into two parts: the software module that will be loaded into
the kernel through the modprobe command and the firmware, which is the
code that will be loaded onto the card and given by the manufacturer (see Intel
page for this model or Linux Wireless project https://wireless.wiki.kernel.org/
en/users/Drivers/iwlwifi). As we are talking about modules, it is interesting to
use the Debian module-assistant package, which allows us to easily create and
install a module (another option would be to install the fonts and create the
corresponding module). The software (found on the manufacturer’s page and
referred to as ipw2200) will be compiled and installed by using the module-
assistant m-a command package:
cp /tmp/fwr/*.fw /lib/firmware/
The module can then be loaded with modprobe ipw2200, the system is
rebooted and then the result of device initialization, or errors, if any, can be
seen with dmesg | grep ipw, (we can also check if it is loaded with lsmod):
• order (for compatibility only). It indicates the order of how the name
search will be performed (e.g., bind, hosts, nis).
• multi. It indicates that it can be on, so it will return all valid addresses for
a host that is in /etc/hosts file instead of just returning the first (off). On
can cause major delays when /etc/hosts is a big file.
• trim. It is designed to be used with local hosts and domains and may
appear more than once and should be followed by a list of domains,
separated by ‘:,;’ with a starting point and will automatically trim the given
domain name from the end of any host name resolved through DNS.
passwd: compat
group: compat
shadow: compat
hosts: dns [!UNAVAIL=return] files
networks: nis [NOTFOUND=return] files
services: nis [NOTFOUND=return] files
Where the first column is the database and the following are the service
specification, e.g., files, db, or nis and where its sequence is the order until
the result is obtained. Additional options can be indicated to take for a result
such as [NOTFOUND=return].
The ‘compat’ descriptor is similar to ‘files’ (files on the local machine) except
that it allows some additional words/options in local information files. The
files consulted when indicated as a ‘files’ service are those that have already
been discussed in this document and in the Introduction to Linux:
• aliases: /etc/aliases
• ethers: /etc/ethers
• group: /etc/group
• hosts: /etc/hosts
• initgroups: /etc/group
• netgroup: /etc/netgroup
• networks: /etc/networks
• passwd: /etc/passwd
• protocols: /etc/protocols
• publickey: /etc/publickey
• rpc: /etc/rpc
• services: /etc/services
• shadow: /etc/shadow
This file acts as a name server and is especially useful on a local network that
does not have high variability of the IPs assigned to the names (or private local
networks without private DNS server):
127.0.0.1 localhost
192.168.168.254 remix.nteum.local remix
# Private network nodes
192.168.168.1 nodo1.nteum.local node1
192.168.168.2 nodo2.nteum.local node2
# IPv6 hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
GNUFDL • PID_00290379 90 Linux administration
ff02::2 ip6-allrouters
Aliases can be used for a machine name, which means that machine can be
called in different ways for the same IP address.
For a system with defined IP, this line must be commented on and it is
advisable to put a domain of the fully qualified domain name (FQDN) type
(as the one that appears in the DNS) or if it is not necessary to insert one
defined as <host_name>.<domain_name> instead of just putting <host_name>
(for machines that do not have a record in a DNS, it is advisable to put as a
local domain, for example nteum.local or nteum.localdomain).
We do not need to, but we could add that all the packets in the network were
linked to the interface with:
Then we can see the result with ip route that will give information such as:
To determine where a packet will be routing for a given IP, we can run:
The next step in network configuration is the configuration of the servers and
services that will allow another user to access the local machine or its services.
Server programs will use ports to listen to client requests, which will be routed
to this service as IP:port.
There are some services that, although they could be put under the influence
of xinetd, but it is advisable either because of the delay in the booting (sshd
case) or because of the load that means booting and shutting it down in each
request, which would generate an extra unnecessary load on services with
many transactions. Daemons that are advised not to be under the influence
of xinetd include:
The configuration of xinetd is very simple and is done through the /etc/
xinetd.conf file (which may include more files from the /etc/xinetd.d/ directory
for better structuring). This file has a defaults section (parameters that will
apply to all services) and service section (or files for each service to be
configured), which will be the services that will be launched through xinetd.
A typical example of the configuration might be that defaults are placed on
xinetd.conf and the services are placed in separate files in the /etc/xinetd.d
directory, although, in this example, everything has been put together for
simplicity:
# xinetd.conf
# They apply to all servers and can be modified for each service
defaults
{
instances = 10
log_type = FILE /var/log/service.log
log_on_success = HOST PID
log_on_failure = HOST RECORD
}
# The service name must be in /etc/services to get the correct port
# If this is a non-standard server/port, use port = X
service ftp
{
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/sbin/proftpd
}
# SSH: although it is not recommended to put it under the control of xinetd but a
# possible configuration is provided.
service ssh
{
socket_type = stream
protocol = tcp
wait = no
user = root
port = 22
server = /usr/sbin/sshd
server_args = -i
}
id = echo-stream
socket_type = stream
protocol = tcp
user = root
wait = yes
}
# udp version of the ECHO service
service echo
{
disable = yes
type = INTERNAL
id = echo-dgram
socket_type = dgram
protocol = udp
user = root
wait = yes
}
The disabled services (lines start with #) will not be available and neither will
those with disable = yes. In the defaults section, we can insert parameters such
as the maximum number of simultaneous requests for a service, the type of
record (log) that we want to have, from which nodes we will receive default
requests, the maximum number of requests per IP that will be handled, among
others.
There must be one service section for each service, and it may contain
specific – and sometimes very detailed – parameters of the service. See man
xinetd.conf for more details.
1) Do not activate services that are not required in both /etc/xinetd.conf and
independent services (standalone). xinetd is not installed in most distributions
and if it is, the services must be analyzed and commented on or put disable =
GNUFDL • PID_00290379 95 Linux administration
yes. List the systemd managed services with systemctl list-units --type
service --all and disable them with systemctl disable name.service
(be careful with disabling services that are necessary for OS operation).
2) If an FTP service is installed (typically managed via xinetd), modify the /etc/
ftpusers file to deny that certain users can connect via ftp.
4) Disable services such as rlogin, rsh that are not encrypted and allow
access to the machine through the /etc/hosts.equiv file without having to enter
an access key (password). The functionality of these services is replaced by ssh
securely and in an encrypted way.
11.14. IP options
auto eno1
allow-hotplug eno1
iface eno1 inet static
address 192.168.1.42/24
gateway 192.168.1.1
auto eno1:0
allow-hotplug eno1:0
iface eno1:0 inet static
address 192.168.1.43/24
auto eno1:1
allow-hotplug eno1:1
iface eno1:1 inet static
address 192.168.1.44/24
Or also with the ip addr add command indicating the corresponding device.
Server configuration requires a little more attention, but does not present any
complications. The installation, for example, in Debian is apt-get install
isc-dhcp-server (it is one of the dhcp servers, but there are others such as
dnsmasq or kea). In general, dhcpd configuration can be done by modifying
the /etc/dhcp/dhcpd.conf file. An example of this file is:
# Example of etc/dhcp/dhcpd.conf:
default-lease-time 1200;
max-lease-time 9200;
option domain-name "remix.cat";
deny unknown-clients;
deny bootp;
option broadcast-address 192.168.11.255;
option routers 192.168.11.254;
option domain-name-servers 192.168.11.1;
mars host {
ethernet hardware 00:00:95:C7:06:4C;
fixed address 192.168.11.146;
option host-name "mars";
}
saturn host {
ethernet hardware 00:00:95:C7:06:44;
fixed address 192.168.11.147;
option host-name "saturn";
}
}
This will allow the server to assign the address range 192.168.11.1 to
192.168.11.254 as described by each node. If the corresponding host segment
{ ... } does not exist, they are randomly assigned. IPs are assigned for a
minimum time of 1,200 seconds and a maximum of 9,200 (if these parameters
do not exist, they are assigned indefinitely). On this server, we must also
modify the /etc/default/isc-dhcp-server file and modify the INTERFACESv4=
“eno2” line to indicate the interface where the requests will be received.
Finally, the service can be restarted with systemctl restart isc-dhcp-
server.
Since the DHCP protocol is performed via broadcast since the requesting
node does not have the network configured (discovery event generated by
the DHCP client), routing to other networks cannot be performed since the
DHCP protocol considers the server and client to be on the same network. To
get from one network to another where the dhcp server is located (and thus
avoid having to put one server for each subnet), an intermediate agent called
DHCP relay can be used. A DHCP relay operates on the machine that acts as an
intermediary for the dhcp broadcast packets. Its installation is through apt-
get install isc-dhcp-relay and it is configured with the /etc/default/isc-
dhcp-relay file by adding SERVERS= IP_DHCP__Server where IP_DHCP_Server
will be the IP of the dhcp server. The file contains other options, such as
defining the interface from which to listen to requests (if it is not indicated,
it is all of them), and another option is to send to the DHCP server.
The nodes that must be masqueraded will be within a second network and
each of these machines should have the address of the machine that performs
the masking as default gateway.
2) Activating masquerade:
In order for the changes to be permanent (and not have to be made after each
boot) it is recommended to install the iptables-persistent package (which will
save the iptables rules when the machine is turned off and will load them
when it is turned on) and to activate the ip_forward by modifying the file
sysctl.conf. We can run iptables -t nat -L to check that the iptables rule
is active. If the 10.0.2.0/24 network is connected to the Internet (obviously
through another NAT), the connectivity of the internal machines could be
verified by running, for example, ping google.com.
This is the simplest way with iptables, but it can also be done with the
command ip route add nat <parameters> to manage rules that route
and move addresses (this is called Stateless NAT).
11.18. Bridging
The bind configuration is not complex but requires dedication and in this
case a widely used DNS server called dnsmasq (and can also act with DHCP
server) has been chosen which is very simple and recommended for medium/
small installations. For the bind configuration, we can consult information
such as that of Linuxconf.org, among others.
The way to quickly configure a DNS for proprietary and forwarder domain
machines is to run apt-get install dnsmasq. If a simple DNS is
desired, then it is already configured considering that the /etc/resolv.conf file
(or equivalents) will have an external DNS server (for example nameserver
8.8.8.8).
The settings can be adjusted on the /etc/dnsmaq.conf file, but with the default
settings we can already query external domains and it will act as DNS-cache.
To complete the installation, a line with nameservers 127.0.0.1 must be
added as nameserver in /etc/resolv.conf (or equivalent service) before the other
nameserver so that the requests can be resolved first by this DNS and then
sent out. On machines where IP is obtained by DHCP and to prevent each
IP renewal from updating the resolv.conf, we can modify /etc/dhcp/dhclient.conf
and remove the comment to the prepend domain-name-servers 127.0.0.1 line;
which will add the indicated line each time the IP is renewed.
Dnsmasq will resolve the internal domains from the FDQNs of the /etc/
hosts machines such as for example if we have a line such as 192.168.1.37
remix.nteum.world remix, we can run host remix.nteum.world and it will
respond to us with the corresponding IP. The /etc/dnsmasq.conf configuration
file includes a number of options for organizing internal domains and other
parameters not only for DNS configuration but also for the DHCP server.
The NIS architecture is of the client-server type, i.e., there is a server that will
have all the databases and some clients that will query this data transparently
for the user. Therefore, the possibility of configuring “backup” servers (actually
called secondary) should be considered so that users are not blocked in case
the main server crashes. That is why the architecture is really called multi-
server (master+mirrors+clients).
To install the server on a machine (nis server) the nis package must be installed
(apt-get install nis). During the installation, a NIS domain will be
requested, under which it will group all the machines it will serve. It is
recommended that this NIS domain does not match the Internet domain or
host name. For example, if the server has name.domain=remix.nteum.world
it could be put as nis domain= NISREMIX (note that it is case sensitive, so
NISREMIX is different from Nisremix). This domain name can be queried
with the order nisdomainname, (or /proc/sys/kernel/domainname can also be
consulted) and can be reconfigured with dpkg-reconfigure nis. The /etc/
default/nis file must then be modified to modify the NISSERVER=master line
to indicate the server role. Also (although it can be done in a second step), the
/etc/ypserv.securenets file must be adjusted to modify the line indicating 0.0.0.0
0.0.0.0.0 that gives access to everyone and restrict it to the client network, for
example 255.255.255.0 192.168.1.0.
Finally, the /etc/hosts must be modified to have the machine with the name
defined in /etc/hostname (it can be changed/displayed with the hostnamectl
command) with an FQND line such as 192.168.1.30 remix.nteum.world remix.
It should be noted that from this point onwards, the commands to change
password or user information, such as passwd, chfn or adduser, are valid
only for changing local information. If we want to change NIS information,
commands such as yppasswd, ypchsh and ypchfn must be used. If users are
changed or local files are modified, NIS tables can be reconstructed by running
the make command in the /var/yp directory to update the tables.
The NIS client uses the ypbind command to find a server for the specified
domain, either via broadcast (not advised) or by searching for the server
indicated in the configuration file /etc/yp.conf (recommended). This file must
have a line with ypserver 172.16.1.1 where the IP is that of the master server
(this file supports different syntaxes and can be consulted with man yp.conf).
In order for a user who is not defined on the client machine to access through
the nis service, the /etc/nsswitch.conf file must be modified to include nis in
the following query bases (see man nsswitch.conf):
netgroup: nis
hosts: files dns nis
We can then restart the service with systemctl restart nis and verify if
it accesses the tables executing a ypcat passwd that will display the list of
users propagated from the server and with rpcinfo -p or with systemctl
status ypbind we will see the ypbind service active.
Although the autohome and automount can be configured for user directories,
it is recommended to mount the /home directory to the clients by NFS (this
will be seen in the next sections) so that users have access to their files on
each client machine.
SSH supports different authentication modes (see man ssh), for example, one
based on the RSA algorithm and public key. With the ssh-keygen -t rsa|
dsa command, we can create the user identification keys that will be saved
by default in the $HOME/.shh directory, the id_rsa and id_rsa.pub files, which
are the private and public keys, respectively. The user could copy the public
(id_rsa.pub) to the remote server with ssh-copy-id user@host_remote that
will include the public key in the user's $HOME/.ssh/authorized_keys file of
the remote machine. This file may contain as many public keys as sites from
which we want to connect to this machine remotely. Syntax is one key per
GNUFDL • PID_00290379 105 Linux administration
line although the lines will be of considerable size. After we have entered the
public keys of the user-machine in this file, this user will be able to connect
without password from that machine.
Normally (if keys have not been created), the user will be asked for a password,
but since the communication will always be encrypted, it will never be
accessible to other users who can listen over the network.
Both the client and server support multiple configurations that can be
changed from /etc/ssh/ssh_config and /etc/ssh/sshd_config (we must remember
to restart the server after changing files with systemctl restart ssh). On
the server, some of the most commonly used options are PermitRootLogin yes|
no to allow the root user to connect or not, IgnoreRhosts yes to avoid reading
the users' $HOME/.rhosts and $HOME/.shosts files, and X11Forwarding yes to
allow Xwindows applications on the server to be displayed on the client
screen (very useful in remote server management with the command ssh -X
host_a_administer command among others).
Very often, access to internal networks is only possible through an SSH server
(e.g., that are in the DMZ –demilitarized zone that is a physical or logical
subnetwork that contains and exposes an external service to untrusted users–)
and from this it is possible to connect to internal SSH servers and then reach
the machine of interest. The way to do this is to first connect to the M1, then
to the M2 (to which it is only possible to connect from the M1) and from it
to the M3 (to which it is only possible to connect from the M2). One way to
facilitate authentication is to use agent forwarding with parameter -A and by
setting the public key to all $HOME/.ssh/authorized_keys so when the different
commands are executed, the key request can be forwarded to the previous
machine and so on, the commands will be ssh -A m1.org and from this
ssh -A m2.org and in turn ssh -A m3.org but can automate with ssh
-A -t m1.org ssh -A -t m2.org ssh -A m2.org where the option
-t has been included for ssh to assign a pseudo-tty to it and only the final
screen will be displayed). The SSHmenu applet can help automate all these
types of commands.
Host m1
GNUFDL • PID_00290379 106 Linux administration
HostName m1.org
Host m2
ProxyCommand ssh -q m1 nc -q0 m2.org 22
Host new
Hostname 158.109.174.19
User root
ForwardX11 yes
ProxyCommand ssh -X [email protected] -p 223 -W %h:%p
The first command (when running ssh m1) will simply connect to m1.org but
the second command when running ssh m2 will establish an ssh connection
over m1 but the ProxyCommand command will use in nc command to
extend the connection over m2.org. Another way to use it is with the third
configuration when running ssh new will connect to router.uoc.edu with the
‘user’ user and port 223 and then to the IP indicated by Hostname and the user
indicated in User.
The NFS system allows a server to export a file system so that it can be used
interactively from a client. The latest version of NFSv4 includes a series of
additional daemons (idmapd, statd) as well as a series of modules for the new
functionality of this version.
To install (on Debian) the client must run apt-get install nfs-common
and the server with apt-get install nfs-kernel-server. The server is
managed through systemctl start|stop|restart|staus nfs-kernel-
server). The server uses a file (/etc/exports) to manage remote access and the
control of file systems.
On the client (or another user via sudo), the root can mount the
remote system via the mount -t nfs Ipserver:remote_directory
local_directory command and from this point on, the remote-directory
will be seen within the local directory (it must exist before running the mount).
This task on the client can be automated by using the /etc/fstab file including
a line, for example, Ipserver:/home /home nfs defaults 0 0 which indicates that
the /home directory of the Ipserver host will be mounted on the local /home
directory. In addition, this file system will be mounted with the default
parameters (see man mount section mount options for ntfs and man nfs for
specific options for NFSv4). The last two zeros indicate that the file system
should not be dumped and that the fsck will not be activated on it.
GNUFDL • PID_00290379 107 Linux administration
The /etc/exports file on the server acts as the ACL (Access Control List) of the
file systems that can be exported to the clients. Each line contains a filesystem
to be exported followed by the clients that can mount it, separated by blank
spaces. Each client can be associated with a set of options to modify behaviour
(see man exports for a detailed list of options). An example of this could be:
# Example of /etc/exports
/pub *(ro)
/soft 192.168.32.0/24(ro)
/home 192.168.10.0/24(rw,no_root_squash,no_subtree_check)
The first line exports the /pub directory to any client in read-only mode,
the second line exports the /soft directory to the 192.168.32.0/24 network
in read-only mode and the third line exports the /home directory to the
192.168.10.0/24 network in read-write (rw) mode, with no_subtree_check (it
indicates that the path/file verification will not be performed on a request on
the server) and no_root_squash (indicates that the root users of both machines
are equivalent).
Two useful commands for working with NFS are exportfs (shows and allows
to update the modifications that have been made) and nfsstat (that will
allow us to obtain NFS operation statistics).
A VPN is a network that uses the Internet as a data transport, but prevents it
from being accessed by members outside of it. Having a VPN means having
different nodes on different networks joined together on a single network
through a tunnel where encrypted communication packets are sent. It is used
when remote users are accessing a corporate network to maintain data security
and privacy. To configure a VPN, we can use a variety of SSH (SSL), CIPE, IPSec,
PPTP methods, among others.
A Debian machine and an Ubuntu machine will be used in this section, but
it is similar in all other distributions. OpenVPN must first be installed on
both machines: apt-get install openvpn. Depending on the distribution,
it may give some errors, as it tries to start the service, but since it is not
configured yet, it shows some warnings. Then, it must be tested in raw mode if
the connectivity between server and client works or if there is any impediment
(for example, a firewall). To check this, we must run:
To finish the application, we must simply do a Crtl+C (and we will see how
the tun1 virtual interface disappears as well). It must be noted that this mode
only allows for verification of connectivity but is not effective for stable
communication (see OpenVPN documentation).
To analyze this service, an OpenVPN option called VPN with pre-shared secret
will be used, which offers a simple way to configure an ideal VPN for testing
or point-to-point connections. Its advantages are simplicity and that an X509
PKI certificate is not required to maintain the VPN. The disadvantages are that
GNUFDL • PID_00290379 109 Linux administration
it only allows one client and one server. By not using the PKI mechanism
(public key and private key), the key must exist in each peer and must have
been previously exchanged through a secure channel.
We must remember that in this example the VPN tunnel will have over the
IP=10.9.8.1 server and the client with IP=10.9.8.2. The communication will
be encrypted between the client and the server over UDP port 1194 (which is
the default OpenVPN port). After installing the package, the static key must
be generated in /etc/openvpn and copied securely to the client:
cd /etc/openvpn
openvpn --genkey --secret static.key
scp static.key [email protected]:/etc/openvpn
In this case, the secure copy (scp) command has been used to transfer the
static.key file to the client (10.9.8.2) over a secure channel. The /etc/openvpn/
tun0.conf server configuration file:
dev tun0
ifconfig 10.9.8.1 10.9.8.2
secret /etc/openvpn/static.key
remote 10.9.8.1
dev tun0
ifconfig 10.9.8.2 10.9.8.1
secret /etc/openvpn/static.key
Before verifying the VPN operation, we must ensure on the firewall that the
1194 UDP port is open on the server and that the tun0 virtual interface used
by OpenVPN is not blocked on either the client or the server. It must be taken
into account that 90% of connection issues encountered by new OpenVPN
users are related to the firewall.
To verify OpenVPN between two machines, run both on the server side and
on the client side (--verb 6 will display additional information to the output
and it can be avoided in subsequent runs):
This will give an output that will end with something similar to Initialization
Sequence Completed. To verify its operation, for example, a ping 10.9.8.1 can be
executed from the client, so we will see its response and also a message of the
tunnel activity in the server console.
GNUFDL • PID_00290379 110 Linux administration
To add compression over the link, the following line must be added to the
two full configuration comp-lzo files, and to protect the connection via a
NAT router/firewall and follow the IP changes via a DNS, if one of the peers
changes, add to the two configuration files:
keepalive 10 60
ping-timer-rem
persist-tun
persist-key
Once the rules are configured, we can check the open services/ports, for
example, from another machine, with a tool such as nmap that will display
the open ports on the machine configured with iptables.
To create the pair of keys, we must run gpg --gen-key by answering its
questions. To display the keys created, we must run:
gpg --list-keys
or
gpg -v -fingerprint
which will result in key information. The next thing is to create a revocation
certificate because, although it is not important now, when the public key is
on a server and we want to destroy it (for different reasons), the only way is to
revoke it. To do this, we must execute gpg -a --gen-revoke and copy the
information between [BEGIN] and [END] into a file and keep it safely, since it
can annul the public key. The public key must then be “public” on a server,
such as pgp.mit.edu, by running
where the last number is the KEY_ID obtained from the key. To incorporate a
public key of another user into our key-ring, we will
GPG solves the issue of the need for key exchange in advance with the public
and private key mechanism, but this brings a new problem: if someone’s
public key is received (e.g., from a key server), how do we know that this key
actually belongs to the person to whom it is said to belong? Anyone could
create a key in someone else’s name and use it, and no one would realize
there’s a phishing!
GNUFDL • PID_00290379 112 Linux administration
That’s why care must be taken when accepting other keys and ensuring that
the key is from a certain person and that it is secure (checking it with the
Key-ID and fingerprint). An easy mechanism is to sign a key and the more
known users sign this key, the more (everyone) will be sure that it belongs to
the user they know (this is called key-signing). A user can sign another key
(with theirs) to ensure that that key belongs to someone that they are sure of
who it is, and also if a public key is received from someone they do not know
but it is signed by several people who they know, then this key can be trusted
to belong to that person (trust).
To sign a public key it must be in the key-ring and execute the command gpg
--edit-key <description>, where “description” can be the name/email or
any data or part of the key we want to sign. Then it will enter command mode
and sign -> confidence level (0-3) -> Y -> passwd -> save should be indicated.
Subsequently, this public key should be uploaded back to the server with the
new signature: gpg -a --send-keys <key-ID>. To update the keys that we
have in the local (key-ring), we must run gpg --refresh-keys. To encrypt
a file, we can run gpg -e -a -r <description> file, which will be
called file.asc; since the -a that indicates that the output must be ASCII has
been included, if it does not exist, it will be generated in binary as file.gpg. To
decrypt, gpg -d -or file.asc output_file must be done, which will
request the passwd and generate it in output_ file.
This tool allows for a full configuration of the filters and rules can be classified
as “intrusion attempt” (cracking), stored in /etc/logcheck/cracking.d/; “security
alert” stored in /etc/logcheck/violations.d/, and those that are applied to the rest
of the messages.
GNUFDL • PID_00290379 113 Linux administration
Given the importance of analyzing where the packages come from and where
they are going, some common tcpdump commands will be displayed:
8)�Other�tools:
Local security is essential for system protection, as, typically, after a first
attempt to access from the network, it is the second barrier of protection before
an attack manages to gain part of the control of the machine. In addition, most
attacks end up using internal system resources. In this section, the different
points of risk will be analyzed.
1)�Bootloaders. This is the first risk point if an intruder has physical access
to the machine. One of the problems is whether the attacker can boot from
removable devices (for example USB) as it could access the data of a GNU/
Linux partition (or also in Windows environments) just by mounting the
file system and could be placed as a root user without needing to know any
passwords. Or he/she could also access to modify the kernel boot form so that
it doesn’t ask for the password. For the first case, it is necessary to protect the
system boot from the BIOS, for example, by protecting password access, so
that boot from USB or other external connections is not allowed.
The next step is to protect the bootloader, (typically Grub2) so that the attacker
cannot modify the core boot options or directly modify the boot. In the
case of Grub 2, it is possible to do this by using menuentry, available in the
configuration, by defining passwords for specific users, which can then be
added to each defined menuentry, in addition to the possibility of specifying
a super user who has access to all the entries. Grub2 uses passwords in clear,
so we must make sure that the file does not have read access for other users, or
instead use alternative methods for password creation, for example, by using
grub-mkpasswd-pbkdf2, which will allow us to generate hashes of the password
to be used. Configuration details can be seen in Grub2/Passwd.
The sticky bit is used primarily in temporary directories, where we want any
user to be able to write, but only the owner of the directory or the owner of the
file in the directory (e.g., /tmp)can delete it. Care should be taken that there
are no directories of this type, as they can allow anyone to write on them, so
it should be checked that there are no more than those purely necessary as
temporary. The bit is placed by (chmod +t dir) and can be removed with the
option -t. In a ls it will appear as a directory with drwxrwxrwt permissions
where the last letter is a t.
GNUFDL • PID_00290379 116 Linux administration
The setuid bit (or setgid) allows a user to run (either an executable binary
program or a shell script) with the permissions of another user. This may be
useful in some cases, but it is potentially dangerous especially in the case
of scripts, as they could be edited and modified to perform any task. These
programs need to be controlled and if setuid is not needed, it should be deleted.
The bit is placed by chmod +s, either by applying it to the owner (then called
suid) or the group (it is called bit sgid); it can be removed with -s. In the case
of viewing with ls, the file will appear with -rwSrw-rw (an S instead of an
x), if it is only suid, in sgid the S would appear in the second w.
It is also possible to detect programs that are running with suid permissions,
using ps ax -or pid,euser,ruser,comm where if the effective user (euser)
and the real user (ruser) do not match, it will surely be an executable or script
with suid permissions.
4)�Hosts. There are a number of special configuration files that enable access
to a series of hosts for some network services, but whose errors can allow local
security to be attacked later. Examples of this are .rhosts in the user directory,
/etc/hosts.equiv, /etc/hosts.lpd, among others.
5)�PAM. PAM modules are a method that allows the administrator to control
how the user authentication process is performed for certain applications.
Applications must have been created and linked to PAM libraries. PAM
configuration is present in /etc/pam.conf (maintained for compatibility)
and in the /etc/pam.d directory, where one PAM configuration file appears
for each application that is using PAM modules. For its configuration, see How
to Configure and Use PAM in Linux.
The same process can be done with a user, although because their permissions
are more limited, it may not affect the system as much, but the user’s own
security instead. Another typical case is the fake login screens, which can
replace the typical login, passwd, process, with a fake program that stores
the entered passwords.
To control this problem, limits can be entered to some of the resources used
with the ulimit command (current values can be seen with ulimit -a),
although the global configuration of limits is maintained in the /etc/security/
limits.conf file. In fact, these limits, which can be imposed on CPU time,
maximum number of processes, amount of memory, are read by PAM modules
during the user login process, and set by default from the limits imposed on
each user. Not setting limits and using default behaviour can make the system
‘fall’ with some ease: a user can easily create a script called a Fork Bomb whose
code is available in various languages and crash the system if there are no set
limits (for example, put the limits.conf on a line with * hard nproc 128
to limit the number of processes to 128 for all users and it can be checked with
limit -a in the user's account).
These techniques are used in conjunction with the compiler (e.g., GNU gcc),
using a series of parameters and options (flags) passed in compile time,
whether for the compilation of user applications, service clients or the service
server part (daemons), which from their code sources and the compile process
are protected against various attack techniques on the executables.
In Debian, the complementary utilities and files can be installed for the
compilation process, in addition to having the hardening-check utility,
which allows checking the protections that a certain command, application or
daemon has. We simply need to install the apt-get install hardening-
wrapper hardening-includes packages and then check the daemon/
service, for example, to check sshd hardening-check /usr/sbin/sshd.
TCP wrappers is a software that runs prior to the service that manages and
verifies an access control rule, typically listed at /etc/hosts.allow and /etc/
hosts.deny. This wrapper can function as a previous service (tcpd) and if it
verifies the access rules, it calls the corresponding service (option used in the
already obsolete inetd) or its libraries can be integrated into the daemon/
service code itself (for example, xinetd or sshd).
To know if the corresponding binary has the libwrap reference included, for
example the sshd daemon, ldd /usr/sbin/sshd | grep libwrap can be
run which will show whether it has the library or not (in Debian branches it
is included).
Technically, the best solution is to have a computer with two or more network
cards that isolate the different connected networks (or network segments), so
that the firewall software on the machine (or if it is a special hardware) is
responsible for connecting the network packets and determining which ones
may or may not happen, and to which network.
The iptables system manages different tables where the most used/
important ones are NAT and FILTER, which in turn contains different CHAINS,
where the rules are associated. The FILTER table is for the filtering standards
themselves, and the NAT table for address translation.
The iptables -L command lists the active rules (if -t filter or -t nat are
not indicated, it lists the rules of the filter table by default) in each chain.
The chains by default in FILTER are INPUT (for packets intended for local
sockets), FORWARD (for packets being forwarded through this machine), and
OUTPUT (for packets generated locally). For the NAT table, the default chains
are PREROUTING (to modify packets before entering the machine), INPUT
(to modify packets intended for local sockets), OUTPUT (to modify packets
generated locally after routing), and POSTROUTING (to modify packets that
will leave).
The typical configuration of the FILTER table is a series of rules that specify
what is done within a given chain through an iptables -A string -
parameters -j action command. The -A option adds the rule to the
existing ones and -j indicates what to do with the package that can be accept
(accept it), reject (reject it) or drop (delete it). The difference between reject and
drop is that the latter sends a connection error not allowed while the first (drop)
GNUFDL • PID_00290379 120 Linux administration
does not, so if the first one is used, an attacker already knows that there is a
service but that cannot access while the second one is considered safer since
an attacker does not know if there is a service or not.
It should be noted that the order matters so the least restrictive rules must be
placed at the beginning, since if a rule is first put that deletes the packages it
will no longer be available for the next ones. There are a set of default rules
(public rules) that apply when there is no specific rule for a given package
and they can be ACCEPT or DENY, that is, if none of the package rules can
be applied to the package and the default rule is ACCEPT, the package will be
accepted and if the default rule is DENY, the package will be deleted. A default
rule of DENY all would be:
which means that no package that does not meet any of the active rules will
pass and that there must be one from both INPUT and OUTPUT for the same
package. A policy of ACCEPTING all would be:
In which if the package does not satisfy any of the subsequent active rules, it
will end up accepting, so this type of configuration (less paranoid) ends with
a last iptable rule -A INPUT -s 0.0.0.0/0 -j DROP (that is, when all
the rules are passed and there is none that satisfies the package, it is deleted).
A typical strategy in environments that are not very hostile is a default policy
of ACCEPT all, a set of rules that filter packets to services and end with a DROP
rule to the rest of the packages. Examples of these Filter table rules could be:
Where:
Regarding protocol and port names, the iptable system uses the information
provided by the /etc/services and /etc/protocols files, and the
information (port and protocol) can be specified numerically or by name (we
must be careful, in this case, that the information in the files is correct and
that they have not been modified, for example, by an attacker).
*filter
# Allow all loopback traffic (lo0) and deny the rest of 127/8
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
# Accept all pre-established incoming connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Accept all output traffic
-A OUTPUT -j ACCEPT
# Allow HTTP and HTTPS from anywhere
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
Allow SSH connections
# It normally uses port 22, check in file /etc/ssh/sshd_config.
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
# Reply to ping icmp
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
# Remove remaining incoming traffic.
-A INPUT -j DROP
-A FORWARD -j REJECT
COMMIT
In this example, ping, http, htpps, ssh incoming traffic is accepted and
the remaining incoming traffic is blocked. When it comes to output traffic,
everything is allowed out without restrictions. To test its functionality from
another machine, run for example nmap, which will show us the open ports
on the machine configured with iptables.
GNUFDL • PID_00290379 122 Linux administration
In the RHEL branch and its derivatives, the firewall by default is firewallD
(although it is possible to install iptables). It provides dynamic control of
the firewall and allows multiple zones to be defined to manage the various
networks to which the system is connected. It allows us to simultaneously
maintain permanent, runtime configurations and apply new rules without the
need to restart the entire firewall. Some useful commands in this case that
allow us to get status, supported services, enable a service, get zones and zones
with enabled services:
firewall-cmd –-state
firewall-cmd --get-services
firewall-cmd --add-service=http
firewall-cmd --get-zones
firewall-cmd --list-all-zones
• Tables and chains are fully user configurable, unlike iptables, which is
based on a predefined table structure.
As for the paths that the packages follow, they continue to have the same
structure (of hooks, in Netfilter terminology): when a package arrives at the
system, it goes through a prerouting, then accessing a routing decision (is it
an entry package for the system or forwarding to others?); if the system is
forwarded (because it works as a router), the package will arrive at postrouting
and exit the system, depending on the routing options. If it is the opposite
case, and the package was for the system, it will move to INPUT, it will be
processed by the system, which can generate output packages, OUTPUT, which
after a routing decision (is it for the system itself or for external network?), will
arrive at postrouting to exit the system.
The first step in ntables is to create the chains as they are not defined:
Create Table:
nft add table ip filter
List tables:
nft list tables ip
List chains associated with a table (initially they will not be created):
nft list table ip filter
Delete a table
nft delete table filter
Flush from a table (release table rules):
nft flush table ip filter
Add a base chain (related to a Netfilter Hook discussed above), this chain will see the Linux
TCP/IP stack packets, input and output examples, and third case a non-base chain.
With delete or flush instead of add, the rules are deleted (or flush):
nft add chain ip filter input { type filter hook input priority 0 \; }
nft add chain ip filter output { type filter hook output priority 0 \; }
nft add chain ip filter test
Rules: list them (options -n disable resolution names, -nn service resolution), a rule for a
particular port, a rule to a particular previous position within the chain, save rules of a
chain in a file, load them from filter-tble file
nft add rule filter output tcp dport ssh counter
nft add rule filter output position 8 ip daddr 127.0.0.8 drop
nft list table filter > filter-table
GNUFDL • PID_00290379 124 Linux administration
nft -f filter-table
In this section, some of the typical GNU/Linux services will be installed, such
as an HTTP/HTTPS server and proxy servers. The range of services that can be
provided with GNU/Linux is very wide, but for space reasons it will only be
limited to the installation and configuration of the most interesting options
of these two services. Interested readers can consult a chapter dedicated only
to servers, which although it is outdated, the main concepts and methodology
have not changed:
CAT: https://openaccess.uoc.edu/handle/10609/60685.
SPA: https://openaccess.uoc.edu/handle/10609/60686
Apache is one of the most popular servers with HTTP (HyperText Transfer
Protocol) capabilities. Apache has a modular design and supports dynamic
extensions of modules during execution. It is highly configurable in terms
of the number of servers and modules available and supports various
authentication mechanisms, access control, metafiles, caching proxy, virtual
servers, etc. With the inclusion of modules it is possible to have PHP, Perl,
Java Servlets, SSL and other extensions that can be consulted on the developer
website.
While all default parameters have functional values, it should be noted that
the ServerName variable is not defined in the default installation and should
be configured in /etc/apache2/apache2.conf or in the site configuration files
within the Virtualhost tag as ServerName srv.nteum.org.
• apache2.conf is the main configuration file where the server features are
defined functionally and the corresponding configuration files (ports,
conf.d, sites-enabled) are called.
• ports.conf defines the ports where the incoming connections will be served,
and which of these are used on virtual hosts (80 for http and 443 for https
by default).
• The envvars file is the one that contains the definition of the environment
variables and it is necessary to basically modify USER/GROUP that will be
the one used for execution and for obtaining the permissions. The user
www-data and the group www-data are created by default (although they
can be changed).
GNUFDL • PID_00290379 127 Linux administration
Virtual servers are isolated sites that will each be served independently of each
other with their own files and configuration. First, the default site must be
disabled with a2dissite 000-default.conf. The sites we will create will
be remix.world and lucix.world which will have two configuration files in the
directory /etc/apache2/sites-available/.
Contents�of�file�/etc/apache2/sites-available/remix.world.conf
<VirtualHost remix.world:80>
ServerAdmin adminp@localhost
ServerName remix.world
ServerAlias www.remix.world
DocumentRoot /var/www/html/remix/
ErrorLog ${APACHE_LOG_DIR}/remix-error.log
CustomLog ${APACHE_LOG_DIR}/remix-access.log combined
</VirtualHost>
Content�of�file�/etc/apache2/sites-available/lucix.world.conf
<VirtualHost lucix.world:80>
ServerAdmin adminp@localhost
ServerName lucix.world
ServerAlias www.lucix.world
DocumentRoot /var/www/html/lucix/
ErrorLog ${APACHE_LOG_DIR}/lucix-error.log
CustomLog ${APACHE_LOG_DIR}/lucix-access.log combined
</VirtualHost>
GNUFDL • PID_00290379 128 Linux administration
This setting is basic and the student should refer to the developer web page
for detailed information. As can be seen, the root directories for each domain
will be in /var/www/remix|lucix and the log files in /errors/accesses in
<html><body><h1>REMIX: It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
And the same for lucix.world but changing the line at <h1></h1>. No action
should be taken for the logs as the directory /var/log/apache2 already exists
and the files will be created by the server. Finally, the sites must be activated
(creating the link from sites-available to sites-enabled) with
192.168.1.37 remix.world
192.168.1.37 lucix.world
Then from a browser on the same machine (as otherwise no domain/IP will
be visible) or from another machine on the same network to which the /etc/
hosts has been modified, the URL remix.world can be entered and the result
will be the index.html display that will show: REMIX:�It�works�
For example, apt-cache search libapache2* can be done to get the list
of modules available for Apache, and to install apt-get install [module-
name] which will be available for use (remember that some additional
configuration in the site files may be necessary). With ls -al /etc/
apache2/mods-available/ we can look at the available ones and install
them with a2enmod [module-name]. To list the loaded modules, we can
execute apache2ctl -M which will list the dynamically loaded ones with
shared and those that are compiled with the server with static (these can also
be obtained with apache2 -l). Modules in the mods-available directory have
.load (indicates the library to load) and .conf (additional module configuration)
GNUFDL • PID_00290379 129 Linux administration
extensions but when using the a2enmod command, only the name of the
module without extension should be indicated. To disable a a2dismod
module[module-name].
The remix.world.ssl.conf file is then edited (only the main/modified lines are
displayed):
<VirtualHost _default_:443>
...
DocumentRoot /var/www/remix.ssl
...
ErrorLog ${APACHE_LOG_DIR}/remix.world.ssl_error.log
CustomLog ${APACHE_LOG_DIR}/remix.world.ssl_access.log combined
...
SSLEngine on
SSLCertificateFile /etc/ssl/private/remix.crt
#SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
...
</VirtualHost>
<Directory /var/www/html/auth>
GNUFDL • PID_00290379 130 Linux administration
AuthType Basic
AuthName “Basic Authentication”
AuthUserFile /etc/apache2/.htpasswd
require valid-user
</Directory>
<VirtualHost authpam.nteum.org:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/auth-pam
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
13.3. Proxies
Apache is a very versatile and efficient http server that has a large number
of modules that extend its functionality, including the proxy module. In
this section, the configuration will be analyzed first as a reverse proxy to an
internal server. This reverse proxy service will then be expanded to balance
the load to more than one server by redirecting requests based on different
policies. Apache supports different proxy modules, among which we can
mention: mod_proxy (multi-protocol proxy), mod_http (http support for
proxy), mod_cache, mod_proxy_html (rewrite HTML links to ensure they
work outside the proxy), mod_proxy_balancer (balance for reverse proxy),
lbmethod_bytraffic (for traffic load balancing) lbmethod_byrequests (request
load balancing), among others. The steps to be followed will be:
<VirtualHost proxy.nteum.org:80>
ServerName proxy.nteum.org
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://mig.nteum.org/
ProxyPassReverse / http://mig.nteum.org/
</VirtualHost>
Where:
• ServerName must be set to /etc/hosts, and indicates how we will call the
input server (it has also been put into VirtualHost).
GNUFDL • PID_00290379 133 Linux administration
• ProxyRequests Off prevents this from being used as an open proxy, that
is, users can go to the proxy and from there to any other address and it is
very important to leave it disabled to avoid security or even legal issues.
• ProxyPreserveHost On allows the jump from the proxy server to the backend
server to be transparent to the user (if it was not enabled, the user would
go to http://proxy.nteum.org but immediately would see how the address
changes to http://mig.nteum.org, which is the internal server –backend–)
and if the backend server is also not visible from the external network the
client would see an error.
• ProxyPass and ProxyPassReverse manage the jump and return from frontend
to backend server (mig.nteum.org) The domain of the backend server can
be changed by the server lp if this domain is not defined in /etc/hosts of
the proxy server.
One of the interesting aspects of the web service is being able to load balance
requests on different servers to avoid the “bottleneck” effect on the service
and improve response time and increase the number of requests handled
per unit of time. This can be done using specific hardware or a reverse
proxy (frontend) that distributes the load to a set of servers (backends)
in accordance with a given policy. Apache has an additional module to
the proxy (mod_proxy_balance) that allows load balancing on a web server
set and different modules to implement policies (lbmethod_byrequests,
lbmethod_bytraffic lbmethod_bybusyness, lbmethod_heartbeat).
<VirtualHost proxy.nteum.org:80>
ProxyRequests off
ServerName proxy.nteum.org
GNUFDL • PID_00290379 134 Linux administration
DocumentRoot /var/www/html
<Proxy balancer://mycluster>
BalancerMember http://172.16.1.2:80
BalancerMember http://172.16.1.3:80
Options Indexes FollowSymlinks Multiviews
AllowOverride None
Order Allow,Deny
Allow from all
#ProxySet lbmethod=bytraffic
ProxySet lbmethod=byrequests
</Proxy>
# Enable Balancer Manager
<Location /balancer-manager>
SetHandler balancer-manager
Order deny,allow
Allow from all
</Location>
ProxyPass /balancer-manager !
ProxyPass / balance://mycluster/
ProxyPassReverse / balancer://mycluster
ProxyPass / http://172.16.1.2
ProxyPassReverse / http://172.16.1.2
ProxyPass / http://172.16.1.3
ProxyPassReverse / http://172.16.1.3
</VirtualHost>
Here the IPs of the nodes that will act as Backend have been put but they could
be given as names in /etc/hosts.
The balance manager is a tool that integrates the module and will allow us to
easily see the statistics of the module activity and some modifications (simple
as well). That is why requests to http://proxy.nteum.org/balancer-manager should
not be redirected and addressed by the proxy.
• Load the modules (if they are not loaded, and check apache2ctl -M):
a2enmod proxy proxy_http
<VirtualHost *:80>
ServerName www.nteum.org
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyRequests On
<Proxy “*”>
Requires ip 172.16.
</Proxy>
ProxyBlock “www.site1.com” “www.site2.com”
#ProxyBlock *
</VirtualHost>
CacheEnable disk /
CacheRoot "/tmp/cache"
CacheQuickHandler off
CacheLock on
CacheLockPath /tmp/mod_cache-lock
CacheLockMaxAge 5
GNUFDL • PID_00290379 136 Linux administration
CacheHeader On
• The ProxyBlock sentence will allow an access control policy and prevent
clients from accessing the indicated websites (blocking).
There are other aspects of cache over Apache that have not been treated as
File Caching to accelerate access to the files served by Apache and Key-Value
Caching used by SSL and authentication caching that can be consulted on the
developer’s web.
HAProxy is a very fast and reliable reverse proxy that offers high availability,
load balancing and proxy for TCP and HTTP based applications and is well
suited for very high traffic websites. This server has become the de facto proxy
balancer and is included in the repositories of most Linux distributions with
very active development (2 versions per year) and new functionalities in each
major revision.
GNUFDL • PID_00290379 137 Linux administration
Activities
1. For RPM packages, how would some of the following tasks be done?
2. Perform the same task as in the previous activity, but for Debian packages, using the APT
tools.
4. Install in the available distribution some generic administration tool, such as Webmin.
What does it offer? Is it easy to understand the executed tasks and the effects they cause?
5. The swap space allows to complement the physical memory to have more virtual memory.
Depending on the sizes of physical memory and swap, can memory run out? Can it be solved
otherwise, other than by adding more physical memory?
6. Assume we have a system with two Linux partitions, one is ‘/’ and the other is swap. How
would we fix the fact that users’ accounts ran out of disk space? And if we had an isolated
partition /home that was running low, how would we fix it?
7. Analyze the systemd system. What services and groupings does it have predefined? Is
there compatibility with the SystemV init (sysvinit)? How are services managed? How do we
change target?
8. Examine default GNU/Linux system settings for non-interactive tasks by cron (or systemd-
cron). What tasks are they and when are they going to be executed? How are new user tasks
added?
• Isolated machine.
• Small local network (4 machines, 1 gateway).
• 2 segmented local networks (2 sets of 2 machines, one router each and one general
gateway).
• 2 interconnected local networks (two sets of 2 machines + gateway each).
• A machine with 2 interfaces, one connected to the Internet with NAT to a router and
another to a private network1, a second machine with two interfaces connected to a
private network1 and the other to a private network2, a third machine connected to a
private network2.
• 2 machines connected over a virtual private network.
10. Using virtual machines, perform the configuration and monitoring and connection test
(for example, ping, dig and apt-get update) of the proposals from the previous point
and on each machine of the proposed architecture.
11. Perform the above experiments on IPv6 using ping6 and one of the tunnels mentioned
in the Network/IPV6 section to show connectivity to the Internet.
13. Configure a NIS server/client with two machines by exporting the server user directories
by NFS.
14. Configure an SSH server to access from another machine without a password.
GNUFDL • PID_00290379 138 Linux administration
Bibliography
All links were last accessed in May 2022.
[IET] IETF. Request For Comment repository developed by Internet Engineering Task Force
(IETF). https://www.rfc-editor.org/rfc/
[Mou01] Mourani, Gerhard. Securing and Optimizing Linux: The Ultimate Solution. Open
Network Architecture, Inc. 2001. https://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-
The-Ultimate-Solution-v2.0.pdf
[Nem] Nemeth, Evi.; Snyder, Garth, author; Hein, Trent, Unix and Linux System
Administration Handbook. O’Reilly. 2010. UOC Library.
[Qui] Quigley, E. (2001). Linux shells by Example. Prentice Hall. UOC Library.
[Soy] Linux administration: a beginner’s guide. Soyinka, Wale. McGraw Hills/O’Reilly. 2016.
UOC Library.