Google
 

Thursday, February 25, 2010

Internet Connection Sharing in Linux over Ad-hoc Wireless

Laptops are common these days and so is wireless networking that comes with it. Almost all of us use Wireless Router for wireless networking and internet sharing. But most of us might not be familiar with ad-hoc mode that works in every wireless card and can eliminate the use of router altogether. Here's how:

To setup ad-hoc wireless, you basically set two or more wireless cards to same ESSID in ad-hoc mode and different IP addresses.

Setting the wireless card in ad-hoc mode

Generally iwconfig is used to set the wireless mode, but if you have madwifi drivers (see this too), the commands are slightly different. Go to terminal and type,

iwconfig
If you see interfaces named wlan0, wlan1, etc iwconfig will work. If you see interface names similar to ath1 and wifi0, then madwifi specific commands are to be used.

For general wifi cards:
sudo iwconfig wlan0 mode ad-hoc
Replace wlan0 with the interface name as listed by iwconfig

For cards using madwifi driver:
sudo wlanconfig ath1 destroy
sudo wlanconfig ath1 create wlandev wifi0 wlanmode adhoc
Now set essid. Pick some name like 'adhocwifi'
sudo iwconfig wlan0 essid adhocwifi
If required, to set encryption key
sudo iwconfig wlan0 key 1234567890
Now set IP address:
sudo ifconfig wlan0 192.168.0.1
Follow the above steps for another wireless card and set IP address in same subnet, say 192.168.0.2, and ping each other.

The whole ad-hoc mode setting can also be done using GUI network-manager, but since i'm not so much fond of graphical interface i'm not covering it. It should be simple.. :)

Internet Connection Sharing

Now to share the internet over wireless,
sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
where ppp0 is the connection you want to share (PPPoE connection in this case)

You also need to enable IP forwarding:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Or, to enable permanently add the following line to /etc/sysctl.conf
net.ipv4.ip_forward=1
Some ISPs might limit the TTL so that you wont be able to share the internet. Fix:
sudo iptables -t mangle -A PREROUTING -j TTL --ttl-inc 1

Using the shared internet (in Linux)

Now to use the shared internet on another computer, set it to ad-hoc mode and assign IP address in the same subnet as described above and perform the following:

1. Set the IP of computer sharing internet as gateway
sudo route add default gw 192.168.0.1
2. Set DNS server. We're using Google's DNS.
sudo sh -c "echo 'nameserver 8.8.8.8' >> /etc/resolv.conf"
You can also use IP and DNS Masquerading to ease the task.


Using the shared internet (in M$ Windows)

If you want to use the shared internet on M$ Windows,

1. Connect to the Wireless Network (in this case 'adhocwifi')
2. Go to Network Connections
3. Right click the Wireless Connection
4. Select the Internet Protocol (TCP/IP) and click Properties
5. Set IP to 192.168.0.2 (or accordingly in the same subnet as set on Linux box), gateway to 192.168.0.1 (as set on Linux box) and DNS to 8.8.8.8

Friday, February 19, 2010

Overriding extension compatibility check for FF3.5+

Disabling extension compatibility check for Firefox was easy. Go to about:config and create a boolean value named extensions.checkCompatibility and set it to false.


Until Firefox 3.5!
(More specifically, products that are based on < Gecko 1.9.2)

Newer Firefox requires you to append version number to the variable. This will ensure the extension override wont work forever as FF is upgraded to next version. For example, in Firefox 3.6, the variable would be extensions.checkCompatibility.3.6

Explained in detail here:
http://kb.mozillazine.org/Extensions.checkCompatibility

Wednesday, February 17, 2010

Converting Latex document to HTML / ODT / DOC

I do all my documents in Latex. Actually i usually use emacs org-mode first and later convert it to Latex, but when it comes to using bibtex, it's all latex. It works great and the output dvi/pdf files look so professional. However recently i had to submit the file in .doc format, and i had a real hard time finding good tools to do that.

There are no direct Latex to .doc converters, so the best bet is to go Latex -> HTML -> DOC. There are lots of Latex to HTML converters like latex2html, tth and hevea, but most of them either don't produce good HTML or mess with bibliography references. But after some research i found the best: TeX4ht

TeX4ht is available in ubuntu/debian repo, so to install

sudo apt-get install tex4ht
Conversion is simple:
htlatex document
(please note, there is no .tex suffix)

This will generate document.html, css and bunch of .png files.

Now to convert it to wordprocessor files (odt, doc..),
1. Open the html file with OpenOffice.org
2. File > Save as
3. Choose the format you want to save it in (odt, doc)

If you have images in the document, they will be linked instead of embedded in the document. To fix this: (source)
1. Edit > Links
2. Click "Break Link" for each image link

Thursday, February 04, 2010

mpg123: Lightest mp3 player in Linux

If you are in search of the lightest barebone mp3 player in Linux, nothing can beat mpg123. Unless you want flashy visualizations and playlist management and such, mpg123 can save you a lot of memory and cpu horsepower.

Installation is easy. In Ubuntu,

sudo apt-get install mpg123

Mpg123 comes with loads of options. Check out the man page for details. Here I'm gonna share a few usage tips.

Shuffle-play a directory of mp3s:
mpg123 -CZ /path/to/mp3/folder/*

-Z option is for shuffle, -C is for control. From man page:
-C, --control
Enable terminal control keys. By default use ’s’ to
stop, ’p’ to pause, ’f’ to jump forward to the next
song, ’b’ to jump back to the beginning of the song,
’,’ to rewind, ’.’ to fast forward, and ’q’ to quit.
Type ’h’ for a full list of available controls.

Equalizer:

Don't fall off your chair! Yes, mpg123 also comes with 32-band equalizer. But there's no inbuilt graphical UI for that, you need to create the plain-text file. There's an editor though if you like, but creating one is not hard either. From man page:
-E file, --equalizer
Enables equalization, taken from file. The file needs to
contain 32 lines of data, additional comment lines may be
prefixed with #. Each data line consists of two floating-
point entries, separated by whitespace. They specify the
multipliers for left and right channel of a certain
frequency band, respectively. The first line corresponds
to the lowest, the 32nd to the highest frequency band.
Note that you can control the equalizer interactively
with the generic control interface.

I've made one with party feel: party.txt

Usage:
mpg123 -CZ -E party.txt mp3_file

Songs again and again:

Plus if you kind of person who listens to couple of songs again and again for weeks (instead of shuffled huge playlist), then hi5! :) and here's how to do that with mpg123:
mpg123 -CZ song1.mp3 song2.mp3

Wednesday, February 03, 2010

Making DLink DWL-650+ PCMCIA Wireless card work under linux

The DLink DWL-650+ PCMCIA Wireless card doesn't work on recent Linux distros (I tried Ubuntu Hardy to Jaunty). After plugging in, the system hangs with CapsLock flashing.

Turns out the card is handled by acx module and the support is broken for this card. So use ndiswrapper instead.

First blacklist acx module. Open /etc/modprobe.d/blacklist.conf file and add the following line

blacklist acx
Now install ndiswrapper
sudo apt-get install ndiswrapper-common
Now get the Windows driver for the card from here. Extract the file, go to the winxp folder and,
sudo ndiswrapper -i AIRPLUS.INF
The card should work now.