Configuring Basic Networking

These days it’s almost a necessity to have your Linux system connected to some type of network. Whether it’s the need to share files and printers on a local network, or the need to con-

nect to the Internet to download updates and security patches, most Linux systems have some type of network connection.

This chapter looks at how to configure your Linux system to connect to a network, as well as how to troubleshoot network connections if things go wrong. Unfortunately, there are a few different methods for configuring network settings in Linux, and you’ll need to know them all for the LPIC-1 exam. First, we’ll cover the common locations for the config- uration files in Linux distributions. Next, we’ll examine the different tools you have at your disposal that help make configuring the network settings easier. After that, you’ll learn some simple network troubleshooting techniques.

Networking Basics

Before we take a look at how Linux handles network connectivity, let’s go through the basics of computer networking. Computer networking is how we get data from one com- puter system to another. To help simplify things, computer networks are often described as layered systems. Different layers play different roles in the process of getting the data from one network device to another.

There’s lots of debate, though, on just how best to split up the networking layers. While the standard Open Systems Interconnection (OSI) network model uses seven layers, we’ll use a simplified four-layer approach to describing the network functions:

  • The physical layer
    • The network layer
    • The transport layer
    • The application layer

The following sections detail the parts contained in each of these four layers.

The Physical Layer

The physical layer consists of the hardware required to connect your Linux system to the network. If you’ve ever connected a computer to either a home or office network, we’re sure you’re already familiar with the two main methods used to connect network devices: wired and wireless network connections.

Networking Basics             425

Wired network connections use a series of network switches to connect network devices using special Ethernet cables. The network switch accepts data packets from the network device and then sends the data packets to the correct destination device on the network.

For large office network installations, switches are usually connected in a cascade design to help reduce traffic load on the network. Switches can be interconnected with one another to help segment the network traffic into smaller areas. Figure 8.1 demonstrates a common layout for a wired network.

Server                  Server                   Server                 Server

While the term “wired” may make you think of copper cables, it can also apply to network connections that use fiber-optic cables. Fiber-optic cables use light to transmit data down a thin glass strand, achieving faster speeds and covering longer distances than conventional copper connections. Although wired networking can be cumbersome, it does provide the fastest network speeds (currently up to 100 gigabits per second). For that rea- son, wired networking is still popular in Linux server environments where high through- put is a must.

Nowadays, though, most small office and home networks utilize wireless networking. Instead of using physical wires or fiber cables to connect devices, wireless networking uses radio signals to transmit the data between the network device and a network access point. The access point works in a similar way to the switch in that it controls how data is sent to each network device communicating with it.

426                       Chapter 8 ■  Configuring Basic Networking

Each access point uses a unique service set identifier (SSID) to identify it from other access points, which can be a text name or a number. You just tell your Linux system which access point to connect to by specifying the correct SSID value. Figure 8.2 demonstrates a common wireless network layout.

F I G U R E 8 . 2      A wireless network infrastructure

SSID: My Network

The downside to wireless networking is that you can’t control where the radio signals travel. It’s possible that someone outside of your home will see your access point signals and try to connect to them. Because of that, it’s important to implement some type of encryption security on your access point. Only devices using the correct encryption key can connect to the wireless access point. Common wireless encryption techniques are Wired Equivalent Privacy (WEP), Wi-Fi Protected Access (WPA), and Wi-Fi Protected Access ver- sion 2 (WPA2).

The Network Layer

The network layer controls how data is sent between connected network devices, both in your local network and across the Internet. For data to get to the correct destination device, some type of network addressing scheme must be used to uniquely identify each network device. The most common method for doing that is the Internet Protocol (IP).

While the IP network protocol is by far the most popular in use, it’s not the only network protocol available. Apple uses a proprietary protocol called AppleTalk to allow Apple computers to communicate with one another on a local network, and Novell used the IPX/SPX protocol for communication between Novell network servers and clients. These network protocols, however, have faded from standard use and aren’t covered on the LPIC-1 exam.

