Linux Networking 101
Linux Networking 101
Linux
Networking 101
David M. Davis
I N S I D E T H E G U I D E:
• Discover how Linux continues its march toward world
domination
In Partnership With
THE GORILLA GUIDE TO...
All rights reserved. This book or any portion thereof may not be reproduced or used
in any manner whatsoever without the express written permission of the publisher
except for the use of brief quotations in a book review. Printed in the United States
of America.
ACT UA LT E C H M E D I A
6650 Rivers Ave Ste 105 #22489
North Charleston, SC 29406-4829
www.actualtechmedia.com
PUBLISHER’S
ACKNOWLEDGEMENTS
E D ITO R S
Hilary Kirchner, Dream Write Creative, LLC
Christina Guthrie, Guthrie Writing & Editorial, LLC
P R O J E CT M A N AG E R
Wendy Hernandez, ActualTech Media
E X E C U T I V E E D ITO R
James Green, ActualTech Media
L AYO U T A N D D E S I G N
Olivia Thomson, ActualTech Media
iii
ENTERING THE JUNGLE
Introduction 8
Six Reasons You Need to Learn Linux 10
1. Linux is the future 10
2. Linux is on everything 11
3. Linux is adaptable 11
4. Linux has a strong community and ecosystem 11
5. Linux is fun! 11
6. Linux is open-source and sometimes free 12
The Components that Comprise the Linux Operating
System? 15
What Is a Distribution? 17
Understanding User Space vs. Kernel Space 18
Benefits of Using Linux 19
How Is Linux Used in the Enterprise? 20
Summary 22
iv
Linux Processes, Programs, and Services 37
Importance of Linux Log Files 40
Users and Super Users 41
Files and Permissions 43
v
Two Links Are Better Than One 89
IP Fabrics Are Easy 89
BGP EVPN—L3 Network Virtualization for Network Engineers 92
vi
CALLOUTS USED IN THIS BOOK
vi i
ICONS USED IN THIS BOOK
D E F I N IT I O N
Defines a word, phrase, or concept.
KNOWLEDGE CHECK
Tests your knowledge of what you’ve read.
PAY AT T E NT I O N
We want to make sure you see this!
GPS
We’ll help you navigate your knowledge to the
right place.
WATC H O U T!
Make sure you read this so you don’t make a
critical error!
vi i i
INTRODUCTION
Modern data centers are vastly different from legacy ones, and with
good reason. In the past, companies typically supported a handful
of critical monolithic applications, and the network was put in
place primarily to support just those applications. Once installed,
the network was left mostly untouched in many organizations. It
consisted of dedicated hardware-based routers and switches that, for
the times, performed their tasks of routing and switching packets
quite well. The routers and switches favored by many enterprises
typically came from one of the “big 3” networking vendors, but their
products generally included costly appliances made up of custom
hardware and highly proprietary software. That network gear was so
specialized that an entire ecosystem sprang up around it to provide
training, education, certification, consulting, software and support
maintenance, and more.
Over time, the data center landscape has changed — and for the
better, particularly given that the application landscape has also
morphed into something radically different from what was seen
in the past. The number of business-critical applications is on the
rise, and, unlike their older stay-at-home cousins, modern appli-
cations are distributed between on-premises infrastructure, partner
networks, and across the public cloud. End user and company data
moves around the globe at light speed, and it’s happening constantly.
New applications are being built today and torn down tomorrow in
favor of even newer applications. Change is happening fast, and the
network is adapting to support these changes.
The key piece of the previous paragraph and the focus of this book is
this: Linux networking is the future for almost every use case. But to
leverage a Linux-based networking solution, you need to understand
Linux, and that’s where this book comes in.
DEFINITIONS ABOUND!
If you don’t know what some of these words mean,
don’t worry! We’ll define them during your Linux 101
journey. By the end of this book, you’ll be using these
phrases in casual conversation!
I ntroduction 10
2. Linux is on everything
Linux runs more than two-thirds of the servers on the Internet, all
Android phones, most consumer network gear, such as NetGear and
Linksys devices, 99% of the top supercomputers in the world, many
Internet of Things (IoT) devices, Tesla cars, and even PlayStation
gaming consoles.
3. Linux is adaptable
The very reason that everything is on Linux is because it’s such an
adaptable operating system. Thanks to Linux’s modularity and open-
source nature, you can choose the pieces you need for your product
or service and develop any pieces that may not already exist. You
can install tiny versions of Linux for specialized use cases (such as
operating water sprinklers in the gorilla exhibit at the zoo), modify
it to work on appliances that route packets across a large enterprise
network, or use it as your desktop operating system. Your choices are
practically endless.
5. Linux is fun!
Linux is a lot of fun because you can do just about anything with it.
Linux is commonly used in Internet of Things (IoT) projects; it runs
on tiny Raspberry Pi computers commonly used by hobbyists, and
it even makes a great operating system on your laptop or desktop
I ntroduction 11
computer. More examples of the many uses of Linux are found
throughout the book.
Turn to the first chapter in this Gorilla Guide and find out the answer
to the burning question: What is Linux?
I ntroduction 12
CHAPTER 1
What Is Linux?
As you get started learning about Linux, you’ll likely have many of
the same questions that thousands of other people have had since the
beginning of Linux time. For that reason, we’ll start this chapter by
answering the most common questions about Linux.
W hat I s L inux ?
14
Figure 1-2: How an operating system works with hardware and applications
W hat I s L inux ?
15
Figure 1-3: Example of a common Linux distribution
W hat I s L inux ?
16
DEFINITION: METADATA
Metadata is data about data. In essence, metadata de-
scribes the kind of information that an underlying data
set will store. Take, for instance, a file system on a com-
puter. When you view a directory listing, you see the file
name, file size, create date, last modified date, and so
forth. These are basic examples of metadata associated
with each object in that directory.
What Is a Distribution?
Often called a “distro,” a Linux distribution is the combination of
specific versions of the Linux kernel with other libraries, system
daemons, development tools, applications, packaging, and life-cycle
management tools that are compatible with each other and tested for
interoperability. The most common way that people acquire Linux
today is by downloading one of the many different Linux distribu-
tions. Distributions are available not just for servers, desktop, and
W hat I s L inux ?
17
laptop computers but also for a huge variety of more specialized
devices that run Linux. Examples of Linux distributions are Ubuntu,
Debian, Fedora, openSUSE, and NVIDIA Cumulus Linux.
Figure 1-4: User Space and Kernel Space in the Linux kernel
W hat I s L inux ?
18
such as memory or network devices. Every modern multi-user oper-
ating system has some type of user space versus kernel space design,
which is intended to keep it secure, high-performing, and reliable.
In short, the separation between user space and kernel space is made
to ensure that Linux is as reliable and secure an operating system as
possible.
W hat I s L inux ?
19
can put those worries aside. If you look at the Linux kernel alone,
with its 22 million lines of code, you’ll find a strong community
developing it behind the scenes. In 2016, one report said that over
5,000 individual developers representing 500 different corpora-
tions around the world contributed to enhancements in the Linux
kernel, not to mention all the other surrounding applications and
services. A staggering 13,500 developers from more than 1,300
companies have contributed to the Linux kernel since 2005.
You might wonder why commercial entities contribute code to
Linux. While many open-source advocates see the open-source
nature of Linux as purely idealistic, commercial contribution of
code is actually a strategic activity. In this sense, the for-profit
companies who are dependent on Linux contribute their changes
to the core to ensure that those changes carry forward into future
distributions without having to maintain them indefinitely.
W hat I s L inux ?
20
Linux Package Management
A Linux package management system is
a tool that helps Linux administrators
install and manage applications and
extensions for the Linux operating sys-
tem. Each Linux distribution carries its
own package management capabilities.
A Linux package includes all the bits necessary for a new application
or service to operate. The package management system can also help
an administrator address any dependencies that a package may have.
A dependency is a software package necessary for another package to
operate. By layering these dependencies, newly developed packages can
then leverage the work of others without having to constantly reinvent
the wheel, but maintaining dependencies can be difficult, particularly
as you continue to add packages. A good package management system
will ensure that all dependencies are handled at the same time that you
install new packages.
You will learn more about package management later in this book.
W hat I s L inux ?
21
• Big data. More and more companies are having to deal with
exponentially increasing amounts of data in their data center,
and because Linux offers such scalability and performance, it has
become the go-to operating system for crunching big data via
applications like Hadoop. Even Microsoft recently announced a
big data solution based on Linux.
KNOWLEDGE CHECK
Answer the following questions to check your knowl-
edge concerning the basics of Linux:
• What is the Linux kernel?
Summary
In this chapter, you learned what Linux is, where it came from, how
it’s being used, and how powerful it is. With that knowledge, it’s
time to get started using Linux yourself! In the next chapter, you will
learn where to download a Linux distribution, discover the basics of
Linux administration, including how the Linux file system works,
how to manage processes, how to log into Linux, and how to deploy
new packages.
W hat I s L inux ?
22
CHAPTER 2
Basics of Linux
Administration
Even though this chapter is entitled “Basics of Linux Administration,”
you should know that this chapter is meant for anyone getting start-
ed with Linux, whether or not you plan to be a Linux administrator
in the future. You can consider this chapter a “getting started with
Linux” resource.
While some people will want to run Linux directly on a physical serv-
er, desktop, or laptop, many people get started learning Linux for the
first time by running it inside of a virtual machine. With a VM option,
you can run Linux inside your existing Microsoft Windows or Apple
macOS operating system using virtualization tools such as VMware
Workstation or VMware Fusion, both of which both offer a free,
limited-time evaluation license. You can also go with a free product
from Oracle called VirtualBox. Another option is to run Linux as a VM
in the public cloud via a provider such as Amazon Web Services or
Microsoft Azure.
In this book, I’ll skip the steps on how to install Linux because you
won’t have to perform the typical installation if you use a live image.
Instead, we will focus on building a skill set on the administrative
tasks needed to understand and navigate Linux.
Most Linux servers are set up to allow users to connect via the network
using the Secure Shell (SSH), an encrypted communications protocol.
SSH is a secure alternative to the insecure telnet that was used in the
past. With SSH, your SSH client connects to the SSH server running
on the Linux host where you log in with a username and password.
We’ll talk more about user administration later in this chapter.
As you can see, with SSH, you connect using the command ssh,
followed by the Username, an @ symbol, and then the Hostname or
IP Address of the Linux host to which you are trying to connect. You
will be prompted for your password to log in. In the example above,
the password is required but is not echoed and therefore not shown.
The uname command shows the basic type of operating system you
are using, like this:
david@debian:~$ uname -a
Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.43-2 (2017-04-30)
i686 GNU/Linux
david@debian:~$ hostnamectl
Static hostname: debian
Icon name: computer-vm
Chassis: vm
Machine ID: 0eb625ef6e084c9181b9db9c6381d8ff
Boot ID: 8a3ef6ecdfcf4218a6102b613e41f9ee
Virtualization: vmware
Operating System: Debian GNU/Linux 8 (jessie)
Kernel: Linux 3.16.0-4-686-pae
Architecture: x86
If you’re new to Linux, you might be wondering how the Linux file
system compares to something familiar like the Microsoft Windows
file system. In Windows, you may be used to drive letters (like the
C: drive) being used as the highest point of a storage volume. Linux
represents the highest level of the volume differently. The Linux file
system can span multiple physical drives, which are all a part of the
same tree. The highest point of the Linux file system is the “/,” or
“root,” with all other directories branching down the tree from there,
as shown in Figure 2-1.
Let’s do a quick exercise. First, by using the pwd command, you can
see what directory I’m currently in.
david@debian:~$ pwd
/home/david
Next, to change to the root directory, you would use the cd command.
david@debian:~$ cd /
david@debian:/$ ls
bin boot dev etc home initrd.img lib lost+found media mnt opt proc
root run sbin srv sys tmp usr var vmlinuz
But, in most cases, you probably want more information than just
a simple list of files. Linux uses command line flags or switches to
extend what a command can do. For example, to list out all the files
and folders in the current directory, along with full details about each
one, you would type ls -la. This long listing format then shows you
each file and directory, as well as the permissions and access rights
for each object (we’ll cover file permissions later in this chapter), the
name of the user that owns the object (root), the name of the group
that owns the object (again, root), the file size, and the data and time
that the object was last modified. Here’s what this output looks like
for the root folder on my test system:
david@debian:/$ ls -la
total 88
drwxr-xr-x 21 root root 4096 May 15 11:50 .
drwxr-xr-x 21 root root 4096 May 15 11:50 ..
drwxr-xr-x 2 root root 4096 May 15 12:11 bin
drwxr-xr-x 3 root root 4096 May 15 15:53 boot
drwxr-xr-x 18 root root 3200 Jul 14 01:52 dev
drwxr-xr-x 134 root root 12288 Jul 14 01:55 etc
drwxr-xr-x 3 root root 4096 May 15 15:53 home
lrwxrwxrwx 1 root root 33 May 15 11:50 initrd.img -> /boot/initrd.
img-3.16.0-4-686-pae
drwxr-xr-x 19 root root 4096 May 17 00:41 lib
drwx------ 2 root root 16384 May 15 11:49 lost+found
In the output, you can see most of the same folders shown in
Figure 2-1.
• /home. Where user home directories are stored, one for each user.
Of course, not all applications play nice, and not all Linux administra-
tors are consistent. This is just where stuff is supposed to go, but things
occasionally end up where they don’t belong. While there may be some
differences between Linux distributions when it comes to where things
are located, in general, the baseline directory structure and usage of it
should be the same because this is defined by the file system Hierarchy
Standard (FHS). For more information on the FHS see: https://en.wikipe-
dia.org/wiki/Filesystem_Hierarchy_Standard
The $PATH variable includes all the locations that are searched when
you run a command in the CLI. Because the /bin directories are in
your path, when you execute the name of any of these sample tools,
they will be found. Here’s what your $PATH variable might look like
(shown by using the echo command to show the $PATH variable):
david@debian:~$ cd /opt/app/bin
david@debian:~$ ./myapp
(the “dot slash” is used to say “in the current directory”, you want to
execute “my app”, in this case)
• Specify the full path of the application when you execute it,
like this:
david@debian:~$ /opt/app/bin/myapp
Besides the standard types of Linux tools, there are tens of thousands
of applications you can install into Linux in just a few commands.
Linux distributions offer package managers that help you search
online package or application repositories and then download and
install just about any application you might want. Package managers
also make it easy to update your packages to get the latest version.
Examples of package managers are apt, dpkg, rpm, and yum. The
package manager that is available to you will be determined by the
Linux distribution that you have installed. Linux running on Android
mobile devices also has its own package manager (similar to the
Apple “App Store”).
Any apt list command will result in very long output, so you may
consider piping it to the “less” pager tool, like this: apt list | less. This
will show you the output page by page and allow you to press the
space bar after each page to see the next page.
What is piping?
You can direct the output of a command
to another command. Say you want to
get a directory listing that doesn’t scroll
off the bottom of the screen. You can use
the less paging tool by piping the output
of ls -al to less. In this case, you would
type ls -al | less at the command prompt and, when the screen fills up,
you will be prompted to hit a key to view the second page of the direc-
tory. Understanding the pipe character “|” and its usage is important
as you begin your Linux journey. In fact, as you get deeper into Linux
territory, you will find that the ability to pipe command output to other
commands is invaluable when it comes to creating scripts to automate
certain functionality.
david@Debian$ man ls
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of
-cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short op-
tions too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
(output truncated)
IMPORTANT!
For commands requiring elevated privileges, we’ll be
prepending those commands with the sudo command,
which will be discussed later in this book. For now, you
just need to understand that sudo allows you to run the
command as an administrator.
In the above example, we used apt install to install the Apache web
server. To verify that a package is installed correctly (and that you
installed what you think you installed), you can use apt show.
You can see that the Apache 2.4.10 web server was installed, and
it says that this package results in a full installation; however, it
also suggests that we install the apache-doc (for documentation) and
www-browser (to act as our HTTP client/ web browser) packages.
But how do you know if it’s still running, and how do you get a list
of every process running on your system? The ps command displays
a list of running processes in Linux. This command is often coupled
with the -ef flag to show every process in the long list format shown
below. You’ll see right at the top that “/sbin/init” is PID (process
identifier) #1, and it’s owned by the root user (the super user—more
on the root user later in this chapter).
david@debian:~$ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 01:52 ? 00:00:01 /sbin/init
root 2 0 0 01:52 ? 00:00:00 [kthreadd]
root 3 2 0 01:52 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 01:52 ? 00:00:00 [kworker/0:0H]
(Output truncated)
You may want to pipe the ps -ef command to less, like ps -ef | less,
to see the output page by page.
If you just enter ps by itself, you’ll see your running processes only,
like this:
david@debian:~$ ps
PID TTY TIME CMD
1679 pts/1 00:00:00 bash
1784 pts/1 00:00:00 ps
In this case, you can see that this user is running the bash shell,
which is providing the command prompt and the ps command to
show what processes are running (also the command that produced
this output).
david@debian:~$ cd /var/log
david@debian:/var/log$ ls -l
total 4924
-rw-r--r-- 1 root root 0 Jul 14 01:57 alternatives.log
-rw-r--r-- 1 root root 40586 May 15 12:12 alternatives.log.1
drwxr-xr-x 2 root root 4096 Jul 14 01:57 apt
-rw-r----- 1 root adm 1471 Jul 14 02:17 auth.log
-rw-r----- 1 root adm 24651 Jul 14 01:55 auth.log.1
-rw-rw---- 1 root utmp 0 Jul 14 01:57 btmp
-rw------- 1 root utmp 768 Jul 14 01:53 btmp.1
drwxr-xr-x 2 root root 4096 Jul 14 01:57 cups
(Output truncated)
• tail. View the last lines (tail end) of a text file. A common use case
for tail is to watch the status of a log file in real time with the
“-f” flag like tail -f /var/log/syslog
Even if you ignore the rest of the commands in the previous list,
learn to use grep. I’ll be using it later in this book.
david@debian:/$ id
uid=1000(david) gid=1000(david) groups=1000(david),24(cdrom),25(-
floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),108(net-
dev),110(lpadmin),113(scanner),117(bluetooth)
david@debian:/$ whoami
david
Notice in the dialog above how the id command was used to see that
we were “uid” (user ID) 1000, and the whoami command was used
to see that we are a user called “david.” From there, the sudo id
command was used to issue the same command as though we are
the root user, and the sudo whoami command shared that we had
become root, where the id command showed that we now have the
uid of 0 (zero).
In the above command sequence, you can see that first there was
a permission denied error when trying to view the syslog file, but
when the sudo command was used (which typically prompts you for
the root password, since no other user was specified), the last 10
lines of the log file were shown. Many systems prevent you from
becoming the root user with su and instead require you to use the
sudo command.
The privileges for who can run what is determined by the /etc/su-
doers file, and that file should be edited using the visudo command
to ensure safe access to what is a critically important configuration
file. For more information on sudo, just use man sudo to view the
manual page.
The file is owned by the user “root” and the group “adm”. The file
permissions are “rw” (shorthand for read/write) for the owner and
“r” (shorthand for “read”) for the group with no permissions for
anyone else, just a series of dashes. Figure 2-2 shows how file per-
missions work in Linux.
In the file permissions graphic (Figure 2-2), a “d” on the left tells
you whether you are looking at a directory (or folder). Then the three
sets of permissions “rwx, r-x, r-x” tell whether you can read, write,
and execute (or start the application) at the user level, the group level,
and the “everyone else” level (others). The type indicator shown in
Figure 2-2 identifies the selected object as a directory, hence the “d”
as the type. The two most important types of objects in the Linux file
system are directories (“d”) and files (“-”). There are other possible
types as well, but for my purposes here, we’ll stick with directories
and files.
Summary
In this chapter, you learned the basics of Linux administration: how
to get Linux, how to log in to Linux, how the Linux file system works,
and how to run and view applications. In the next chapter, you’ll
learn the basics of Linux network administration.
If you want to learn how to communicate with other hosts and devices
on your local network and around the world on the Internet, read on!
david@debian:~$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state
UNKNOWN mode DEFAULT group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq
state UP mode DEFAULT group default qlen 1000
link/ether 00:50:56:a3:71:f5 brd ff:ff:ff:ff:ff:ff
If you’re only doing this because you’re comfortable with the old ways,
however, we recommend that you start to phase out your use of these old
commands because there’s no guarantee that they’ll be around forever,
they aren’t kept up to date, and they may not support all the features of
the new commands.
MAC Addresses
A media access control (MAC) address is the unique identifier assigned
to a network interface at layer 2 of the OSI Model, or of the data
link layer. A network interface always has a MAC address—often
referred to as the hardware address—even if it does not have an IP
address. MAC addresses are assigned at the time that a network
adapter is manufactured or, if it’s a virtualized network adapter,
the time that the adapter is created and appears as six groups of
two hexadecimal digits each. On the Ethernet interface, eth0, shown
above, the MAC address is also called the link or ether address. In the
ip link output above, you can see that the MAC address in this case is
00:50:56:a3:71:f5.
IP Addressing
They are unique on the same network, every device has at least
one, and addresses typically fall somewhere between 1.1.1.1 and
255.255.255.255. What are they? IP addresses, of course! For this
book, I’m going to assume that you already know the basics around
TCP/IP, and we’ll focus on how to work with them in Linux. Later in
this chapter, we’ll talk about how to configure IP addresses on your
Linux machine.
david@debian:~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state
UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq
state UP group default qlen 1000
When it comes to Linux networking tools, there is one that just about
everyone has heard of, and that is ping. Ping, which began life as
an acronym but now enjoys its status as a full-fledged word, is the
most basic network test tool around for testing network reachability.
It sends out an Internet Control Message Protocol (ICMP) packet across
the network and notifies you whether there is a response. If a host is
up and able to communicate on the network, an ICMP response will
be returned. If, however, a host is not reachable, you will get a notice
that the host was unreachable or timed out (meaning that the ping
test failed). Here’s an example of a host that is unreachable:
(The “-c5” was used to send just five ping packets; otherwise, ping
will continue forever.)
In these results, five packets were transmitted, and all of them re-
ceived no response, so there was 100% packet loss. What that means
is that this host is unreachable, or down.
But why are some of those addresses listed on the left actually names
instead of IP addresses? That’s because domain name system (DNS) is
replacing the IP with a friendly name. You’ll learn about DNS in just
a couple of pages!
DHCP
What if you have dozens, hundreds, or thousands of computers on
your network? It would be incredibly time-consuming to manual-
ly assign IP addresses and to actually track which machines have
which IP address. That’s where the dynamic host configuration protocol
(DHCP) comes in. DHCP is used to obtain an IP address when a host
or device first comes on the network.
DHCP is commonly used for client systems or devices that don’t ex-
perience any side effects from a periodically changing IP address. On
server systems, administrators either manually configure static IP
To learn more about the exact packets that make up the pro-
cess of obtaining an IP address, see this diagram: http://www.
smartpctricks.com/wp-content/uploads/2014/04/DHCP-Packets-
Establishment.png.
Note that the prior text said “IP address configuration” and not just
“IP address.” The IP configuration that is returned to a requesting
client contains, at a minimum, the IP address, the IP subnet mask,
the IP default gateway, and DNS server details. Most end user devices
are configured to use DHCP.
The local configuration file for the DHCP client (called dhclient) is at
/etc/dhcp/dhclient.conf. This is a configuration file that dictates to
You can find more details on the DHCP client leases in the files /var/
lib/dhcp/*.leases
DNS
Computers that connect to each other using TCP/IP (the most prev-
alent form of connection protocol) talk with each other using IP
addresses; however, it would be really painful to have to remember
the IP address of everything you want to connect to. Imagine having
to recall the IP address of Google each time you wanted to search
the web. Domain name system (DNS) is used to map IP addresses to
names. Everyone is familiar with using their web browser, entering a
friendly name like google.com or apple.com, and being taken to the
company’s website without ever having to type an IP address. It’s
DNS behind the scenes that is mapping that friendly name to an IP
address by doing a DNS lookup. To find out if your Linux host is using
DNS, we will be running through some troubleshooting commands,
such as like dig and nslookup, later.
• A local file called /etc/hosts is used for the first point of lookup for
any host name prior to going out to a DNS server on the network.
If the name is found there, no further searches are performed.
DNS RESOLUTION
By default, DNS name resolution works as described
here but is very modular. The hosts portion of /etc/
nsswitch.conf can include directory services like NIS+
or LDAP as well.
• getent ahosts. The genent tool with the ahosts option enumer-
ates name service switch files, specifically for host entries.
Tools that can help you answer those types of questions are the ip
command and the netstat command.
david@debian:~$ ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state
UNKNOWN mode DEFAULT group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
63339 505 0 0 0 0
TX: bytes packets errors dropped carrier collsns
63339 505 0 0 0 0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq
state UP mode DEFAULT group default qlen 1000
link/ether 00:50:56:a3:71:f5 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
410864536 1342597 0 0 0 925004
TX: bytes packets errors dropped carrier collsns
20398071 163673 0 0 0 0
david@debian:~$ netstat
Active Internet connections (w/o servers)
david@debian:~$ netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:mysql *:* LISTEN
tcp 0 0 *:48875 *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 localhost:ipp *:* LISTEN
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] SEQPACKET LISTENING 8197 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 8200 /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 15895 /run/user/1000/keyring/
pkcs11
(output truncated)
• Changes that are effective after the next restart of the OS, known
as persistent changes
To make the IP address change take effect, you can either reboot the
host or use the ifdown/ifup commands. At that point, the ip address
command output might look like this:
By the way, the ifdown and ifup commands aren’t included in the default
path on all Linux distributions. As such, you may have to explicitly in-
clude the full path to the command. For example, to bring down the eth0
interface, you may need to type /sbin/ifdown eth0. Likewise, to bring the
interface back up, you may need to type /sbin/ifup eth0.
You can see that the new IP address has been added, and making
the change this way ensures that it is persistent after the Linux
OS restart.
At this point, you can create a bond using the iproute2 tools, which
allow you to establish the bond as well as set its mode (we’ll cover
modes more in the next chapter). You can get some hints with ip link
help and ip link help bond.
You can put interfaces eth0, eth1, and eth2 into a bond like this
(Figure 3-1):
Figure 3-1: Multiple Ethernet Interfaces Bonded into a Single Network Interface
Summary
You should now know the basics of Linux network administration.
You just learned about network interfaces, DHCP, DNS, IP address
configuration, interface bonding, and more.
Understanding Linux
Internetworking
You might have heard of something called “the Internet,” the largest
internetwork ever created. In fact, the term Internet (with a capital I)
is just a shortened version of the term internetwork. An internetwork
is multiple networks connected together. For example, most com-
panies create some form of internetwork when they connect their
local-area network (LAN) to a wide area network (WAN) in order to
connect to one or multiple other LANs. For IP packets to be delivered
from one network to another network, IP routing is used — typically
in conjunction with dynamic routing protocols such as OSPF or BGP.
You can easily use Linux as an internetworking device and connect
hosts together on local networks and connect local networks together
and to the Internet.
Transparent bridges are layer 2 devices that send all frames received
on one port out the other bridge ports, based on knowledge of the
frame’s destination MAC address. Ethernet switches are multiport
network bridges. Multiport network bridges learn of the MAC ad-
dresses in the network and intelligently forward frames based on the
destination MAC address in the frame.
The problem is that these approaches limit the ability for layer 2
networks alone to operate efficiently beyond relatively small-scale
locations and very simple topologies. Layer 2 networks suffer from
two major limitations. First, they allow for hosts to send traffic to
unknown destinations. This causes broadcasts, which impact every
node in the broadcast domain. Many networks have been taken of-
fline due to “broadcast storms” or when many hosts are broadcast-
ing at once. In contrast, layer 3 networks do not allow for unknown
communication. If a layer 3 router does not have a route to the
destination IP address, it will drop the packet instead of broadcasting
like layer 2 does.
Bridging
What do you do when you have two different Ethernet networks that
need connecting? Build a bridge! Bridges have traditionally been ded-
icated hardware devices, but you can easily create a bridge in Linux.
For example, when you have a Linux host that has two or more net-
work interfaces, you can create a bridge to pass traffic between these
interfaces. You can add two interfaces to a Linux bridge with ip link
set and ip link add using:
• The two ip link set commands add the two Ethernet interfaces,
eth0 and eth1, to the new bridge resulting in a connection be-
tween that these two interfaces.
Once a bridge is created, you can view the MAC address table, which
shows which ports can reach a specific MAC address, with the bridge
command. The command shown in the example below uses fdb
show as its parameter. In this command, fdb stands for forwarding
database management, and show is a way for you to see the current
contents of this database:
Unlike layer 3 packets, layer 2 frames do not possess a TTL field. A packet
contains a special field that is set by the host that first created the packet.
Each router along the path will decrement this field by 1. If a misconfig-
uration in the network causes a similar loop, the TTL field will eventually
be decremented to 0 and the packet will be dropped. Because a layer 2
frame does not have this field, there is no limit to how many bridges a
frame can pass through. Also, because the packet is being bridged and
not routed, the TTL field will never be examined by any of the devices and
never decremented. The lack of TTL is one of the major problems with
layer 2 networks.
The Spanning Tree Protocol (STP) does not add a TTL field to the frame,
but it will prevent layer 2 loops from forming, preventing the broadcast
storm described earlier. Bridges that speak STP will exchange information
about the network using Bridge Protocol Data Units (BPDUs). Through this
BPDU exchange, the bridges will build a loop-free “tree” of the network.
In our two-switch example, STP would disable one of the two links and
never send traffic over it, until the active link failed.
The 32-bit address is broken up into four 8-bit sections called octets.
For example, the decimal to binary conversation for the above IP address
(192.168.192.168) is
How, exactly, does your networking stack know that 192.168.10.2 is not
in the same network as 192.168.192.168 when using a 255.255.255.0 sub-
net mask? If you’ve ever wondered how the math works, the magic lies in
the use of the bitwise AND operator. In the figure below, you can see that
performing a bitwise AND operation between the origination address and
Neighbor Table
When an IP node wants to communicate with a system in the same
layer 2 domain, it looks in its neighbor table, or ARP table, to deter-
mine how to construct the Ethernet frame. If the desired destination
IP address is not in the neighbor table, the node issues an ARP re-
quest, which is broadcast to everyone in the layer 2 domain, that
asks, “Please tell me the MAC address for the node with IP address
X.X.X.X.” Assuming the target device is available, the node with that
IP address will respond. In Linux, you view (and manipulate) the
Neighbor table using the ip neighbor show command (also known as
ip neighbor show, ip neigh show, or even just ip n s):
Here you can see that the routing table knows that the 172.20.10.0/28
network is a locally attached layer 2 network. The routing table also
includes a route to the default gateway (172.20.10.1), which Linux calls
“default,” that will be used to reach any node that isn’t on the local
network. If you’re used to networking on non-Linux systems, you
may have seen a default route expressed as something like 0.0.0.0/0.
Routes can be added or deleted from the routing table in a few dif-
ferent ways:
However, once the host is restarted, this route disappears because it’s
not persistent. To make this route persistent, you would edit the /etc/
network/interfaces file and, after the network device configuration,
add a post-up command with the same ip route command so that
this static route is added every time the Linux host is restarted or the
The purpose of the post-up command is to add the default route only
after the network interface is brought up.
Suppose you want a Linux system to have eth1 in one bridge (VLAN11),
eth3 in a second bridge (VLAN12), and eth2 in both (i.e. a tagged
trunk). First, we make sure the 802.1Q trunking driver is installed.
Then we create a bridge, add the ports to the bridge, and make sure
the ports are part of the desired set of VLANs. Notice that both eth1
and eth3 used untagged VLANs. However, per the bridge’s configu-
ration, traffic from those ports will be placed onto their configured
VLANs, which are VLAN 11 and VLAN 12 in this case. Untagged traffic
from the trunk port will be placed into the native VLAN, which is
VLAN 1 by default.
If you look at the Ethernet frames, you can’t tell that the interfaces
are part of a VLAN; however, eth2 is a member of both VLANs, and all
frames carry the 802.1Q VLAN tag (shown in Figure 4-2).
• In the command sudo bridge vlan add dev eth1 vid 11 pvid un-
tagged the vid parameter is the VLAN ID. VLAN IDs are used to
specify which VLAN the interface is assigned to. The pvid param-
eter specifies the private VLAN ID. In this case, the private VLAN
is left untagged.
(IP/UDP), sending them over both layer 2 and layer 3 networks. The
benefits of VXLAN on layer 2 (IP) networks are global addressing,
better scale, more resiliency, and better use of available bandwidth.
If you have two Linux systems and you want to bridge them with
VXLAN, you would install a bridge on both systems, add a local IP
address to that bridge, and add a VTEP to that bridge pointing the
VTEP to the other Linux host (shown in Figure 4-3).
Linux System 1
Now these two systems both exist on the 10.0.0.x/24 layer 2 network
(via the VXLAN overlay) even though they are connected by a layer 3
IP fabric. It’s also worth noting that the hosts are completely isolated
from the underlying layer 3 network.
KNOWLEDGE CHECK
Answer the following questions to check your knowl-
edge concerning Linux internetworking:
Summary
You should now have a good understanding of the basics of Linux
internetworking. In this chapter, you learned about layer 2 versus
layer 3 networking, bridging, routing, traffic filtering, and VXLAN. I
hope that you have enjoyed the chapter!
N V I D I A C umulus L inux 84
Latest and Greatest Networking Protocols
Internetworking requires protocols to interact with network peers
and provide the services for the underlying network model. For ex-
ample, if you want a Linux system to act as a router without having
to painfully and manually manage what could be thousands of static
routing rules, you need to run a routing protocol, such as BGP, on the
Linux system so that you can automatically share IP routes with the
rest of the network. NVIDIA Cumulus Linux uses the following:
N V I D I A C umulus L inux 85
invoked by the net command to provide a consistent and helpful user
interface.
$ net help
Usage:
# net <COMMAND> [<ARGS>] [help]
#
# net is a command line utility for networking on NVIDIA Cumulus
Linux switches.
#
# COMMANDS are listed below and have context specific arguments
which can
# be explored by typing “<TAB>” or “help” anytime while using net.
#
# Use ‘man net’ for a more comprehensive overview.
net abort
net commit [verbose] [confirm] [description <wildcard>]
net commit delete (<number>|<number-range>)
net commit permanent <wildcard>
net del all
net help [verbose]
net pending [json]
net rollback (<number>|last)
net rollback description <wildcard-snapshot>
net show commit (history|<number>|<number-range>|last)
net show rollback (<number>|last)
N V I D I A C umulus L inux 86
net show rollback description <wildcard-snapshot>
net show configuration [commands|files|acl|bgp|multicast|ospf|osp-
f6|interface <interface>]
Options:
# Help commands
help : context sensitive information; see section below
example : detailed examples of common workflows
# Configuration commands
add : add/modify configuration
del : remove configuration
# Commit buffer commands
abort : abandon changes in the commit buffer
commit : apply the commit buffer to the system
pending : show changes staged in the commit buffer
rollback : revert to a previous configuration state
# Status commands
show : show command output
clear : clear counters, BGP neighbors, etc
N V I D I A C umulus L inux 87
Building a Better Bridge
One of the most basic networking use cases is a single transparent
bridge. In our example, we’ll put the interfaces named swp1, swp2,
and swp3 into a transparent bridge with swp3 connecting back into
our layer 2 bridge infrastructure (Figure 5-2).
This simple example has a few noteworthy things going on. The first
is that we don’t need to use the sudo command for privileged access.
NCLU makes sure that the user has permission to invoke privileged
commands (or belongs to a group that has permission). The second
is that net puts commands into a “commit buffer” so that you can
issue a bunch of commands, review them in a pending state (with net
pending), correct them as needed, and then “commit” them to the
system with net commit.
N V I D I A C umulus L inux 88
Two Links Are Better Than One
A very typical layer 2 edge use case is using two switches to act like
one in a bond to a server. This provides for link- and switch-level
redundancy. These types of connections are called multi-chassis link
aggregations (MLAG), and they are typical of server connections in
just about any server deployment.
Figure 5-3 shows such a deployment with swp1 and swp2 connect-
ed to servers (each is part of an 802.1ad bond on the server side),
swp3 and swp4 connected back to the network core, and swp5 and
swp6 acting as “peer links” between the two switches that form the
redundant pair. In the example, 100 VLANs are trunked to each of
the servers. Try net example clag for a few MLAG use cases and net
example clag l2-with-server-vlan-trunks for something close to
what is described here:
N V I D I A C umulus L inux 89
What is the leaf-spine
network topology?
Local area networks were originally de-
signed with a “three-tiered” network to-
pology made up of the Core, Aggregation/
Distribution, and Access layers. The
spanning tree (STP) loop prevention pro-
tocol was commonly used to prevent loops. As
modern data centers became much more dynamic, network architects
realized the inefficiencies in the three-tiered architecture and came up
with a better design.
The leaf-spine network topology was introduced to ensure that all devices
have the exact same number of segments to the core. The end result is
that the leaf-spine network
has consistent network
delay and low latency. This
is possible because there are
only two layers. The leaf-
spine network topology is
best used in network data
centers to solve “easy-
west” data center traffic
(traffic between hosts in the
data center).
N V I D I A C umulus L inux 90
Figure 5-4 shows the configuration of a leaf switch in a layer 3 leaf-
spine network built using BGP unnumbered. The leaf switch has
a bridge with swp1-4 that has the 10.0.0.0/24 IPv4 subnets. Swp5
through swp8 are connected to spines using BGP unnumbered, ad-
vertising reachability of the bridge subnets to the rest of the network.
N V I D I A C umulus L inux 91
BGP EVPN—L3 Network Virtualization
for Network Engineers
Many networks have the scale that requires layer 3 internetworking;
however, some applications still require layer 2 peering over the
layer 3 fabric. One example of where this can be extremely useful is
VMware’s vMotion. The Ethernet Virtual Private Networks facilities
built into FRRouting’s BGP daemon allows us to use BGP to build
both the IP fabric as well as any distributed layer 2 overlays that
are needed to support your applications. BGP EVPN will take any
MAC address learned and advertise it to the remote EVPN peers. This
allows each leaf in the network to know where to send the Layer 2
VxLAN traffic without flooding or the need for spanning tree.
N V I D I A C umulus L inux 92
The details of the configuration show a leaf switch in a layer 3 leaf-
spine network built using BGP unnumbered. The leaf switch has a
default VLAN (1) with swp1-4 that has the 10.0.0.0/24 IPv4 subnet
and a second VLAN (100) on swp1-4 that is tagged. Swp5 through
swp8 are connected to spines using BGP unnumbered, advertising
reachability of the bridge subnets to the rest of the network. VLAN
100 also has a VTEP and is advertised via BGP EVPN. (See Figure 5-5.)
Note: The VXLAN header used to build the layer 2 network in EVPN
makes Ethernet frames larger than the default of 1518, so you need
to include the maximum transmission unit (MTU). In this case, set it
to 9216 (large enough to support “jumbo” frames) so that you don’t
have to worry about it ever again.
N V I D I A C umulus L inux 93
KNOWLEDGE CHECK
Answer the following questions to check your knowl-
edge concerning Linux internetworking:
• What is EVPN?
These use cases are just four examples of how Linux networking can
be easy, efficient, and powerful. If you’d like to try out more use
cases and commands, we recommend downloading NVIDIA Cumulus
VX, a free prototyping environment where you can test out your new
Linux networking skills.
N V I D I A C umulus L inux 94
NEXT STEPS
OR
Here you’ll find case studies, videos, validated designs, and white
papers that will show how NVIDIA Cumulus Linux is being used in
real data centers around the world.