dimanche 14 décembre 2008

Outgoing emails : how to fake your MTA's idea of the host name?

When your MTA (mail transfer agent, in my case Postfix) is forwarding e-mails to the outside world, you'd better make it aware of your true host name (as seen from the Internet). In my case, like many personal Internet users I don't have my own servers and registered domain name. So I need to make Postfix believe that it's running on an Internet host and it better be the right one. My ISP assigns me a temporary IP address when my router connects. I want to discover the fully qualified domain name (FQDN) for this IP address then assign this host/domain name to the Postfix instances running inside my home network.

How do I know what my real Internet address is ?
Theres at least two ways to do this : from the inside (by looking at your software or router configuration or log files). This is usually the hardest way to get at the information (depending on how much your home network setup is complex). On the other hand, some sites like http://www.ip-adress.com/ will happily display the IP address that it sees connecting to itself. So all you have to do is fire up Firefox and look at that site. Heres an example:



How to resolve the IP address to a host name ?

$ dig -x 85.134.14.152 | grep PTR
;152.14.134.85.in-addr.arpa. IN PTR
152.14.134.85.in-addr.arpa. 28800 IN PTR 55860e98.adsl.multi.fi.


Where to put this host name ?

sudo vi /etc/postfix/main.cf
myhostname = 55860e98.adsl.multi.fi.

How to activate this change?

$ sudo /etc/init.d/postfix restart
* Stopping Postfix Mail Transport Agent postfix [ OK ]
* Starting Postfix Mail Transport Agent postfix Dec 15 01:33:05 kid postfix/master[4792]: terminating on signal 15
[ OK ]
luc@kid:~/tmp$ Dec 15 01:33:06 kid postfix/master[9762]: daemon started -- version 2.5.1, configuration /etc/postfix

dimanche 7 décembre 2008

Configuring an old timer ne2000 ISA PNP card

Ubuntu normally installs the network-manager package. This will usually allow you to configure, stop and start your network connections.
Problem with old ISA cards is they don't provide the same level of self-description and auto-configuration as most modern PCI devices do. For instance these old NE2000 compatible cards used to be configured using hardware jumpers, and required the software driver to know what position is configured on the card in order to be able to talk to it.
In my case I had a PCI card installed but some day it broke and I needed to replace it. I took an old NE2000 ISA card out of the closet, and since this PC still had a mix of ISA and PCI slots I was able to remove the PCI card and install the NE2000. However several problems popped up:

  • Making the kernel recognise the card
  1. Try loading the module manually at the command line in order to see if it recognizes the card. Try "sudo modprobe ne".
  2. If the kernel doesn't find the card you might have to add parameters to this line to force the kernel to use particular IO addresses or IRQ. eg "sudo modprobe ne io=0x280 irq=10"
  • Auto-loading the module at boot
  1. The kernel module that must be loaded (in my case "ne") can be forced to load at boot in two different ways. One way is to hardcode the module load in /etc/module by simply putting its name (ne) on a single line of its own.
  2. Alternatively, you can define it as an alias of "eth0" so that the network start stripts (/etc/init.d/networking) will find it when trying to activate the ethernet interface. You can do that by adding (also to /etc/modules) the line "alias eth0 ne2000". Don't ask why you have to use ne2000 here while the module is called "ne" :-). Make sure to remove the line with the module name '"ne" from /etc/modules if you want to go this way.
  3. If the kernel doesn't find the card when starting the network you might need to add the parameters (just like when you tested using the command line). This also goes in /etc/modules, on a separate line like "options ne io=0x280 irq=10".
  4. Try rebooting.
  • Fixing the firefox "offline mode" issue
In my case network-manager was still not able to see the card at that point (but the networking was running fine). Except that some applications, like firefox, are somewhat getting the information from network-manager that there is allegedly no network card active, and in the case of firefox it goes to offline mode when starting up. This was such a pain that I removed network-manager altogether : "sudo apt-get remove network-manager".

samedi 6 décembre 2008

Disk backup

Installing and configuring backup2l

This covers only basic configuration. In a following post I might want to explain how to set it up for writing your backups on an external disk (NAS/NDAS).

Install backup2l software:

$ sudo apt-get install backup2l
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
liblockfile1
Veuillez utiliser « apt-get autoremove » pour les supprimer.
Paquets suggérés :
cdlabelgen
Les NOUVEAUX paquets suivants seront installés :
backup2l
0 mis à jour, 1 nouvellement installés, 0 à enlever et 0 non mis à jour.
Il est nécessaire de prendre 29,8ko dans les archives.
Après cette opération, 143ko d'espace disque supplémentaires seront utilisés.
Réception de : 1 http://be.archive.ubuntu.com hardy/universe backup2l 1.4 [29,8kB]
29,8ko réceptionnés en 0s (97,9ko/s)
Sélection du paquet backup2l précédemment désélectionné.
(Lecture de la base de données... 144923 fichiers et répertoires déjà installés.)
Dépaquetage de backup2l (à $ sudo apt-get install backup2l
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
liblockfile1
Veuillez utiliser « apt-get autoremove » pour les supprimer.
Paquets suggérés :
cdlabelgen
Les NOUVEAUX paquets suivants seront installés :
backup2l
0 mis à jour, 1 nouvellement installés, 0 à enlever et 0 non mis à jour.
Il est nécessaire de prendre 29,8ko dans les archives.
Après cette opération, 143ko d'espace disque supplémentaires seront utilisés.
Réception de : 1 http://be.archive.ubuntu.com hardy/universe backup2l 1.4 [29,8kB]
29,8ko réceptionnés en 0s (97,9ko/s)
Sélection du paquet backup2l précédemment désélectionné.
(Lecture de la base de données... 144923 fichiers et répertoires déjà installés.)
Dépaquetage de backup2l (à partir de .../archives/backup2l_1.4_all.deb) ...
Paramétrage de backup2l (1.4) ...partir de .../archives/backup2l_1.4_all.deb) ...
Paramétrage de backup2l (1.4) ...

