Reader small image

You're reading from  Mastering Ubuntu Server - Fourth Edition

Product typeBook
Published inSep 2022
PublisherPackt
ISBN-139781803234243
Edition4th Edition
Concepts
Right arrow
Author (1)
Jay LaCroix
Jay LaCroix
author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix

Right arrow

Connecting to Networks

Linux networks took the IT industry by storm. Many organizations use Linux in their data centers, on both physical servers and in the cloud. Ubuntu Server is among the most popular choices for running mission-critical applications, but without a stable network to connect the individual components of your infrastructure together, even the most powerful server hardware will be ineffective.

So far in this book, we’ve worked with a single Ubuntu Server instance. Here, we begin a two-part look at networking in Linux. In this chapter, we’ll discuss topics related to initial network connectivity and remote management. We’ll continue learning additional networking topics in Chapter 11, Setting Up Network Services, where we’ll work on building and configuring additional components that will enable your servers to communicate more effectively, which will result in a strong foundational network that will serve your needs for years to come...

Setting the hostname

During installation, you were asked to create a hostname for your server. Specifically, the field was labeled Your server's name during the initial setup process. At that time, our goal was to simply get an Ubuntu Server installation set up for working through the examples in this book. At this point, you may consider changing the hostname of your server.

When we utilize OpenSSH to remotely manage our servers (as we’ll do later on in this chapter), the hostname is shown on the command line. That can be very confusing if all servers have the same name. More importantly, the hostname of a server gives it an identity. When it comes to real production deployments of Ubuntu Server, each individual server should have its own designated purpose, and be named accordingly. Often, organizations will have their own naming scheme. Perhaps web servers in a company are named similar to webserver-01, or with a fully qualified domain name, such as webserver-01...

Managing network interfaces

Networking is critical for server infrastructure. Without a network, servers cannot communicate with one another, and users will be unable to access them. In order for a server to connect to a network, it needs to have a network interface installed. Most servers will have a standard wired Ethernet adapter installed, allowing you to plug in a network cable to connect it to a switch. Assuming our server’s hardware has been properly detected by Ubuntu, this is handled pretty much automatically. However, the automatic configuration is not always ideal. Perhaps we want to customize the IP address or settings related to the connection.

First, we need to understand how to view the current connection parameters that the network card of our server currently has in effect. That’s the main goal of this section. We can do so using two basic commands: ip (which is recommended) and ifconfig (which was the previous method in older versions of Ubuntu...

Assigning static IP addresses

With servers, it’s very important that your IP addresses remain fixed and do not change for any reason. If an IP address does change (such as a dynamic lease with no reservation), your users will experience an outage, services will fail, or entire sites may become unavailable. When you install Ubuntu Server, it will grab a dynamically assigned lease from your DHCP server, but after you configure the server the way you want it, it’s important to set a permanent IP address right away before it’s considered production-ready. One exception to this rule is an Ubuntu-based VPS. Cloud providers that bill you for these servers will have an automatic system in place to declare an IP address for your new VPS, and will already have it configured to remain in place. But in the case of virtual or physical servers you manage yourself, you’ll start off with a dynamic address, unless you’ve already configured a static IP address during...

Understanding Linux name resolution

In Chapter 11, Setting Up Network Services, we’ll have a discussion on setting up a DNS server for local name resolution for your network. But before we get to that, it’s also important to understand how Linux resolves names in the first place. Most of you are probably aware of the concept of a Domain Name System (DNS), which matches human-understandable domain names to IP addresses. This makes browsing your network (as well as the internet) much easier. However, a DNS isn’t always the first thing that your Linux server will use when resolving names.

For more information on the order in which Ubuntu Server checks resources to resolve names, feel free to take a look at the /etc/nsswitch.conf file. There’s a line in this file that begins with the word hosts. Here is the output of the relevant line from the file on my server:

hosts:          files mdns4_minimal [NOTFOUND=return] dns mymachines

In this case,...

Getting started with OpenSSH

OpenSSH is quite possibly the most useful tool in existence for managing Linux servers. Of all the countless utilities available, this is the one I recommend that everyone starts practicing as soon as they can. Technically, I could probably better fit a section for setting up OpenSSH in Chapter 11, Setting Up Network Services, but this utility is very handy, and we should start using it as soon as possible.

OpenSSH allows you to open a command shell on other Linux servers, enabling you to run commands as if you were there in front of the server. For Linux administrators like us, this is extremely convenient. We could be tasked with managing dozens, hundreds, or even thousands of servers.

With OpenSSH, we can manage our entire server architecture without even getting out of our chairs. In this section, I’ll give you some information on OpenSSH and how to install it, and then I’ll finish up the section with a few examples of actually...

Getting started with SSH key management

When you connect to a host via SSH, you’ll be asked for your password, and after you authenticate you’ll be connected. Instead of using your password, though, you can authenticate via public key authentication instead. The core benefit to this method is added security, as your system password is never transmitted during the process of connecting to the server. When you create an SSH key pair, you are generating two files, a public key and a private key. These two files are mathematically linked, so if you connect to a server that has your public key, it will know it’s you because you (and only you) have the private key that matches it. This method is far more secure than password authentication, and I highly recommend that you use it. To get the most out of the security benefit of authentication via keys, you can actually disable password-based authentication on your server so that your SSH key is your only way in. By disabling...

Simplifying SSH connections with a config file

Before we leave the topic of OpenSSH, there’s another trick that has the benefit of convenience, and that is the creation of a local configuration file for SSH. This file must be stored in the .ssh directory of your home directory, and be named config. The full path for this file in my case looks like this:

/home/jay/.ssh/config

This file doesn’t exist by default, but if it’s found, SSH will parse it whenever you use the client and you’ll be able to benefit from it. Go ahead and open this file in your text editor, such as nano:

nano /home/your_username/.ssh/config

This config file allows you to type configuration for servers that you connect to often, which can simplify the ssh command automatically. The following are example contents from such a file that will help me illustrate what it does:

host myserver 
    Hostname 192.168.1.23 
    Port 22 
    User jdoe 
Host nagios 
    Hostname...

Summary

In this chapter, we worked through several examples of connecting to other networks. We started off by configuring our hostname, managing network interfaces, assigning static IP addresses, as well as looking at how name resolution works in Linux. A decent portion of this chapter was dedicated to topics regarding OpenSSH, which is an extremely useful utility that allows you to remotely manage your servers. We’ll revisit OpenSSH in Chapter 21, Securing Your Server, with a look at boosting its security. Overall, we’ve only begun to scratch the surface of this tool. Entire books have been written about SSH, but the examples in this chapter should be enough to make you productive with it. The name of the game is to practice, practice, practice!

In the next chapter, we’ll talk about managing software packages. We’ll work through adding and removing them, adding additional repositories, and more!

Relevant videos

Further reading

Join our community on Discord

Join our community’s Discord space for discussions with the author and other readers:

https://packt.link/LWaZ0

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Ubuntu Server - Fourth Edition
Published in: Sep 2022Publisher: PacktISBN-13: 9781803234243
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix