StepInside

Creativity and Inspiration

Entries tagged with "linux"

Connecting linux laptop to the Internet using Nokia e61

Finally I replaced my old Sony Ericsson t68i phone with new shiny Nokia e61 . It is really great smartphone (should I say multimedia computer? :) with every imaginable feature built-in. Just to name a few: 3G, Wi-Fi, Bluetoth, USB cable, Irda, MiniSD card reader, 320×240 screen, QWERTY keyboard.

While it is possible to browse internet using phone itself laptop provides much better user experience for doing it.

Connecting my linux laptop to the internet using Nokia e61 phone was surprisingly easy. I’ve managed to setup network connection using both USB cable and bluetooth in less than half an hour. Under Windows cable connection was working out of the box with Nokia software, but bluetooth doesn’t work at all (but I haven’t tried too hard to make it work).

If you want to use internet from your laptop using Nokia e61 (and most probably other Nokia phones as well) as modem you need:

  • recent kernel with bluetooth and ACM (for using phone as USB modem, CONFIG_USB_ACM kernel configuration option) support
  • bluez-utils
  • wvdial – of course it is possible to use ppp only, but I found wvdial much simpler to configure

My further instructions are gentoo specific, though they shouldn’t differ too much for other distributions.

USB modem

On my system (kernel-2.6.18, udev-103) when I plug USB cable and selected PC Suite mode on my Nokia phone proper drivers are loaded and proper devices are created automatically. This is really how it should work! After phone is connected /dev/ttyACM0 device should be created.

If you have problems with it try to load drivers manually:

modprobe cdc_acm
modprobe usbserial vendor=0x0421 product=0x044d

wvdial configuration is also very simple (T-Mobile specific):

[Dialer usb-tmobile]
Modem = /dev/ttyACM0
Phone = *99#
Username = t-mobile
Password = t-mobile

Bluetooth

Follow these steps:

  • make sure that /etc/init.d/bluetooth is started
  • add your laptop to paired deviced of the phone from Menu / Connectivity / Bluetooth (Paired devices -> Options -> New Paired Device)
  • Use sdptool browse command to find channel number that is used for dial up networking:

  ...
  Service Name: Dial-Up Networking
  Service RecHandle: 0x10052
  Service Class ID List:
  "Dialup Networking" (0x1103)
  Protocol Descriptor List:
    "L2CAP" (0x0100)
    "RFCOMM" (0x0003)
    Channel: 2
  ...
  • find bluetooth address of your phone using hcitool scan command.
  • edit /etc/bluetooth/rfcomm.conf to configure RFCOMM port:
  ...
  rfcomm2 {
        # Automatically bind the device at startup
        bind yes;
        # Bluetooth address of the device found using hcitool
        device 00:11:22:33:44:55;
        # RFCOMM channel for the connection found using sdptool
        channel 2;
        # Description of the connection
        comment "Modem (Nokia e61)";
  }
  ...
  • make sure that RFCOMM_ENABLE = true in /etc/conf.d/bluetooth
  • configure wvdial:
  [Dialer bluetooth-tmobile]
  Modem = /dev/rfcomm2
  Phone = *99#
  Username = t-mobile
  Password = t-mobile

Devices permissions

By default modem devices belongs to root group, so only root user can use them. In order to allow regluar users that belong to group tty to use modem create file in /etc/udev/rules.d with following content:

KERNEL=="rfcomm[0-9]*", GROUP="tty"
KERNEL=="ttyACM[0-9]*", GROUP="tty"

That’s all. Now type wvdial bluetooth-tmobile and go online :)

Posted by ksh on December 14, 2006 | 9 comments | e61, linux

Renaming network interfaces using udev rules

By default network interfaces in Linux have non-informative names, like eth0 or eth1. It is more convenient to give them logical names. F.e. wireless link can be named wlan and ethernet link – lan.

There are several ways to rename network interfaces but I find solution with udev to be the easiest solution. All that you should do is to add following rules to udev (usually this can be done by adding file with new rules to /etc/udev/rules.d directory):

