Thursday, September 16, 2010

Connecting to Multiple Networks

Here in my job I have to connect to two networks, one the intranet of the company and other a 3G network in order to access my email (since I am not a employe I don't have a company mail, and use a free one for everything).

Since I only really need to use the company network to access the nodes I do support, the best option would be connect to both network and use the company one when I try to access the nodes, and the 3G network for everything else (which would basically mean all the internet). Before using this solution I was always needing to change from one network to another depending on what I needed to do.

So, how to do that? It is so incredible easy that took me some weeks to find out! ;)

Basically you first need to connect to both networks (one at a time), and take a look at your routing table.

Ok, so, first I connect to my company network (via cable, which in my case mean that interface eth0 will be used), and it gives me a routing table like the following (obviously, I am changing the address):
$ netstat -rn 
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.10.10.1   0.0.0.0         UG        0 0          0 eth0

Ok, so lets disconnect and see how it looks like when connecting to the 3G (which in my case is the ppp0 interface):

$ netstat -rn 
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1   0.0.0.0         UG        0 0          0 ppp0

It can have some other lines in the configuration, but the "0.0.0.0" line (depending on the configuration it will be shown as "default").
Well, once you have the default route information, just connect to both networks, delete the default route, and add the route you want, in my case I do something like this:

route del default
route add -net 10.10.8.0/23 gw 10.10.10.1 dev eth0
route add -net 10.11.0.0/16 gw 10.10.10.1 dev eth0
route add -net 10.12.50.0/24 gw 10.10.10.1 dev eth0
route add default gw 192.168.1.1 dev ppp0

Where the first line delete the current default route, the 3 next lines add the routing to the nodes I need to have access in my work, and the other creates a default route for everything else to go through the 3G connection.

Hope it helps you people!

Wednesday, September 15, 2010

Java Plugin 64bits

As someone may have already notice I am using this blog more as a way to remind myself some little things to do when I install a new Linux than any other thing.

And here is another small but importante detail: In the newer versions of Sun Java for 64bits environments there is already a native plugin for your browser, in debian you just need to do this to be happy:

ln -s /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins/libnpjp2.so

Since /usr/lib/jvm/java-6-sun is a link to the newest java-6 version, you will only need to change the link if you want to change the java from 6.x to 7.x (which is not likely to happen frequently), otherwise even in the usual java updates you won't need to worry about anything, except maybe a Firefox / Iceweasel messages saying that some plugins have been changed and it need to be restarted.

MS Office in Linux

In the newer versions of wine is incredible easy to install the versions of MS Office prior to 2007, but after doing that I had some little trouble on how to make KDE use the MS Office Applications to correctly open a MS Office document when I click on it.

Well, the answer, as usually happens in Unixes, come as the form of a script.

Actually, two scripts for each MS Office application, on when you call it via shell and the other to be used exclusively when it is called by KDE.

Here is the one to be used by the KDE configuration, I usually place it under /usr/local/bin/winword-gui, and here are its contents:

#!/bin/bash
FILENM=$( basename "$@" )
UNXDIR=$( dirname "$@" )
WINDIR=$( echo $UNXDIR | sed 's@\/@\\@g' )
DOCPTH="Z:$WINDIR\\$FILENM"
/usr/bin/wine "C:\Program Files\Microsoft Office\Office12\WINWORD.EXE" "$DOCPTH" &

After creating this file you just right click on some .doc file in KDE and go "Open with -> Other" and select the file you created.

And, if you want to call it via shell, you can have this other script named /usr/local/bin/winword:

#!/bin/bash
/usr/bin/wine "C:\Program Files\Microsoft Office\Office12\WINWORD.EXE" "$@" &

Obviously depending on your wine configuration and office installation you need to change the last line of both scripts.

It could also be done in just one script, but since I am so lazy I prefer to just let it like this.

For the other MS Office applications, you create the same scripts but change the last line for the program you want (EXCEL.EXE, POWERPNT.EXE or whatever).

Ear phone not working in HP Pavillion

Here is what I had do add to my /etc/modprobe.d/alsa-base.conf so my ear phones start working, without it when I plugged it nothing changes, the sound keep going out only by the speakers.

Those are the magic lines:

alias snd-card-0 snd-hda-intel
alias snd-card-1 snd-usb-audio
alias sound-slot-0 snd-hda-intel
options snd-hda-intel index=0 model=hp-dv5 enable-msi=1 position-fix=1
options snd-usb-audio index=1

Peace!

Things I usually add to my bashrc

Here are some little things I usually like to add to my bash configuration, since I used debian the file is /etc/bash.bashrc, but could also be ~/.bashrc:

readonly HISTTIMEFORMAT="%d/%m/%Y at %T: "
readonly HISTFILESIZE=5000
export HISTCONTROL="erasedups"
readonly command_oriented_history=1
export HISTTIMEFORMAT HISTFILESIZE HISTCONTROL command_oriented_history
source /usr/bin/funcoeszz
shopt -s histappend
shopt -s cdspell
shopt -s dirspell
history -a
set -o vi
if [ -x /usr/games/fortune ]; then
        echo
        /usr/games/fortune -a
        echo
fi

Much funnier than default!

Monday, September 13, 2010

Backup Files Bigger than 4Gb in FAT Filesystems

Sometimes we need to copy files to Fat filesystem that are larger than 4Gb, which this filesystem do not support, if I need to do that just for some period (as backup), I use the following:

$ rar a -m0 -v500M -R <rar-file-name> <original-file>

It won't compress the file (-m0 parameter) and will divide the file into smaller 500M file (-v500M parameter).

I already used it in a lot of situations where I really needed to free some space in a more decent filesystem (usually my XFS home or root partitions).

Peace!

Backup with rsync

Millions of years after the last post I decided to make it come to live again, lets see for how long.

Simple, simple thing to start the new era, that's how I am usually making the backups from my work directory in my machine to the external disk:

rsync -av --link-dest=/Backups/2010-09-07/ ~/Work/ /Backups//2010-09-08/

This way everything that already exists in the previous backup (2010-09-10 directory) will be hard linked to the new backup, so my space is not all wasted and I can keep track of what was changed from backup to backup.

That's funny how the size is shown when you use those hard links:

$ mkdir 1 2
$ dd if=/dev/zero of=./1/somefile bs=1k count=5120
5120+0 records in
5120+0 records out
5242880 bytes (5.2 MB) copied, 0.0218812 s, 240 MB/s

$ ls -lrth *
2:
total 0

1:
total 5.0M
-rw-r--r-- 1 andre wheel 5.0M Sep 13 17:32 somefile

$ ln 1/somefile 2/somefile-hard-link
$ ls -lrth *
1:
total 5.0M
-rw-r--r-- 2 andre wheel 5.0M Sep 13 17:32 somefile

2:
total 5.0M
-rw-r--r-- 2 andre wheel 5.0M Sep 13 17:32 somefile-hard-link

$ du -ksh *
5.0M    1
0       2

$ rm 1/somefile

$ ls -lrth *
2:
total 5.0M
-rw-r--r-- 1 andre wheel 5.0M Sep 13 17:32 somefile-hard-link

1:
total 0

$ du -ksh *
0       1
5.0M    2

Nice, hm?