Configure the software

Backup2l is a niece piece of software. All configuration is located in /etc/backup2l.conf and few changes are required to make it work:

  • Source directories to be backed up. In my case I did not want /var/mail or /usr/local to be backed up so I removed that from the configuration:
< srclist="(/etc"

> SRCLIST=(/etc /root /home )
  • Files and Directories to skip. I don't want to backup music or video files, or firefox caches, or different kinds of "Thrash" cans:
< skipcond="(-path"

> SKIPCOND=( -path '*/.cpan/*' -o -path '*/lost+found/*' -o -path '*/CPAN/*' -o -path '*/.thumbnails/*' -o -path '*/.Trash/*' -o -path '*/Trash/*' -o -path '*/Cache/*' -o -path '*/.cache/*' -o -name '*.mp3' -o -name '*.wmw' -o -name '*.mov' -o -name '*.avi' -o -name '*.MP3' -o -name '*.WMW' -o -name '*.MOV' -o -name '*.AVI' )
  • Where to put the backups. In this case we'll use a file system (/var/backup) defined in /etc/fstab with the "noauto" option. This means that the file system is not mounted at boot but reserved for backup2l usage. The backups will be located in a subdirectory hereunder:
< #BACKUP_DEV="/disk2"
---
> BACKUP_DEV="/var/backup"

< backup_dir="/disk2/backup"
> BACKUP_DIR="/var/backup"
  • Pre- and Post- backup commands. Mounting the backup file system is not necessary, backup2l will do that before running the pre-backup commands. You might want (like I did) to uncomment the action that keeps a list of your selected (installed) packages before running the backup. This can be used to reinstall the system if you lose the entire system disk. Remember, /root is being backed up so you'll have this list available after you restore your backup on a new system:
<
> #echo " pre-backup: nothing to do"
90,91c91,92
< #echo " writing dpkg selections to /root/dpkg-selections.log..."
< #dpkg --get-selections | diff - /root/dpkg-selections.log
> /dev/null || dpkg --get-selections > /root/dpkg-selections.log
---
> echo " writing dpkg selections to /root/dpkg-selections.log..."
> dpkg --get-selections | diff - /root/dpkg-selections.log > /dev/null || dpkg --get-selections > /root/dpkg-selections.log
  • Final steps. You should enable the following to allow the software to run automatically from your daily crontab:
< autorun="0"

> AUTORUN=1

< unconfigured="1"

> #UNCONFIGURED=1
  • Lots of space but slow CPU? You might want to enable the following to produce backups in plain TAR format (instead of compressed tar.gz):
< # CREATE_DRIVER="DRIVER_MY_AFIOZ"

> CREATE_DRIVER="DRIVER_TAR"

Enabling outgoing internet email on a dialup/adsl host

You don't have a real internet host with a full connection and a registered domain name, do you ? If you do then you can skip this post, as it discusses something more basic for home usage.

$ sudo vi /etc/postfix/main.cf
> add this at the end:
smtp_generic_maps = hash:/etc/postfix/generic

$ sudo vi /etc/postfix/generic:
> add your mapping between local and "real" email addresses:
luce@off.mymail tuxic@aol.com
root@off.mymail tixuc@blogspot.com

$ sudo postmap /etc/postfix/generic

To check the results:
$ tail -f /var/log/mail.info
Dec 6 19:14:49 off postfix/pickup[8501]: 76CA8D7A6B: uid=1000 from=
Dec 6 19:14:49 off postfix/cleanup[8589]: 76CA8D7A6B: message-id=<20081206181449.76ca8d7a6b@off.home>
Dec 6 19:14:49 off postfix/qmgr[8503]: 76CA8D7A6B: from=<luce@off.home>, size=28995, nrcpt=1 (queue active)
Dec 6 19:14:51 off postfix/smtp[8591]: 76CA8D7A6B: to=<tuxic@aol.com>, relay=smtp.micromou.com[1.7.7.2]:25, delay=1.9, delays=0.04/0.02/0.57/1.3, dsn=2.0.0, status=sent (250 2.0.0 mB6IEnRH030552 Message accepted for delivery)
Dec 6 19:14:51 off postfix/qmgr[8503]: 76CA8D7A6B: removed

SMTP MTA setup

Setting up a simple SMTP server

This is based around Postfix on Ubuntu linux.

Install: sudo apt-get install postfix

Config: during apt-get install you'll get a configuration dialog.
  1. enter your local host name and a dummy mail domain (this assumes that you don't own a proper domain name). For instance, myhost.mymail.
  2. To allow outgoing email; enter the SMTP host for your internet provider (e.g. smtp.myprovider.com). This is not going to allow incoming emails to flow in (for this you'll need fetchmail or a full SMTP setup which goes beyond this post)
To allow shell utilities like mailx to send internet emails, a further step is required.