Networking Basics             427

To connect your Linux system to an IP network you’ll need four pieces of information:

  • An IP address
  • A hostname
  • A default router
  • A netmask value

The following sections walk through what each of these values represent.

The IP Address

In an IP network, each network device is assigned a unique 32-bit address. Networking layer software embeds the source and destination IP addresses into the data packet so that networking devices know how to handle the data packet and the Linux system knows which packets to read and which to ignore.

To make it easier for humans to recognize the address, IP addresses are split into four 8-bit values, represented by decimal numbers, with a period between each value. This format is called dotted-decimal notation. For example, a standard IP address in dotted- decimal notation looks like

IP addresses are split into two sections. One part of the IP address represents the network address. All devices on the same physical network have the same network address portion of their IP addresses. For example, if your home network is assigned the network address 192.168 1.0, all of the network devices must start with the IP address 192.168.1.

The second part represents the host address. Each device on the same network must have a unique host address. Figure 8.3 demonstrates assigning unique IP addresses to devices on a local network.

F I G U R E 8 . 3      Network addressing on a local network


Network      Host

Network      Host

To complicate things even further, an updated IP network protocol has been introduced called IP Version 6 (IPv6). The IPv6 networking scheme uses 128-bit addresses instead of the 32-bit addresses used by IP, which allows for lots more network devices to be uniquely identified on the Internet.

428                       Chapter 8 ■  Configuring Basic Networking

The IPv6 method uses hexadecimal numbers to identify addresses. The 128-bit address is split into eight groups of four hexadecimal digits separated by colons, such as


If one or more groups of four digits is 0000, that group or those groups may be omitted, leaving two colons:


However, only one group of zeroes can be compressed this way.

The IPv6 protocol also provides for two different types of host addresses:

  • Link local addresses
  • Global addresses

The IPv6 software on a host device automatically assigns the link local address. The link local address uses a default network address of fe80:: and then derives the host part of

the address from the media access control (MAC) address built into the network card. This

ensures that any IPv6 device can automatically communicate with any other IPv6 device on a local network without any configuration.

The IPv6 global address works similarly to the original IP version: each network is assigned a unique network address, and each host on the network must have a unique host address.

Netmask Address

The netmask address distinguishes between the network and host address portions in the IP address by using 1 bit to show which bits of the 32-bit IP address are used by the net- work and 0 bits to show which bits represent the host address. Since most people don’t like working with binary numbers, the netmask address is usually shown in dotted-decimal format. For example, the netmask address indicates the first three decimal numbers in the IP address represent the network address, and the last decimal number rep- resents the host address.

There is another way to represent netmask addresses called Classless Inter-Domain Routing (CIDR) notation. CIDR notation represents the netmask as just the number of masked bits in the IP address. CIDR notation is usually shown with a slash between the network address and the CIDR value. Thus, the network and netmask would have the CIDR notation of Although CIDR notation is becoming popular in the networking world, Linux configuration files still use the netmask value to define the network.

When working on the Internet, it’s crucial that no two physical Internet connections have the same IP address. To accomplish that, the Internet Assigned Numbers Authority (IANA) maintains strict control over the assignment of IP network addresses. However, not all networks need to be connected to the Internet, so to differentiate those networks, IANA has made the distinction between public and private IP networks.

Networking Basics             429

Specific subnetwork ranges are reserved for private IP networks:

  • 10.0 0.0 to
    • 172.16 0.0 to
    • 192.168 0.0 to

These private IP addresses can’t be used for Internet traffic; they work only on local networks.

As you can imagine, with the popularity of the Internet, it didn’t take long for IANA to run out of available public IP address networks. However, in a brilliant move, the idea of network address translation (NAT) saved the day. A NAT server can take an entire private IP network and assign it a single public IP address on the Internet. This is how you can connect your entire home network to a single ISP Internet connection and everything works.

Default Router