SUBSYSTEM=="net", SYSFS{address}=="00:13:02:65:74:c1", NAME="wlan"
SUBSYSTEM=="net", SYSFS{address}=="00:18:d3:05:e3:da", NAME="lan"

SYSFS{address} in these rules is hardware address of network card and can be found in /sys/class/net/ethN/address file, where ethN – old name of the interface you want to rename. Note that string comparison in udev rules is case sensitive.

Posted by ksh on November 6, 2006 | 0 comments | linux

Starting with UML

I have been using Linux for a long time but mostly for developing high level applications in java and python and as home operating system (multimedia, Internet surfing and so on). From everyday usage I’ve gained understanding of how different parts of Linux system work together, how to configure and use various applications, how to find what’s going wrong and many other things. So my experience was mostly “in user-mode” and I have little understanding (except some common principles that are applicable to all modern operating systems) how kernel of Linux works. Recently I became very interested in it for several reasons:

  • I’ve bought laptop and there is plenty of hardware that is currently not supported by Linux, including built-in web cam, microphone and IR-receiver.
  • Linux crashed several times on my laptop and I have no idea why and even how to find out the reason.
  • Some nice features like suspend-to-ram and hibernate don’t work and again I can’t figure why.
  • It’s just interesting and about having fun :)

Unfortunately it is hard to start with kernel development especially taking into account that my knowledge of C language is limited to university courses that I took several years ago. Linux kernel is very large piece of code and it is easily possible to get lost in it.

To have something to start with I’ve decided to play with UML . In particular I’ve thought about creating my own filesystem image for running UML and running UML process in debugger. So exploring source code for UM architecture I can learn about system
programming for Linux (such things like signals, threads, etc) and at the same time learn about kernel by exploring rest of kernel sources.

In this post I am going to describe how to create very simple basic filesystem image and run UML with it.

At first you need to create empty file with ext2 filesystem inside:

dd if=/dev/zero of=minimal-1.ext2 count=10k bs=1024
/sbin/mke2fs minimal-1.ext2

To mount this file as real file system run following command as root:

mount minimal-1.ext2 minimal-1/ -t ext2 -o loop=/dev/loop1

Statically linked busybox can serve as minimal Linux distribution. Installation is pretty straightforward:

make menuconfig
make
make install

Make sure that at least following busybox applets are enabled:

  • init* (CONFIG_INIT)
  • ash (or any other shell, make it default shell, CONFIG_ASH, CONFIG_FEATURE_SH_IS_ASH)
  • mount/umount (CONFIG_MOUNT, CONFIG_UMOUNT)

and it is configured for static build (CONFIG_STATIC). It is also very convenient to configure mounted at the previous step directory as installation prefix (PREFIX).

Now it is time to make some missing directories in just created filesystem:

mkdir minimal-1/proc
mkdir minimal-1/dev
mkdir minimal-1/tmp
mkdir minimal-1/etc

and devices for consoles, terminals and virtual hard drive (run following commands as root):

cd minimal-1/dev
mknod console c 5 1
mknod tty0 c 4 0
mknod tty1 c 4 1
mknod tty2 c 4 2
mknod tty3 c 4 3
mknod tty4 c 4 4
mknod tty5 c 4 5
mknod ubda b 98 0

Only 2 things are left: /etc/fstab:

/dev/ubda /boot ext2 defaults 1 2
none /proc proc defaults 0 0

and startup script (called by init) /etc/init.d/rcS:

#!/bin/sh
# mount proc
/bin/mount /proc
# remount root file system in rw mode
/bin/mount -o remount /
echo "Started!"

Thats all! Now you can unmount created file system or run sync several times to make sure that all changes are written to the file and use it as root image for UML:

./linux ubda=minimal-1.ext2

In the next posts I am going to describe my further experiments with UML.

Posted by ksh on September 5, 2006 | 2 comments | linux

Watch

