This course covers the essentials of networking with Linux. This course is part of the Linux Administration Bootcamp learning path, designed to get you up and running with Linux.
Learning Objectives
- Understand the TCP/IP protocol and the most important aspects of IP networking
- Learn how DNS, hostnames, and IP addresses are used in networking on Linux
- Learn about DHCP, as well as status and dynamic addressing
- Learn some of the most common tools you can use to perform network diagnostics
Intended Audience
- Anyone with basic knowledge of Linux who wants to learn more
- System administrators or IT professionals who want to learn more about networking on Linux
Prerequisites
This is an intermediate-level course so some knowledge of Linux is expected. If you're just starting out, then try our Linux Fundamentals course first.
In this lesson, you will learn what network ports are and what they're used for. You'll also learn about DHCP and how to configure a Linux server as a DHCP client. We'll also cover how to assign static IP addresses to the network interfaces on a Linux system. Next, you'll learn about the ifup and ifdown scripts. Finally, you'll learn about a couple of menu driven tools you could use to easily configure the network settings on various Linux distributions.
Just like IP addresses identify hosts on a network, ports identify the services on a host. When a service starts on a system, it binds itself to a port and listens for traffic destined for its port. Ports range from one to 65,535. Ports 1 through 1023 are called well-known ports or system ports. These ports are pre-assigned ports and are used for common system services. These ports are also called privileged ports, since it requires super user privileges to open these ports. Ports above 1024 can be opened and used by normal users on a system and are called unprivileged ports. I've listed a few common ports on the screen.
Port 22 is reserved for SSH, port 25 for SMTP, 80 for HTTP, 143 for IMAP, 389 for LDAP, and 443 for HTTPS. When you type in HTTPS://www.mybank.com in your web browser, your computer translates www.mybank.com into an IP address. Then your web browser initiates a request to that IP address on port 443, since you specified the HTTPS protocol. The service, in this case, a web server, will receive the traffic on port 443. The /etc/services file translates human readable names into port numbers. Here, you'll find a list of predefined ports, you can also add to this list.
Sometimes when you install third-party software, you may need to add an entry and /etc/services for the service that that software provides. You can also create entries for your own custom written applications that use ports. DHCP stands for dynamic host configuration protocol. DHCP is primarily used to assign IP addresses to a host on a network. When a DHCP client wants to request an IP address, it sends a broadcast message looking for a DHCP server. The DHCP server then responds to the client and provides it with an IP address and other additional information such as the netmask, the gateway and DNS servers to use for name resolution.
The DHCP client configures itself with this information and begins to communicate on the network. The IP address assigned to a DHCP client is leased from the DHCP server. The client will be able to use that IP address for the lease expiration time configured by the DHCP server. If the DHCP client wants to continue using the IP address beyond the lease expiration time, it must send a renewal request to the DHCP server. If no renewal is received by the DHCP server it will place this IP address back into the pool of available addresses.
To configure a RedHat based system as a DHCP client, edit the network device configuration file located in the /etc/sysconfig/network-scripts directory. The name of this file will be ifcfg- network device name. Depending on the system configuration and the underlying hardware, it might be ifcfg-eth0 or even something like ifcfg-enp5s2. To get a list of network devices on your system, run ifconfig -a or ip link. Once you've identified the configuration file for the network device, set the boot proto variable to DHCP.
To configure an Ubuntu system as a DHCP client, edit the /etc/network/interfaces file. Add the DHCP method to the inet address family statement for the interface. The line will read iface network device name inet dhcp. For eth0 this line will be iface eth0 inet dhcp. You can also assign a static IP address to a Linux system. For RedHat based systems, edit the network interface configuration file located in /etc/sysconfig/network-scripts. Be sure to set the boot proto variable to static, assign the IP address, the netmask, network, broadcast and gateway as shown on the screen.
If you want the network device to be activated at boot time, set on boot two, yes. To assign an interface a static IP address on an Ubuntu system, edit the /etc/network/interfaces file. Use the static keyword following inet on the iface line for the network interface. Next, supply the IP address, netmask and gateway address. You can use the IP command to manually assign an IP address to a network interface. To add the IP address of 10.11.12.13 to eth0, run, ip address add 10.11.12.13 dev eth0. You can also supply the netmask by following the IP address with a forward slash and then providing the netmask.
To bring the interface up, run ip link set eth0 up. If the ifconfig tool is available, you can use it to assign IP addresses to network interfaces as well. To add the IP address of 10.11.12.13 to eth0, run, ifconfig eth0 10.11.12.13. To specify the netmask, use the netmask keyword and follow it by the netmask you intend to use. In this example, it's netmask 255.255.255.0. To bring the interface up, run ifconfig eth0 up.
An easier way to bring network interfaces up and down, is by using the ifup and ifdown commands. These commands are actually scripts that are provided by many Linux distributions. They use the information specified in the network configuration files to configure the interfaces. If you make a configuration change, you can test your change by using the ifup and ifdown commands.
Instead of manually editing network configuration files, some distribution supply GUI or TUI tools. QUI stands for graphical user interface and TUI stands for textual user interface. RedHat supplies a TUI called nmtui. You could run nmtui as root and use the simple menu driven interface to configure your network devices. Older versions of RedHat include a very similar utility called system-config-network. You can use YaST, which stands for yet another setup tool on SUSE systems. At the time of this recording, there are no official Ubuntu network configuration tools available.
In this lesson, you learned about network ports and how super user privileges are required to open ports below 1024. These ports go by two names, privileged ports and well-known ports. Ports above 1024 are unprivileged ports and can be opened by normal users on a Linux system. You also learned that the primary purpose of DHCP is to assign IP addresses to hosts on a network. You learned how to configure Linux servers to use DHCP to obtain their networking information and how to assign static IP addresses as well. You learned that the ifup and ifdown scripts are available on many Linux distributions and that they can be used to easily bring up or down a network interface. Finally, you learned about GUI and TUI tools that you can use to configure the networking settings on a Linux server.
Jason is the founder of the Linux Training Academy as well as the author of "Linux for Beginners" and "Command Line Kung Fu." He has over 20 years of professional Linux experience, having worked for industry leaders such as Hewlett-Packard, Xerox, UPS, FireEye, and Amazon.com. Nothing gives him more satisfaction than knowing he has helped thousands of IT professionals level up their careers through his many books and courses.