With IP and IPv6, devices can communicate directly only with other devices on the same physical network. To connect different physical networks together, you use a router. A router passes data from one network to another. Devices that need to send packets to hosts on remote networks must use the router as a go-between. Usually a network will contain a single router to forward packets to an upper-level network. This is called a default router (or sometimes, a default gateway). Network devices must know the local default gateway for the network to be able to forward packets to remote hosts.

Thus, for a device to communicate in an IP network, it must know three separate pieces of information:

  • Its own host address on the network
    • The netmask address for the local physical network
    •    The address of a local router used to send packets to remote networks Here’s an example of what you would need:
    • Host address:
    • Netmask address:
    • Default gateway:

With these three values in hand you’re almost ready to configure your Linux system for working on the Internet. There’s just one more piece of the puzzle you’ll need to worry about, and we’ll look at that in the next section.

Host Names

With all of these IP addresses, it can be impossible trying to remember just what servers have what addresses. Fortunately for us, yet another network standard is available that can help out. The Domain Name System (DNS) assigns a name to hosts on the network.

430                       Chapter 8 ■ Configuring Basic Networking

With DNS, each network address is assigned a domain name (such as that uniquely identifies the network, and each host in that network is assigned a unique host name, which is added to the domain name to uniquely identify the host on the network.

Thus, to find the host shadrach on the domain, you’d use the DNS name The DNS system uses servers to map host and domain names to the specific network addresses required to communicate with that server. Servers respon- sible for defining the network and host names for a local network interoperate with upper- level DNS servers to resolve remote host names.

To use DNS in your network applications, all you need to configure is the address of the DNS server that services your local network. From there, your local DNS server can find the address of any host name anywhere on the Internet.

Dynamic Host Configuration Protocol

There’s one more network layer feature that we need to discuss before we move on to con- figuring the Linux system. Trying to keep track of host addresses for all of the devices on a large network can become cumbersome. Keeping individual IP address assignments straight can be a challenge, and often you’ll run into the situation where two or more devices acci- dentally are assigned the same IP address.

The Dynamic Host Configuration Protocol (DHCP) was created to make it easier to configure client workstations, which don’t necessarily need to use the same IP address all the time. With DHCP, the client communicates with a DHCP server on the network using a temporary address. The DHCP server then tells the client exactly which IP address, net- mask address, default gateway, and even DNS server to use. Each time the client reboots, it may receive a different IP address, but that doesn’t matter as long as it’s unique on the network.

These days, most home network routers include a DHCP server function, so all you need to do is set your Linux client to use DHCP and you’re done. You don’t need to know any of the “behind the scenes” details of the network addresses.

Although DHCP is great for clients, it’s not a good idea to use for servers. Servers need to have a fixed IP address so that clients can always find them. While it’s possible to configure static IP addresses in DHCP, usually it’s safest to manually configure the network information for servers. This is called a static host address.

The Transport Layer

The transport layer can often be the most confusing part of the network. Whereas the net- work layer helps get data to a specific host on the network, the transport layer helps get the data to the correct application contained on the host. It does that by using ports.

Networking Basics             431

Ports are sort of like apartment numbers. Each application that’s running on a network server is assigned its own port number, just like different apartments in the same apart- ment building are assigned separate apartment numbers. To send data to a specific applica- tion on a server, the client software needs to know both the server IP address (just like the apartment building address) and the transport layer port number (just like the apartment number).

Two common transport protocols are used in the IP networking world:

  • Transmission Control Protocol (TCP)
  • User Datagram Protocol (UDP)

The Transmission Control Protocol (TCP) transport protocol sends data using a guar- anteed delivery method. It ensures that the server receives each portion of data that the client computer sends, and vice versa. The downside is that a lot of overhead is required to track and verify all of the data sent, which can slow down the data transfer speed.

For data that’s sensitive to transfer speed (such as real-time data like voice and video), that can cause unwanted delays. The alternative to this is the User Datagram Protocol (UDP) transport protocol. UDP doesn’t bother to ensure delivery of each portion of the data—it just sends the data out on the network and hopes it gets to the server!

Though losing data may sound like a bad thing, for some applications (such as voice and video) it’s perfectly acceptable. Missing audio or video packets just show up as blips and breaks in the final audio or video result. As long as most of the data packets arrive, the audio and video is understandable.

Though not used for sending application data, there is one more transport layer protocol that you’ll need to know about. There’s a need for network devices to communicate “behind the scenes” with each other, passing network management information around the network. The Internet Control Message Protocol (ICMP) provides a simple way for network devices to pass information such as error messages and network routing information to make it easy for each client to find the required resource on the network.

The Application Layer

The application layer is where all the action happens. This is where the network programs process the data sent across the network and then return a result. Most network applica- tions behave using the client/server paradigm. With the client/server paradigm, one net- work device acts as the server, offering some type of service to multiple network clients (such as a web server offering content via web pages). The server listens for incoming con- nections on a specific transport layer port assigned to the application. The clients must know what transport layer port to use to send requests to the server application.

To simplify that process, both TCP and UDP use well-known ports to represent com- mon applications. These port numbers are reserved so that network clients know to use

432                       Chapter 8 ■  Configuring Basic Networking

them when looking for specific application hosts on the network. Table 8.1 shows some of the more common well-known application ports.

TA B L E 8 .1      TCP and UDP well-known ports

20TCPFile Transfer Protocol (FTP) data
21TCPFile Transfer Protocol (FTP) control messages
22TCPSecure Shell (SSH)
23TCPTelnet interactive protocol
25TCPSimple Mail Transfer Protocol (SMTP)
53TCP&UDPDomain Name System (DNS)
80TCPHypertext Transfer Protocol (HTTP)
110TCPPost Office Protocol version 3 (POP3)
123UDPNetwork Time Protocol (NTP)
139TCPNetBIOS Session Service
143TCPInternet Message Access Protocol (IMAP)
16UDPSimple Network Management Protocol (SNMP)
162UDPSimple Network Management Protocol trap
389TCPLightweight Directory Access Protocol (LDAP)
443TCPHypertext Transfer Protocol (HTTPS) over TLS/SSL
465TCPAuthenticated SMTP (SMTPS)
514TCP&UDPRemote Shell (TCP) or Syslog (UDP)
636TCPLightweight Directory Access Protocol over TLS/SSL (LDAPS)
993TCPInternet Message Access Protocol over TLS/SSL (IMAPS)
995TCPPost Office Protocol 3 over TLS/SSL (POP3S)

Configuring Network Features             433

If you think trying to remember all of those port numbers is a hassle, you’re not alone.

In an attempt to simplify ports, there’s somewhat of an ad hoc standard for assigning names each of the well-known port numbers. Each Linux system maintains a list of its net- work port names in the /etc/services file. Network applications can read this file when working with network ports and use the name instead of the port number. This approach of displaying port names instead of numbers is commonly used in network troubleshooting tools.

Now that you’ve seen the basics of how Linux uses networking to transfer data between systems, our next section dives into the details of how to configure these features in your Linux system.

Configuring Network Features

There are five main pieces of information you need to configure in your Linux system to interact on a network:

  • The host address
  • The network subnet address
  • The default router (sometimes called the gateway)
  • The system host name
  • A DNS server address for resolving host names

We have three ways to configure this information in Linux systems:

  • Manually editing network configuration files
  • Using a graphical tool included with your Linux distribution
  • Using command-line tools

The following sections walk through each of these methods.

Network Configuration Files

Linux systems that utilize the systemd initialization method normally use the systemd- networkd daemon to detect network interfaces and automatically create entries for them in the network configuration files. You can modify those files manually to tweak or change network settings if necessary.

Unfortunately, though, no single standard configuration file exists that all distributions use. Instead, different distributions use different configuration files to define the network settings. Table 8.2 shows the most common network configuration files that you’ll run into.

Need help with this assignment or a similar one? Place your order and leave the rest to our experts!

Quality Assured!

Always on Time

Done from Scratch.