In this post I am going to write about very useful utility called watch and its possible usages. I discovered it several weeks ago, but since then I use it quite often. It’s a pity that I didn’t know about this program all the time that I had been using Linux. This utility executes given program periodically, showing output fullscreen. It can be used to monitor any kind of information about your system.

Below you can find some examples:

  • Monitor wireless connection (bit rate, signal quality and so on):

    watch -n1 -d /sbin/iwconfig eth1

  • Monitor CPU temperature:

    watch cat /proc/acpi/thermal_zone/TZS*/temperature

  • Monitor CPU frequency:

    watch sudo cat /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_cur_freq

  • Monitor disc usage:

    watch df

And of course (as with almost any UNIX utility) you can invent a lot of other ways how to use watch.

Posted by ksh on August 21, 2006 | 1 comment | linux

Short guide to Wi-Fi under Linux

Recently I bought notebook and needed to connect to hotel Wi-Fi network (to install Gentoo linux :) All information that I’ve found didn’t help me to setup wireless connection in less a minute. This guilde explains (in very simple way) how to connect your PC to Wi-Fi network under linux.

You should have following applications installed on your PC:

Follow these 7 simple steps:

  1. Load Wi-Fi driver (Intel 3495 specific):

    modprobe ipw3945
    ipw3945d

  2. Figure out the name of network interface that is bound to Wi-Fi card:

    iwconfig

  3. Find list of available networks:

    iwlist scanning

  4. Connect to one of it:

    iwconfig eth1 essid ESSID


    where eth1 – network interface found at the second step and ESSID – id of wireless network found at the third step
  5. (optional, I haven’t used it) If network is secured you should also specify key:

    (This sets a hex WEP key)
    iwconfig eth0 key 1234123412341234abcd
    (This sets an ASCII key – prefix it with “s:”)
    iwconfig eth0 key s:some-password

  6. Obtain IP address using DHCP:

    dhcpclient eth1

  7. Make sure that everything is ok:

    ifconfig

Probably these steps are too simplistic and will not work in all cases, but they work fine for me and when I was in need for simple instructions I haven’t found such small guide.

Posted by ksh on August 16, 2006 | 1 comment | linux

Logwatch and Gentoo

Today I have upgraded logwatch package on my VPS server to the latest version (7.1).

Most noticeable change in this version comparing to previous (6.0.2) installed on my system – whole new directory structure (see Details on how to create your own filter, create local customizations, etc for more details).

Logwatch is very useful tool if you want to know what your server is doing the whole day. It provides nice summary of log of every service, like list of emerged packages, number of mails sent by your mail server, number of failed authentication attempts through SSH, summary of served by apache files, free disk space, information about possible attacks on your server by using known hacks and a lot more.

Unfortunately default configuration of just installed package is not compliant with default logfiles used by gentoo and some services are missing in result report. logwatch provides easy way to override default configuration in /etc/logwatch/conf/override.conf file. Below is file that I am using on my gentoo server:

logwatch: Detail = High

logfiles/cron: LogFile = messages
logfiles/cron: Archive = messages.*.gz
logfiles/cron: *OnlyService = cron

