Sunday, October 17, 2010

Make an incredibly fast Linux Desktop with Fluxbox

There are a lot of Linuxers out there who make use of lightweight window managers due to the benefit of having a customized and lightning fast Desktop environment yielding productivity on a cheap machine. Fluxbox is this kind of window manager and has been r00tb0x's favorite for a long time.

This article will not cover a detailed installation of fluxbox as it is a fairly easy process if you have a decent package manager such as apt-get:

apt-get install fluxbox

After installation, reboot the machine and choose Fluxbox as your default window manager. If you have problems installing Fluxbox you can just visit the official website. Once you are inside Fluxbox you might get lost. So the following are configuration tips to maximize your environment:


Changing the background:
This task is not a right click on the desktop, select background, and save the settings. You would need to execute the following command from terminal:

fsetbg -f /path/to/wallpaper.jpg

Keyboard Shortcuts:
The default Fluxbox is not very usable. To launch an application you need to click on the desktop and select the application from a little context menu (TWM lookalike) which is very unpractical. However when you assign keyboard shortcuts, Fluxbox becomes an efficient monster. The ones defined by default are the F1 to F12 keys and are assigned to change the workspace. While switching workspace is a common task, there are other important shortcuts to define such as minimizing and closing windows and launching applications. All the key bindings are defined inside ~/.fluxbox/keys file. Note that Mod1 refers to 'alt' and Mod4 refers to the windows key.

As a tip, you can define most of shortcuts through the Mod4 key so they do not interfere with the inbuilt applications' shortcut keys. This is an extract of a configuration file which was used by one of the authors at r00tb0x, and which you can easily adapt to your desktop as you wish:

# locks X11 display to the current user
Mod4 l :ExecCommand xscreensaver-command --lock
 
# opens a number of programs with quickkeys. These are just examples, I am sure
# you get the point...
Mod4 f :ExecCommand firefox
Mod4 e :ExecCommand firefox <a href="http://gmail.google.com" title="http://gmail.google.com">http://gmail.google.com</a>
Mod4 i :ExecCommand aterm -name aterm -sl 3000 -tr +sb -sr -sk -bg black -fg white -fade 90 -bl -tn xterm -fn -misc-fixed-medium-r-normal-*-*-120-*-*-c-*-iso8859
-15 -g 116x57 -e /usr/bin/irssi
Mod4 g :ExecCommand gaim
Mod4 u :ExecCommand amule
Mod4 m :ExecCommand gmplayer <a href="http://wm.smgradio.com/vruk_vc_hi" title="http://wm.smgradio.com/vruk_vc_hi">http://wm.smgradio.com/vruk_vc_hi</a>
Mod4 v :ExecCommand vmware
Mod4 Print :ExecCommand gnome-screenshot
 
# This launches fbrun, which in turn launches other programs
Mod4 r :ExecCommand fbrun
 
# Program Control. It just makes life simpler...
Mod4 4 :Close
Mod4 q :Minimize
Mod4 w :Deiconify All OriginQuiet
 
# if you have aterm (emerge x11-terms/aterm), then this opens a really nice
# transparent aterm with no borders, fitting nicely with 1024x768
# resolution, while still leaving room for conky. Once again, feel free to
# modify.
Mod4 a :ExecCommand aterm -name aterm -sl 3000 -tr +sb -sr -sk -bg black -fg \
white -fade 90 -bl -tn xterm -fn \
-misc-fixed-medium-r-normal-*-*-120-*-*-c-*-iso8859-15 -g 116x57
 
# Fluxbox has no sound control, so we need to do a hack to get one
# Modify Sound
Mod4 F11 :ExecCommand aumix -v -3
Mod4 F12 :ExecCommand aumix -v +3
 
# Reconfigure Fluxbox
Control Mod4 Delete :Reconfigure

This is a very powerful configuration and will maximise your productivity - We guarantee you that with these shortcuts you will not use the mouse for a while, and it is only a little portion of what you can define in Fluxbox. Note that in the last part of the configuration we are also including the possibility of changing the sound volume through keyboard as well - you just need to install aumix, which is a command line mixer but takes arguments so volume is altered on the fly.
Startup Programs:
You might need to execute a bunch of commands when you start fluxbox, such as setting the desktop, or launching some scripts. You can make all these configurations inside the ~/.fluxbox/startup file. Just add entries to that file and next time you boot into fluxbox, they are executed on startup. This is an extract of our startup file:

# Define background:
fbsetbg -f /home/r00tb0x/wallpapers/43492-escher.jpg
 
# Applications you want to run with fluxbox.
# MAKE SURE THAT APPS THAT KEEP RUNNING HAVE AN ''&'' AT THE END.
gnome-settings-daemon&
gkrellm&
amule&
fetchmail -d 60&

Save Window positions:
One of the most things I enjoy in fluxbox is the possibility to save window sizes, positions, and workspace locations. This is a feature which one cannot find in other environments such as Gnome or KDE. This is ideal if you want to launch certain applications in the same workspace so that your default workspace will not be cluttered. Again, this is another reason why Fluxbox increases your efficiency and productivity.

To save the window position, just right click on the window and select Save Window Position from the context menu.

One word of advise...Make yourself a favor a get used to Fluxbox for a couple of days before you give up and return to your old overbloated windows manager.

Friday, October 01, 2010

Setting up a Linux box as a router

If you have a virtual machine in a Linux host which requires Internet and physical LAN connectivity, or you just need to pass all traffic of a LAN through a Linux machine, you may need to set up Linux as a router.

Prerequisites:
Enable IP forwarding on the Linux box
Create a NAT rule to masquerade the IP

A virtual private IP must be configured on the Linux machine:

ifconfig eth0:1 192.168.1.1


This will serve as the gateway address for the other machines in the network (or of the virtual machine). In this case the other machines must have an IP in the form of 192.168.1.x. IP forwarding must be enabled:

echo 1 > /proc/sys/net/ipv4/ip_forward


Then we need to create the NAT rule to masquerade the private IP into a public one:

iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE

That's it! Remember that for the other machines you must set the gateway IP as 192.168.1.1. You might also need to enter the DNS details (you can easily obtain it from dig [your ISP]. To list all the NAT rules:
iptables -t nat -L

To delete the NAT rule:
iptables -t nat -L

If you need to access your windows share, you can use smbclient as follows:
smbclient -U r00tb0x_user //192.168.1.2/public
smb: \] dir
file1.txt
file2.txt

Note that you can do all the FTP stuff here..If you want to list shares available on a windows host:
smbclient -U r00tb0x_user -L //192.168.1.2/
If you want to mount a SAMBA share on your filesystem:
mount -t smbfs -o username=r00tb0x_user //192.168.1.2/public /mount/point