Getty Images/iStockphoto
8 network tasks administrators can do quicker from the CLI
Admins can use the command-line interface to manage network tasks. Learn how to streamline automation, troubleshoot networks and manage services on Linux, macOS and Windows.
It's a commonly held belief that Linux isn't a modern OS because users often still work with archaic commands. But administrators can accomplish many jobs, including networking tasks, more quickly using a CLI rather than a GUI.
There are many other benefits of working with a CLI. For example, most commands usually have more options or choices available than their graphical counterparts. Systems such as servers might benefit from a slight performance boost because they don't have to support a GUI.
However, scripting is the most important benefit of CLI tools. It's almost impossible to script GUI-based tasks -- imagine automating mouse movement and clicks -- but you can place commands in a text file with their options and arguments and then execute automatically. This is an essential function.
In addition, command-line environments make it easy to redirect command results to files for future use or analysis. As you run the network commands below, add >> test.txt to them to write the command output to a text file.
For example, if you want to check the IP address on your Windows system, you can use a series of mouse clicks and windows to navigate: Right-click Start > Network Connections > Ethernet > Select the network connection.
To display the IP address at the CLI, open a terminal from the taskbar, and type ipconfig. If Windows Server puts a PowerShell console in the taskbar, you might have a terminal shortcut on your desktop or taskbar.
The CLI method is much quicker than four or more mouse clicks.
Tab completion and history are two of the most important functions of the CLI. It's essential for network administrators who want to become fast at the CLI to learn to maximize these functions.
Windows, Linux and macOS terminal environments let you type in part of a command, directory name or file name and press the Tab key to auto complete the string. Be sure to type in enough to make the term unique -- or hit Tab twice to see all matching options.
The terminals also keep track of commands you've entered, and Linux and macOS write these to files. Type the history command to see recent commands. Use the up and down arrow keys to cycle through the list. Various commands also repeat specific commands, depending on the shell.
This article lists standard network tasks you probably do regularly on your Mac, Linux and Windows systems that you can do quicker with the CLI.
1. Get help
To become proficient with the CLI, it's important to learn how to find help. It's difficult enough to remember many commands, but it can be even tougher when options and switches are added to the mix.
Unix-related systems, such as Linux and macOS, use manual pages for basic documentation. These pages typically provide a brief explanation of the command, a few examples and a list of the available options.
To display a man page, type man and the command name, such as in the following:
man ifconfig
Windows commands offer similar functionality. Type /? after a command to see a summary, usage and options:
ipconfig /?
2. Display and test network configurations
One of the most fundamental steps of network troubleshooting is to check the system's IP address. Misconfigured IP addresses are frequent culprits in network communications problems. This task is almost always quicker from the CLI on Windows, Linux and macOS systems.
On a Mac or older Linux box, type the following command:
ifconfig
On a newer Linux system, enter the following:
ip addr
On a Windows computer, type the following:
ipconfig
All three commands have options to provide additional and more granular information, but those commands are a good start.
The ipconfig command has many useful switches.
For example, when you troubleshoot IP address issues on a Windows computer, use the following command to release the IP address:
ipconfig /release
If the system is a Dynamic Host Configuration Protocol client, acquire a new IP configuration from the DHCP server with the following command:
ipconfig /renew
Confirm network connectivity with the following ping command:
ping 8.8.8.8
Windows, Linux and macOS all use this command. Be aware that Windows sends four pings by default, while Linux and macOS send continuous pings unless you specify otherwise.
You can also test connectivity with the following PowerShell cmdlets:
Test-Connection 8.8.8.8
Test-Connection server01
This table includes other network troubleshooting commands.
Command | Explanation |
tracert 8.8.8.8 | Display network communication route on Windows. |
traceroute 8.8.8.8 | Display network communication route on Linux and macOS. |
pathping 8.8.8.8 | Display dropped packets along a route on Windows. |
mtr 8.8.8.8 | Display dropped packets along a route on Linux, or install it on macOS. |
It's helpful to display the system's hostname, and all three platforms recognize hostname as the same command for this.
3. Install software
Linux users frequently manage software with package managers from the CLI, while Mac users use the Homebrew manager. These tools make it easier to install software. It's sometimes more efficient to install software with package managers at the CLI.
Linux relies on several different package managers depending on your distribution of choice. You can use a tool like Vim to edit network configuration files, such as the sshd_config file that controls Secure Shell (SSH) security settings on Linux servers.
Two common commands used to install the Vim package on Linux are the following:
apt install vim
dnf install vim
To put a package like Neovim on a Mac with Homebrew, type the following:
brew install neovim
Windows systems don't tend to use package managers from the CLI, but you can select choices such as winget or Chocolatey.
If your system includes winget, use the following command:
winget install vim.vim
Package managers offer many benefits, such as automating software installations after deploying a new system.
PowerShell makes it easy to install Windows components. For example, type the following command to add the Windows Server Backup feature to the system:
Install-WindowsFeature Windows-Server-Backup
Use the Uninstall command to remove a component.
4. Perform system management
Many network management tasks are easier to complete from the CLI. You can check the status of processes, log off or shut down the system, and gather performance information.
The commands in the following table show processes that run on the system.
Command | Explanation |
netstat | Display current active connections. |
nslookup | Display and troubleshoot DNS name resolution information. |
ps | Display process statistics on Linux and macOS. |
tasklist | Display process information on Windows. |
logoff | Log off the current user on Windows. |
shutdown -h now | Shut down Linux and macOS. |
shutdown -r now | Restart Linux and macOS. |
shutdown /s | Shut down Windows. |
shutdown /r | Restart Windows. |
You can see which network applications or services consume the most CPU time and memory by using the top command in Linux and macOS. Use the q command to close top.
You can also see Windows system details with the systeminfo command.
5. Manage services
While a computer reboot can fix many issues, you might need to restart a specific network service that could be the cause of problems. Reboots create downtime, which is what server administrators should avoid, so it might be better to restart services to correct issues or update configurations.
To restart a SSH server service on Linux, type the following command:
systemctl restart sshd
To display the status of a service or to restart a Windows service with PowerShell, enter the following commands:
Get-Service -Name "Dhcp Server"
Restart-Service -Name "Dhcp Server"
6. Edit network configuration files
Text editors such as Vim are useful because they can modify configuration files for network services, such as Apache, SSH and name resolution. Text editors make it quick and easy to work with basic text files. While word processors like Microsoft Word and LibreOffice Writer can work, they aren't always good for when you want to enter information.
Learn how to open, edit, save and exit editors like Vim and Nano and rely on them to generate basic documents and edit network configuration files.
7. Explore fun commands
If you've experimented with these network commands on one or more of your systems, you might now have a cluttered terminal window. One of the most helpful commands is the clear command -- or cls command -- which lets you refresh the screen.
Command | Explanation |
clear | Clear the screen of existing command output for Linux and macOS -- also works with Windows. |
cls | Clear the screen of existing command output for Windows. |
This doesn't clear the command history, so your previous commands remain available.
Many Linux and macOS systems require the sudo command to elevate privileges to execute network commands. You can add a fun option in the sudoers configuration file that insults users if they type the wrong password.
Add the following line to the sudoers file. You can edit the file with the following visudo command:
Defaults insults
Save your changes, and close the file. Attempt a sudo command, and deliberately enter the wrong password.
8. Use commands in the GUI
Not every administrator wants to manage network tasks at the CLI, and not all situations warrant it. However, it can still be useful for GUI users to type commands.
Open a folder in the Windows terminal. Press Shift, and right-click in the folder. The context menu offers the option to open a command window here. Browse to the C:\Windows\system32\drivers\etc folder, which is the location of the host's name resolution file.
Another way to open a folder in the Windows CLI is to browse to the folder in Windows Explorer and then drag and drop it to the terminal window.
It's quick to type a command to open a Windows management console, control panel applet or folder. Press Ctrl+R to open the Run window.
The following table includes commands you can use to open network-oriented consoles.
Command from the Run box | Explanation |
ncpa.cpl | Open the Network Connections Control Panel applet. |
control firewall.cpl | Open the Windows Defender Firewall Control Panel applet. |
compmgmt.msc | Open the Computer Management console. |
services.msc | Open the Service console. |
dsa.msc | Open Active Directory Users and Computers on a Domain Controller. |
C:\Users\Administrator\Downloads | Open the Administrator's Downloads folder. |
Open Server Manager, browse to Tools and select Services to open the console. It's also quicker to press Ctrl+R and type services.msc.
Wrap-up
It can be beneficial for network administrators to work with commands from the CLI. Advantages of using the CLI for network tasks include the following:
- Scriptable commands. You can add these commands to scripts to automate tasks.
- More options. Command prompts almost always have more options for commands than their GUI equivalents. GUI tools usually only offer the most common options.
- Redirect output to a file. You can use the >> redirector to write command results to a file, which is handy if you want to keep the information for future reference or analysis.
- Faster to keep your hands on the keyboard. It's more time-consuming to reach for and maneuver the mouse than it is to keep your hands on the keyboard.
- Tab completion. Tab completion enables you to work faster and reduces typographical errors.
- History. A record makes it easier to repeat recent commands.
The CLI can be intimidating with all its network commands to remember. However, the more you commit to it, the faster you learn. Commands are scriptable in a way that graphical mouse clicks aren't, which makes them a critical part of automation and orchestration processes.
Look into ways to customize the terminal to make it comfortable and useful for you. For example, you can change font sizes and background colors. You can also alias long commands to make them easier to remember and type. Don't forget tab completion and history.
You can master network tasks with the CLI if you start small. Find several network management tasks that you do regularly and jot down the related commands. Make it a habit to use the commands instead of the mouse to accomplish your tasks. Place a shortcut to the terminal in your taskbar or dock to remind yourself to use it. The more you practice, the more you'll find the CLI useful.
Damon Garn owns Cogspinner Coaction and provides freelance IT writing and editing services. He has written multiple CompTIA study guides, including the Linux+, Cloud Essentials+ and Server+ guides, and contributes extensively to TechTarget and CompTIA Blogs.