logfiles/http: LogFile = apache2/*access_log
logfiles/http: Archive = apache2/*access_log.*.gz

logfiles/maillog: LogFile = messages
logfiles/maillog: Archive = messages.*.gz

Posted by ksh on July 22, 2006 | 4 comments | gentoo, linux

Development of Personal Site: Part 3 (Software for server)

If you read my previous posts about development of personal site you probably already guessed that I have installed gentoo linux on my VPS.

Gentoo is my favorite linux distribution over there. I am using it already for 3 years at home, for almost 1 year at work and for 2 months at VPS server :) and not going to change it. Before I have found gentoo I tried RedHat, now I am administrating Debian and RHEL servers at my work, but I’ve never feel enough comfortable with these distributions. I am not sure what are the real reasons for it, probably this is because of lack of knowledge and practical experience with particular distribution or may be I just do not like them and has mental barrier that prevents me to use them efficiently. But anyway I have chosen gentoo and want to describe some details about what software and why I have installed.

Because VPS memory (64Mb RAM + 128Mb swap =198Mb total), CPU and hard drive (3Gb) resources are quite limited at first I doubted that they are enough for source-based linux distribution where you need to compile every single package from sources and also keep a lot of development files (in /usr/include) that are not usually necessary for binary distributions. But it turned out that it is more than enough. Upgrading all packages (including glib and gcc) to the most recent versions and installing all necessary software is a matter of several hours. Additionally I’ve performed some configuration and was able to decrease disk usage. Here are some tips:

  • add nodoc, noman, noinfo to your FEATURES in /etc/make.conf (man make.conf for more details)
  • make sure that you have configured RSYNC_EXCLUDEFROM (Diverting from the Official Tree). You certainly don’t need ebuilds in such categories like x11-base or kde-base on your server and you can safely remove all such ebuilds from your PORTDIR
  • do not allow make to execute several commands simultaneously: MAKEOPTS=”-j1”

While portage tool itself is very convenient it still lacks some helpful functionality. Fortunately there are some tools that fill this gap: gentoolkit and flagedit. I would recommend every gentoo user to install these packages and learn how to use them.

Every site need HTTP server. I have chosen apache, mainly because I want to be able to access my subversion repositories via HTTPS. Another good HTTP server is lighttpd .

Though mail server is not really necessary it is very convenient to have it. I have installed postfix. It is quite simple to configure (it is very good tutorial in gentoo wiki) and has all necessary features that I need out of the box. BTW if you have VPS you can have very cool email address, like yourname@step-inside.org. but I decided that my mailbox at gmail is enough for me and also I don’t want to fight with spam, so postfix is used only for local mail.

Everybody likes statistics. So do I. I have chosen awstats package. I recommend to install Geo-IP package and enable geoip plugin for awstats: you will see what countries your visitors come from. It was necessary to tune apache configuration slightly so awstats can understand its logs: CustomLog logs/access_log combined.

You most probably want to install logrotate , if you don’t want to find out that log files have eaten all your free disk space.

It is very important (and sometimes interesting) to know what your server is doing all those long and boring days and nights when it doesn’t server content of your site. I recommend to use logwatch for this purpose. It will check your log files every day and send summary report to your mail with description what happened. It requires some tuning after installation, particularly I have changed log directory for apache (in /etc/log.d/conf/logfiles/http.conf), and specified that cron and postfix do not use log files and instead rely on syslog service, so logs of these tools should be extracted from /var/log/messages file (in /etc/log.d/conf/services/cron.conf and /etc/log.d/conf/services/postfix.conf). After these changes still some tuning is necessary, but I haven’t figured out what exactly. Probably I will blog about it in future entries.

I was amazed that there were so much breaking attempts: dictionary attacks by SSH happen every day, when I installed apache I immediately started to receive a lot of requests for such URLs like:

/articles/mambo/index2.php?_REQUEST[option ... cho%20YYY;echo|
/blog/xmlrpc.php
/blogs/xmlsrv/xmlrpc.php
/cvs/mambo/index2.php?_REQUEST[option]=com ... cho%20YYY;echo|
/drupal/xmlrpc.php
/index.php?option=com_content&do_pdf=1&id= ... cho%20YYY;echo|
/index2.php?option=com_content&do_pdf=1&id ... cho%20YYY;echo|
/mambo/index2.php?_REQUEST[option]=com_con ... cho%20YYY;echo|
/phpgroupware/xmlrpc.php
/xmlrpc.php

This brings another important issue: security. Gentoo developers pays a lot attention to it. So I have scheduled emerge sync and receive email with warning if my system is affected by any GLSA . Also I have disabled root logins via SSH (Tip: do not forget to add your main user to wheel group before doing it).

Other software packages that I have installed (and you can also find them useful):

Posted by ksh on March 30, 2006 | 0 comments | development, gentoo, linux, web

Calendar

August 2008
MoTuWeThFrSaSu
0000123
45678910
11121314151617
18192021222324
25262728293031

Tags

Archives

RSS feeds