Montag, 4. Januar 2010

PrimaCom Internet verteilen mit Knoppix

Wenn Sie einen PrimaCom-Anschluss besitzen und das hier lesen, werden sie vermutlich bemerkt haben, dass im Windows für die LAN Verbindung keine Internetverbindungsfreigabe möglich ist. Das liegt möglicherweise daran, dass das PrimaCom-Gerät sich einmalig den erstbesten Rechner sucht, und ihm eine dynamische, externe IP zuweist. Über diese wird dann kommuniziert. Es ist eben ein "Cable-Modem", das via Ethernet funktioniert, zum Leidwesen aller Windows-User, die nur eine Netzwerkkarte haben - oder grad keinen Hardware-Router zur Hand. Aber es gibt ja zum Glück noch andere Systeme. Mit Knoppix lässt sich alles ordentlich dahin routen wo es hin soll.

Wir wollen:
  • Beliebig viele PCs online haben
  • Ohne Hardware-Router
  • Mit nur einer Netzwerkkarte pro PC
Was man dafür braucht:
  • Einen Hub oder Switch
  • Einen Rechner auf dem Knoppix dann laufen wird (oder ein anderes Linux)
Letzteres sollte idealerweise das Gerät sein, auf das das Modem standardmäßig anspricht. Sollte dies nicht der Fall sein, könnte eventuell ein Modem-Reset von Nöten sein, was ich allerdings nicht ausprobiert habe.

So sieht die Konfiguration dann aus:
|---------|        ________        _____________
| Knoppix |_______| Switch | _| PrimaCom |
| PC | #-oooo-o-# / | Cable-Modem |
|---------| || \____/ #-------------#
||
|---------| || |---------|
| Anderer |_________||____________| Anderer |
| PC 1 | | PC 2 |
|---------| |---------|
Wenn kein Crosskabel vorhanden ist, kommt das Modem an den Uplink-Port des Switches (die sind meistens extra gekennzeichnet). Wenn der PC mit Knoppix startet, müssten die Netzwerkeinstellungen für's Internet schon korrekt sein.

Unter Knoppix dann folgendes (mit sudo davor, wenn es Probleme mit den Berechtigungen gibt):

  • ifconfig eth0:1 192.168.0.1 netmask 255.255.255.0 up
  • sysctl net.ipv4.ip_forward=1
  • iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Nun gibt es für die anderen Geräte zwei Möglichkeiten:

A) Manuelle Konfiguration
B) Automatische Konfiguration

A geht mit Linux so:

  • ifconfig eth0 192.168.0.2 netmask 255.255.255.0 up
  • route add default gw 192.168.0.1
  • echo "nameserver 8.8.8.8" >> /etc/resolv.conf

Und für Windows:

  • IP-Adresse: 192.168.0.2
  • Subnetzmaske: 255.255.255.0
  • Standardgateway: 192.168.0.1
  • DNS: 8.8.8.8
Natürlich brauch der nächste Rechner dann 192.168.0.3 usw.

Für Möglichkeit B muss ein DHCP Server auf dem Knoppix Rechner eingerichtet werden.

Das Cable-Modem ist ansich nicht schlecht. Vor allem mag ich den dicken, großen Knopf zum An- und Ausschalten. Es bietet zwar einen DHCP Server, aber keine Routing Funktionalität. Warum man nun scheinbar ausschließlich durch einen Reset des Modems den Zielrechner ändern kann... tja. Als langfristige Lösung bietet sich am Besten ein wLan Hardware-Router an.

Mittwoch, 25. November 2009

PXE Odyssey

Booting via network is a nice thing, when it works. I tried to boot my laptop (which didn't recognize my CDRW) with the help of another Windows machine to finally install a Linux distribution from the Internet. At first, the best solution wasn't obvious. You'll need a few server apps which are all nicely integrated into a program which goes by the name tftpd32. Next prerequisites are some files (bootloader, installer...) which will be actually loaded into the target machine. Just follow the instructions of this excellent post.

I had a few problems, though. Unfortunally, PXE error messages aren't very enlightening. At best you'll be able to find out to which server application the error message is referring to. For example I got that one:

PXE-E53: No boot filename received

I don't know why it happened. I guess it simply asked the wrong DHCP server (although I saw that tftpd32 was correctly responding). As soon as I removed my DSL router, I got another error:

PXE-E51: No DHCP or proxyDHCP offers were received

Guess this is another DHCP problem :-). He claims that he didn't receive an offer from tftpd32, and he's a damn liar. tftpd32 told me otherwise. I struggled around for a half an hour and got it finally done. I read something on the net about Full-Duplex problems and so on... well, nonsense. Solution was to go back to basic. I put both machines on a switch, configured the windows network adapter manually just with 192.168.0.1 / 255.255.255.0, adjusted "IP pool starting address" in tftpd32 to 192.168.0.2, made the default router 192.168.0.1 and it worked. Well, DHCP worked, but not TFTP:

