In this article by Michael Duffy, author of DevOps Automation Cookbook, we discover some basic command line tools. From the very basics of navigating the filesystem to the ability to run diagnostic tools to examine potential issues, every Linux systems administrator should have a solid grasp of command-line tools. The command line offers unparalleled power and flexibility as well as the ability to easily chain together commands to form powerful one-line scripts. Although GUI tools can generally be quicker to pick up and use than the command-line equivalents, a few of them offer the combination of concision and power that a well used combination of command-line tools can bring.
For system administrators who utilize DevOps techniques, the command line offers the first steps on the road to automation and offers powerful abilities that can be leveraged with full-stack automation. Ansible, Puppet, and Chef are powerful tools, but sometimes, it can be easier to write a small bash script to undertake a task, rather than writing a custom function in a configuration management tool. Despite automation, the command line will be somewhere you will spend the majority of your time. Remember that no matter how attractive a point and click tool is, it's highly unlikely that you can automate it.
Most operating systems have a command line even if they are traditionally seen as the domain of the GUI. For instance, Windows users have the option of using the excellent PowerShell tool to administer and control Windows servers.
In this chapter, we will cover some of the useful recipes that can help DevOps engineers in their day-to-day working life. These commands will cover a wide variety of topics, covering elements, such as basic networking commands, performance metrics, and perhaps the most important of all, the basics of using the Git DVCS (Distributed Version Control Software). Depending on where you approach the DevOps role from, you will find that some of this chapter talks about topics that you have already covered in depth; for instance, seasoned systems administrators will find the items on the NET tools and system performance is a familiar ground; however for a developer, these can be valuable introductions. Likewise, developers will probably find the section on Git to be nothing new, however, many systems administrators may not be used to control version systems.
Controlling network interfaces
Networking is one of the core elements of server management and can be one of the elements that can be complex to manage. This recipe will show you how to use the IP tool to both discover the details of and make changes to the networking setup of your server.
Although these are ephemeral changes, being able to apply them at the command line is very powerful, for instance, it allows you to script the addition and removal of IP addresses. When you look at the command-line tools, it's a good idea to think of not only how they can help you now, but also how they could be used to automate in future.
Getting ready
The IP tools come preinstalled on the major Linux distributions (RHEL and Debian based), so no additional configurations should be required.
How to do it
- Sometimes, you just want to know the IP address of the server you are working on; this can be found using the following command:
$ ip addr showThis should give you an output similar to to the following screenshot:

This output gives you the details of each interface, including the IP address, state, the Mac address, and the interface options.
To narrow this down to a single interface, you can use the following command:
$ ip addr show <interface>Where <interface> is the name of the network interface you wish to see details for. So for example, to see the details of eth0, you could use the following:
$ ip addr show eth0 - To add a new IP4 address, use the ip addr add command. Note that you also need to supply the netmask in the Classless Inter-Domain Routing (CIDR) format. This is how the command looks:
$ ip addr add <IP address>/<CIDR> dev <device>For example, to add a new RFC1918 compliant address to the interface named eth1, you would use the following command:
$ ip addr add 10.132.1.1/24 dev eth1You can check whether the new address is available on the interface using the ip addr show command:
$ ip addr show eth1 - Removing an IP address is a straightforward reversal of adding it. The command is basically the same as the command to add addresses, but with the delete option:
$ ip addr del <IP address>/<CIDR> dev <device>So, to remove the address that we just added, we can use the following command:
$ ip addr del 10.132.1.1/24 dev eth1 - The ip command can be used to control the physical interfaces that allows you to bring them up and down from the command line.
It goes without saying that you need to be careful when you use this command. Removing the only available interface on a remote server is both possible, and if you don't have access to a remote console, it is extremely inconvenient.
To bring an interface up, you can use the ip link set command, followed by the interface name, and then the desired state. For instance, to set the eth2 interface to be enabled, you can use the following command:
$ ip link set eth2 downConversely to bring it back up, you can use the following command:
$ ip link set eth2 upYou can also check the state of the interface using the ip command:
$ ip addr eth2
See also
You can find further details of the ip command within its man pages. You can access these using the following command:
$ man 8 ipTo learn more DevOps techniques to help with the day-to-day complications of managing complex infrastructures, take a look at the DevOps Automation Cookbook.