Ákos Takács
Posted on December 25, 2023
Introduction
There are some tools that we almost always install on our servers. Sometimes we install them immediately, and sometimes we realize what is missing later, and install it then. In this post we will discuss the tools I always install on Ubuntu servers. Although the following package names will be for Ubuntu linux, most of the tools can also be installed on other distributions as well and some of them, like jq and yq can be installed on macOS as well.
Table of contents
- Common network tools
- Python 3 support
- Formatting tools for scripting and user-friendly outputs
- Packages for downloading files and webpages
- Monitoring tools in command line
- User manual related packages
- Text editors
- Conclusion
Common network tools
bridge-utils
It contains the brctl command which can manage bridge interfaces. The brctl command can be replaced with the "ip" command, but it is useful to have it in case you copy-paste some commands from tutorials where brctl is used.
To list bridge interfaces, you could use the following command for example:
brctl show \
| awk -F $'\t' '$1 != "" {print $1}' \
| tail -n +2
Example output:
br-35a7f7573daa
br-40c75c6946c5
br-415f86d29b58
br-85776ec34ce3
br-a39b1276c115
br-be88ce1dc3d8
br-c506658ca645
docker0
net-tools
It contains "netstat" which can also be replaced with another command called "ss" which is part of the "iproute2" package on Ubuntu. A common netstat command is the following to list used ports on which processes are listening:
netstat -tulpn
Output example:
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8952 0.0.0.0:* LISTEN -
tcp 0 0 192.168.4.58:53 0.0.0.0:* LISTEN -
tcp 0 0 10.17.181.1:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:61209 0.0.0.0:* LISTEN -
tcp 0 0 192.168.4.58:5432 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp6 0 0 ::1:8952 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
udp 0 0 10.17.181.1:53 0.0.0.0:* -
udp 0 0 192.168.4.58:53 0.0.0.0:* -
udp 0 0 0.0.0.0:67 0.0.0.0:* -
iproute2
Usually installed by default on recent Ubuntu distros. It gives you the "ip" command to manage IP addresses and network interfaces. It also contains the "ss" command which can be used instead of "netstat".
The alternative command to the previously mentioned brctl command is the following:
ip -json link show type bridge \
| jq -r .[].ifname \
| sort
This specific command requires jq which I will write about later.
If you want to replace the netstat command with the newer "ss" command, you can run the following:
ss -tulpn
As you can see the parameters are the same, but the output will be slightly different:
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
udp UNCONN 0 0 10.17.181.1:53 0.0.0.0:*
udp UNCONN 0 0 192.168.4.58:53 0.0.0.0:*
udp UNCONN 0 0 0.0.0.0%lxdbr0:67 0.0.0.0:*
tcp LISTEN 0 5 127.0.0.1:61209 0.0.0.0:*
tcp LISTEN 0 32 10.17.181.1:53 0.0.0.0:*
tcp LISTEN 0 256 192.168.4.58:53 0.0.0.0:*
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
tcp LISTEN 0 244 192.168.4.58:5432 0.0.0.0:*
tcp LISTEN 0 16 127.0.0.1:8952 0.0.0.0:*
tcp LISTEN 0 128 [::]:22 [::]:*
tcp LISTEN 0 16 [::1]:8952 [::]:*
Python 3 support
Python 3 is recommended usually instead of Python 2. This role also installs common tools which we use in a Python environment:
python3
The main package for Python 3. Sometimes you want a specific version if the APT repository supports multiple versions. Then you could specify that like python3.11
if the exact version number matters.
python3-pip
Pip package manager for Python 3. If you install python3.11
then the package name will be python3.11-pip
python3-venv
The venv module is one of the modules that can create a virtual environment.
Example:
python3 -m venv venv
python3-virtualenv
The virtualenv module is also one that can create a virtual environment. It is probably better known than venv, but you can use very similarly.
python -m virtualenv venv
Formatting tools for scripting and user-friendly outputs
jq
To handle JSON files and JSON outputs in a script or format and highlight it, jq can be very handy. Many command line tools provide a json output, so you don't have to write a custom parser for a table a list in a terminal. Instead of that, you can use jq to get a specific value from the output or even modify the output. For more information, you can visit https://jqlang.github.io/jq/
Example:
lxc list --format json docker \
| jq -r .[].created_at
The above command is similar to what we will discuss in the near future in another post. Docker also supports JSON outputs, so jq can be useful in case you are not comfortable with golang templates.
python3-pygments
It will install the "pygmentize" command to highlight contents of files like source codes in the terminal. It isn't required for JSON because of jq, but it could be useful for other kind of outputs.
For example instead of using cat lxd-init.yml
to get the content of a yaml file (which we did before in previous chapters), you can use the pygmentize command and have a highlighted, colorized output:
pygmentize lxd-init.yml
If you want to read about the installation of LXD for running virtual machines and containers on Linux, read Creating virtual machines with LXD
Instead of remembering the name "pygmentize" you would probably prefer "highlight", so you can also add a symbolic link to "pygmentize".
ln -s /usr/bin/pygmentize /usr/local/bin/highlight
yq
yq is similar to jq, except it is for YAML files. Let's say you want to get the profile definitions from an lxd init yaml. You can run the following:
yq .profiles lxd-init.yml
Example output:
- config: {}
description: ""
devices:
eth0:
name: eth0
network: lxdbr0
type: nic
root:
path: /
pool: default
type: disk
name: default
For more information about this command visit https://github.com/mikefarah/yq
Packages for downloading files and webpages
curl and wget are two popular commands to download files from the internet or just handle API calls. I usually install both of them, so whatever commands I find in a documentation, I can copy and paste. However, I prefer using curl. Curl is also implemented in programming languages like PHP.
Example commands with curl and wget to get the response header and follow redirections:
curl -L http://google.com
wget -O- -S --spider http://google.com
Compress and decompress files
On Linux I usually use "tar" and "gzip" to compress files. Sometimes I need to download a release from GitHub or any file compresses with zip, so I also install "zip" and "unzip".
Monitoring tools in command line
htop
Probably everyone knows about the "top" command. Htop is similar, but gives us a more user-friendly output. It shows processes using the most resources, how much available resources you have and who runs those processes. For more information, visit https://htop.dev/
btop
Btop is even more advanced than htop. It is almost like a GUI in terminal, and it feels like a dashboard of an airplane. I like it, but when I want to see what processes are using most of my resources, it is usually htop
that comes to my mind and not btop
, since btop shows more by default than I usually want. For more information see https://github.com/aristocratos/btop.
glances
It has a web-based interface too, but you can use it from terminal. "Glances" shows information about Docker containers too by default, so when it comes to Docker containers, it is really useful. For more information see https://glances.readthedocs.io/en/latest/
I created the screenshot in a virtual machine (which we will create together in a following tutorial) where I have Docker installed. As you can probably see (click on the image if it is too small), there is a "containers" section as well.
User manual related packages
The "man" command is almost always available on Linux, but sometimes it is missing. Some virtual machine images and container images don't come with this package, so I installed it to make sure I always have it, so I can get the user manual of curl for example.
man curl
Text editors
nano
A simple text editor in terminal with limited capabilities, but it is very easy to use. I usually prefer this one and I don't care how many people tell me that vim is much better. When I want to edit a simple file quickly like /etc/hosts
I don't need any advanced editor and when I need an advanced editor, I almost always have GUI, so I can use VSCode for example.
vim
An advanced text editor in terminal which is very popular. It has many keyboard shortcuts for example to delete multiple lines and other tasks which is not as simple in a terminal as it would be with a GUI. Even if I usually don't need it, I install it, because it could be useful sometimes.
Conclusion
The list I shared in this post shows what I install on my servers. Those servers are usually debian based like Ubuntu, but whatever Linux distributions I run, I like to use the same tools. For example, I use nano, jq, curl almost every day on my macOS.
I also use Docker and although it has a command line part as well, it is much more than that, so I didn't include it in this list.
Posted on December 25, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.