PXE-E32: TFTP open timeout

tftpd32 told me this instead:

Rcvd DHCP Discover Msg for IP 0.0.0.0, Mac 00:00:39:59:11:B4 [24/11 22:14:37.161]
DHCP: proposed address 192.168.0.1 [24/11 22:14:37.161]
2868 Request 2 not processed [24/11 22:14:37.239]
Rcvd DHCP Rqst Msg for IP 0.0.0.0, Mac 00:00:39:59:11:B4 [24/11 22:14:38.145]
Previously allocated address 192.168.0.1 acked [24/11 22:14:38.145]
Connection received from 192.168.0.1 on port 2070 [24/11 22:14:38.161]
Read request for file <pxelinux.0>. Mode octet [24/11 22:14:38.161]
OACK: <blksize=1456,> [24/11 22:14:38.161]
Using local port 55153 [24/11 22:14:38.161]
2868 Request 2 not processed [24/11 22:14:38.208]
File <pxelinux.0> : error 10054 in system call recv An existing connection was forcibly closed by the remote host. [24/11 22:14:38.270]

Okay. That is, he tries to read 1456 bytes from pxelinux.0 and closes the connection. Something went wrong at the remote machine. The laptop doesn't remember and simply says "timeout". So I tried lots of things. Shortened the directory names (C:\pxe\...), tried other pxelinux.0 files and so on.

Nothing changed, till I deleted everything except tftpd32.exe/.ini and pxelinux.0 and suddenly the laptop complained about several missing files (e.g. pxelinux.cfg/default). So I added step-by-step the remaining files and it worked. It loaded all files necessary for booting the debian installer. I switched back cables and re-configured network connections (also in the installer) and could complete the installation. Happy end with PXE.

Donnerstag, 27. August 2009

Kontochart erstellen mit Sparkassendaten

Kunden der Sparkasse können sich ihre Kontoauszüge auch im CSV Format herunterladen. Mit Hilfe von GNUplot und dieser Liste aller Kontobewegungen kann man dann natürlich ganz einfach nette Visualisierungen erstellen. Falls man mit Windows gestraft ist, kann man wenigstens noch Cygwin benutzen; das macht die ganze Arbeit wesentlich angenehmer.

Mein Problem war am Anfang, dass die Beträge jeweils die Differenz darstellen und nicht den Saldo zum jeweiligen Zeitpunkt. Wenn man das dann als Chart darstellt kommt natürlich nur Müll heraus. Ich habe ewig versucht das ganze mit GNUplot ausrechnen zu lassen; kam allerdings auf keinen grünen Zweig. Also schrieb ich schnell ein C++ Programm, welches die Daten auf die notwendige Art und Weise umschreibt. Hier ist es (uuenc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A'6"AM/LA)3_[M((N$+F.WQ1JED\I>QUOV1K\\&H9C,@^SNC
M[YN!R=*.0_=BQMDK4+>;90HJV"L0.>"K"E@)TUA=-^G&J=[2FY%J52_@YY,]
M)/[5FM(DKK]</9CN(IH.5S,L<_]?D=?5`^9S8EH51]3H][87V?JG(8QS%/:3
,6PA_`&0Q9^DH"0``
`
end


Also im Prinzip, muss man die Erste (unnötige) Zeile von umsaetze.csv löschen, da GNUplot damit nicht klar kommt. Dann, mein Programm (im selben Ordner) ausführen und schließlich GNUplot starten. Dort gibt man die folgenden Befehle ein:

set xdata time
set xlabel "Datum"
set ylabel "EUR"
set title "Kontochart Sparkasse"
set datafile separator ";"
set timefmt "%d.%m.%Y"
set terminal png size 1024,768
set output "Chart.png"


plot "result.csv" using 1:7 w boxes fs pattern 2


Und so könnte beispielsweise dann das Resultat aussehen (hier etwas verkleinert):



Oder man benutzt:

plot "result.csv" using 1:7 w l

und bekommt:



plot "result.csv" using 1:7 smooth bezier title "bezier" w l, \
     "result.csv" using 1:7 title "line" w lp


ist auch nicht schlecht.


Und weil GNUplot toll ist, geht das ganze auch noch mit candlesticks und financebars.