I recently started using CrunchBang linux on my IBM T43 laptop. I really like CrunchBang and highly recommend it for those looking for a minimalistic , lightweight alternative to Ubuntu, especially on older machines. However, by default, it, or more accurately, its window manager Openbox, makes heavy use of the keyboard “Super” key (also called the “Windows” key) to open many of the most used applications. For example, Super+t opens the default terminal emulator, Super+w opens the default browser, etc. Now normally this would not be a problem, unless of course you own an IBM T43 laptop, in which case you have no windows key. Sure I could go through the hassle of changing all those key assignment in Openbox to something else, say Alt+w, but then both Alt keys would be dedicated to the task. I also wanted to mimic the same key behavior I currently use in Windows. In Windows I assigned my right Alt key as the “Windows” key. Here’s what worked for me in CrunchBox.
First I created the file .Xmodmap so I could add my own key map changes. The standard location for .Xmodmap is your home directory and it (and any key map changes contained therein) should load automatically at start up.
1
touch~/.Xmodmap
Then I opened the file and added the following lines:
1
2
3
4
remove mod1=Super_R
remove mod1=Alt_R
keycode108=Super_R
add mod4=Super_R
Rebooted and now have a working right Alt key acting as the Super key.
While the default XTerminal or Gnome Terminal that comes with Ubuntu is just fine, I had the occasion recently to use Xubuntu, a Ubuntu derivative that uses the Xfce desktop environment. I really fell in love with Xfce-Terminal, Xubuntu’s default terminal emulator. This article will describe how to install Xfce-Terminal and configure some of its options.
Written for the Xfce desktop environment, Xfce-Terminal is a modern, lightweight, and low memory cost terminal emulator for X11. It offers full-customization for the key bindings, the aspect ratio, the colors, and the ability to use multiple tabs with terminals within a single window. Most importantly though, it doesn’t bore you to tears looking it all the time.
Figure 1
Install and Configure
To install Xfce-Terminal on Ubuntu use apt-get:
1
sudo apt-get install xfce4-terminal
To install Xfce-Terminal on Fedora* use yum:
1
su-c'yum groupinstall xfce'
* A quick note concerning the installation on Fedora. The Xfce project site offers the source tarball for Xfce-Terminal but I simply ran into too many unresolvable package dependency problems while trying to compile it on Fedora 11. This command simply installs the Xfce desktop environment, which includes Xfce-Terminal, and you won’t have to switch to Xfce in order to use it.
After the package is installed you can find a link to Xfce-Terminal under Applications -> Accessories (Ubuntu) or Applications -> System Tools (Fedora). Of course, you can also start from the application launcher – just hit Alt-F2 and use the command xfce4-terminal (Ubuntu) or Terminal (Fedora). Xfce-Terminal will use the login shell of the user who starts the application (/bin/bash in case of a typical Linux system).
Configuration is easy. Open Edit->Preferences to bring up the Preferences dialog allowing you to tweak Xfce-Terminal to your liking. The settings are stored in ~/.config/terminalrc (Ubuntu) or ~/.config/Terminal/terminalrc (Fedora), which also stores a few hidden options for settings that are not included in the user interface.
You can also customize the behavior of Xfce-Terminal by passing along options via the command line. For example:
1
xfce4-terminal--geometry80x40--title foo
In this case, the terminal will launch with a window that is 80 columns * 40 rows and with the title “foo.”
One of the things I also find really useful is the tab feature that enables you to open several terminals within a single window. Since each tabbed terminal in the window is a separate subprocess, you can also use each terminal for a different task. For example:
1
xfce4-terminal--tab--command nano
This would result in two tabs; one terminal window open and ready with a command prompt, the other open with nano ready to go.
Just substitute Terminal for xfce4-terminal in the preceding commands when working in Fedora.
Conclusion
Terminal emulators are like your significant other – you have to be with them all the time so you might as well get the one you want. Xfce-Terminal is certainly worthy of a look for those looking for a nicer experience than the standard XTerminal or GNOME Terminal. You can find out more about Xfce-Terminal at the developer’s site.
Have a favorite terminal emulator? Leave a comment on what you use and why you like it.
(20161025 – The software versions used in this post were updated — iceflatline)
(20150902 – The steps and script in this post were amended to remove logging — iceflatline)
This post will describe how to install and configure Tobi Oetiker’s MRTG (Multi Router Traffic Grapher) on your Ubuntu server. All steps assume that the Apache http server is installed and operating correctly. Once configured, you’ll be able to use MRTG to monitor the traffic in and out of your network using the SNMP capability in your network’s gateway\router. MRTG generates static HTML pages containing PNG images which provide a visual representation of this traffic. MRTG typically produces daily, weekly, monthly, and yearly graphs. MRTG is written in perl and works on Unix/Linux as well as Windows. MRTG is free software licensed under the GNU GPL.
Software versions used in this post were as follows:
Ubuntu Server v16.04.1 x64 LTS)
mrtg v2.17.4-3ubuntu1
So, let’s get started.
Download and Install
First, update your package list:
1
sudo apt-get update
Then download and install MRTG:
1
sudo apt-get install mrtg
If this is the first time installing MRTG on your server you’ll likely be presented with the following message (See Figure 1). Answering “Yes” means that the MRTG configuration file will not be readable by others (file permissions set to 640). Answering “No” means that the file is readable by others (file permissions set to 644). In this example we’re going to accept the default Yes.
Figure 1
MRTG installs a sample configuration file /etc/mrtg.cfg used to hold the SNMP information obtained from your gateway\router. For a full listing of what MRTG installs and where, run the locate command:
1
sudo updatedb&&locate mrtg
Technically speaking, mrtg.cfg could remain in /etc, but just to keep things tidy let’s create a directory for it and move it into that directory:
That’s it for installing MRTG. Now let’s move on and configure it.
Configure
MRTG includes a script called cfgmaker that will help us populate /etc/mrtg/mrtg.cfg with the information obtained from your gateway\router. But before you run cfgmaker, you should setup the SNMP service in your gateway\router. This usually involves logging into your gateway\router and enabling SNMP. The default SNMP community name is typically “public.” If you change the SNMP community name to something else, make note of it. Now, run the following command, substituting your SNMP community name, if you’ve changed it, and adding the IP address of your gateway\router:
If you would like to add more than one gateway\router to MRTG simply append the additional URL(s) to the same mrtg.cfg file. Then, when you build the web page using the indexmaker command described below, all the gateway\routers (and their associated graphs) will be displayed on the same HTML page.
Next, open /etc/mrtg/mrtg.cfg and make sure under Global Configuration Options that the lines “WorkDir: /var/www/mrtg” (under Debian), and “Options[_]: growright, bits” (under Global Defaults) are uncommented. Finally, add the following lines to the existing line EnableIPv6: no under the Global Defaults section:
1
2
RunAsDaemon:Yes
Interval:5
What does all this do? The line RunAsDaemon: Yes will enable MRTG to…um… run as a daemon. This is beneficial because MRTG is launched only once, thus the parsing of the /etc/mrtg/mrtg.cfg file is done only once, not repeatedly as would be the case if one were to run MRTG as a cron task – another acceptable method for running MRTG. Also, when running as a daemon, MRTG itself is responsible for timing the measurement intervals; therefore, we need to add the Interval line option and assign it a value – in this example 5. This means that every five minutes MRTG will poll the SNMP service in your gateway\router and update its graphs. Finally, since many gateway\routers do not currently support SNMP over IPv6, we’ll retain the line EnableIPv6: no.
Speaking of graphs, by default MRTG graphs grow to the left, so by adding the option “growright” the direction of the traffic visible in MRTG’s graphs flips causing the current time to be at the right edge of the graph and the history values to the left. We’ve also chosen the “bits” option, which means that the monitored traffic values obtained from your gateway\router are multiplied by 8 and displayed bits per second instead of bytes per second.
Okay, now it’s time to create the web pages which display the MRTG graphs using the indexmaker command. Run the following commands:
Open /etc/apache2/apache2.conf and add the following lines in the section containing similar Directory directives:
1
2
3
4
5
6
7
Alias/mrtg"/var/www/mrtg/"
<Directory"/var/www/mrtg/">
Options None
AllowOverride None
Require all granted
</Directory>
Then restart Apache:
1
sudo service apache2 restart
When restarting Apache you may receive a warning concerning its inability to “…reliably determine the server’s fully qualified domain name…” This non-critical error can be fixed by adding the following line to /etc/apache2/apache2.conf:
1
ServerName locahost:80
MRTG has been configured. Let’s start it up and see what it displays.
Start
There’s something important to keep in mind when starting MRTG, and that is that MRTG requires the environmental variable “LANG” to be C in order to run properly. Since most Linux systems these days, including Ubuntu server, use UTF-8 (run echo $LANG to see what your system uses), let’s change LANG to C and start MRTG using the following command:
1
sudo env LANG=C/usr/bin/mrtg/etc/mrtg/mrtg.cfg
When you run MRTG for the first time you may see a lot of complaints about missing log files. No worries, this is normal for the first 2-3 times you start MRTG this way. If, however, it continues to complain you may want to look into the source of the problem.
Well, that’s it. Now point your browser to http://your-server-address/mrtg and you should see a page that resembles Figure 2. You may have more or less graphs depending on the number of interfaces reported by your gateway\router(s).
Figure 2
Because of the aforementioned option in /etc/mrtg/mrtg.cfg, you’ll see the graph starting “grow” to the right as the traffic is monitored over time, and the Y axis displayed as bits per second. If you click on any one of these graphs you’ll be taken to another page showing individual graphs for 30 minute, two hour, and daily averages, along with the maximum, average, and current bit rate in and out of that particular interface. Only interested in displaying one particular interface? Want to graph other SNMP data? No worries, just remember to run indexmaker again to update the MRTG index.html file.
Okay, so now that we have MRTG installed, configured and running let’s move on and discuss how to keep it running.
Operate
Starting MRTG by hand is not ideal in the long run. So perhaps after you’ve done some tweaking on MRTG and are satisfied with the results, you can automate the process of running MRTG by using a startup script in your system startup sequence. Here’s the script that I use:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /bin/sh
### BEGIN INIT INFO
# Provides: mrtg
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mrtg init script
# Description: This file is used to start, stop, restart,
# and determined status of the mrtg daemon.
# Author: iceflatline <iceflatline@gmail.com>
### END INIT INFO
### START OF SCRIPT
set-e
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="mrtg"
NAME=mrtg
DAEMON=/usr/bin/$NAME
DAEMON_ARGS="/etc/mrtg/mrtg.cfg"
PIDFILE=/etc/mrtg/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the mrtg package is not installed
[-x"$DAEMON"]||exit0
# Load the VERBOSE setting and other rcS variables
./lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
To use the script, save it to your home directory as mrtg and make it executable. Then move or copy it to /etc/init.d:
1
2
3
cd~
chmod+xmrtg
sudo mv mrtg/etc/init.d/
Now, link the mrtg script to all of Ubuntu server’s multi-user run levels (2-5):
1
sudo update-rc.dmrtg defaults
Now, let’s start MRTG using our script. If it’s currently running then substitute restart for start in the following command:
1
sudo service mrtg start
That’s it. Now if for some reason your server is rebooted, MRTG should fire up automatically. If you would like to remove the MRTG script from the server’s multi-user run levels, use the command sudo update-rc.d -f mrtg remove).
Conclusion
This concludes the post on how to install and configure MRTG on Ubuntu server. As you can see, MRTG isn’t terribly complicated and proves to be a really nice open source package for monitoring and displaying traffic in and out your network from virtually anywhere you have a web browser. For a full list of all the configuration options and other information I encourage you to visit the MRTG web site.