Gateway Installation: Unterschied zwischen den Versionen
(→ON Webstat (Gateway Status): header footer uprecords leeren) |
Mdbw (Diskussion | Beiträge) (→NTP-Server: ntpdrehash auf extra Seite) |
||
Zeile 258: | Zeile 258: | ||
chmod go+rx /etc/ntp | chmod go+rx /etc/ntp | ||
ln -sf ntpkey_MD5key* keys | ln -sf ntpkey_MD5key* keys | ||
− | In /etc/ntp.conf sind dann folgende Einträge erforderlich: | + | |
+ | * In /etc/ntp.conf sind dann folgende Einträge erforderlich: | ||
+ | |||
keys /etc/ntp/keys | keys /etc/ntp/keys | ||
keysdir /etc/ntp/ | keysdir /etc/ntp/ | ||
Zeile 264: | Zeile 266: | ||
requestkey 10 | requestkey 10 | ||
restrict 127.0.0.1 | restrict 127.0.0.1 | ||
− | + | ||
− | + | * Das Script [[Gateway_Installation/ntpdrehash]] als /usr/local/bin/ntpdrehash ablegen: | |
− | + | ||
− | + | * Und schliesslich /etc/ppp/ip-up.d/70ntpdrehash anlegen: | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | Und schliesslich /etc/ppp/ip-up.d/70ntpdrehash anlegen: | + | |
#!/bin/sh | #!/bin/sh | ||
/usr/local/bin/ntpdrehash | ntpdc & | /usr/local/bin/ntpdrehash | ntpdc & |
Version vom 16. April 2006, 15:07 Uhr
Kurzer Leitfaden für das Aufsetzen neuer Vereinsgateways.
Inhaltsverzeichnis |
Hardware
- sinnvoll >500 Mhz CPU, >256 MB RAM
- mindestens 2 NICs
- ausreichend HD-Kapazität; ideal SCSI (z.B. U2W), alternativ IDE (mit z.B. RAID1)
Basisinstallation
- Booten, z.B. per CD oder PXE mit Knoppix
- Dateisystem vorbereiten:
- cfdisk /dev/<device>, z.B. /dev/hda (IDE) oder /dev/sda (SCSI)
- primäre Partitionen: 32 MB boot (Typ 83 + bootable), 500 MB swap (Typ 82), Rest für / (Typ 83)
- boot mit EXT2: mkfs.ext2 /dev/<device>1
- swap mit SWAP: mkswap /dev/<device>2
- root mit XFS: mkfs.xfs /dev/<device>3
- Debian (bevorzugt Testing) installieren
- a) Neuinstallation, vgl. Debian GNU/Linux-Installationsanleitung
- c) per debootstap von Knoppix aus, vgl. Debian GNU/Linux-Installationsanleitung - C.4
- b) als Kopie von vorhandenem GW, z.B. izumi
- Filesysteme auf izumi ggf. mounten, crontab Einträge ggf. deaktivieren (CPU-Last)
- boot einbinden: mount /dev/<device>1 /mnt/
- boot spiegeln: rsync -axz --numeric-ids root@izumi.on:/boot/ /mnt/
- root einbinden: umount /mnt; mount /dev/<device>3 /mnt/
- root spiegeln: rsync -axz --numeric-ids root@izumi.on:/ /mnt/
- Minimale Device-Nodes anlegen (bei UDEV): MAKEDEV null console zero
- Bootloader installieren (grub):
- via chroot und grub-Skripte: (chroot...); grub-install --no-floppy /dev/<device>; update-grub
- oder manuell, dabei /boot/grub/menu.lst selbst anpassen/erstellen: grub --no-floppy (root (hd0,0) / setup (hd0) / quit)
- Kernel bauen / aktualisieren
- cd /usr/src/linux; make menuconfig; make; make install; make modules_install; update-grub
- ggf. local-version neu setzen
Hilfsmittel: chroot Umgebung
mount /dev/<device>3 /mnt mount /dev/<device>1 /mnt/boot mount -t proc proc /mnt/proc mount --bind /dev /mnt/dev chroot /mnt
Hilfsmittel: RAID mit mdadm
- spezieller Partitionstyp FD (Linux raid autodetect), mit cfdisk einstellen
- direkt: mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/hda3 /dev/hdc3
- oder auch schrittweise:
- mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/hda3 missing
- Daten in /hda3 einspielen
- mdadm --manage /dev/md0 --add /dev/hdc3
Konfiguration
Allgemeines
- Hostname /etc/hostname + /etc/mailname
- Zeitzone /etc/timezone -> UTC
- Kernelmodule /etc/modules
- Dateisysteme /etc/fstab
/dev/<device>1 /boot ext2 noauto,noatime 1 1 /dev/<device>3 / xfs noatime 0 0 /dev/<device>2 none swap sw 0 0 /dev/cdrom /mnt/cdrom iso9660 noauto,ro 0 0 none /proc proc defaults 0 0 none /dev/shm tmpfs defaults 0 0
Netzwerk-Geräte
PPP bzw. DynIP
- Ethernet /etc/network/interfaces
auto lo iface lo inet loopback auto eth0 iface eth0 inet manual auto eth1 iface eth1 inet static address 192.168.0.X netmask 255.255.0.0 network 192.168.0.0 broadcast 192.168.255.255 auto <peername> iface <peername> inet ppp provider <peername>
- PPP /etc/ppp/*
- /etc/ppp/pap-secrets -> "<account>" * "<password>"
- /etc/ppp/peers/<peername>, Defaults mit:
logfile /var/log/pppd/qsc-dsl.log #defaultroute hide-password lcp-echo-interval 20 lcp-echo-failure 3 connect /bin/true noauth persist mtu 1492 noaccomp default-asyncmap plugin rp-pppoe.so eth0 user "<account>"
- ln -s /etc/ppp/peers/<peername> /etc/ppp/peers/provider
- mkdir /var/log/pppd
- /etc/ppp/ip-up.d
#!/bin/sh # default routes route add -net 0.0.0.0/1 gw $PPP_REMOTE route add -net 128.0.0.0/1 gw $PPP_REMOTE # uni rostock route add -net 139.30.0.0/16 gw $PPP_REMOTE # ipkg repositories route add -host 195.56.146.238 gw $PPP_REMOTE route add -host 212.91.225.42 gw $PPP_REMOTE # wikipedia route add -net 207.142.131.192/26 gw $PPP_REMOTE route add -net 145.97.39.128/28 gw $PPP_REMOTE route add -net 212.85.150.128/28 gw $PPP_REMOTE # www.opennet-initiative.de route add -host 212.105.204.29 gw $PPP_REMOTE # rostock.de route add -net 195.37.188.160/28 gw $PPP_REMOTE
- /etc/ppp/ip-down.d/00routes - analog nur s/add/del
Statische IP
- Externe und Intern IP in /etc/network/interfaces konfigurieren. Dabei eth0=extern und eth1=intern
- /etc/network/if-up.d/gatewaysetup ist ein Synlink auf /etc/init.d/gatewaysetup. Dieses Script setzt die Netfilter Regeln
- Das Script /etc/network/if-up.d/routes setzte die Routen die olsr per HNA raus gibt.
- Diese sollten wir Zentral verwalten so das die GW's sich die Route automatisch ziehen.
- Das Script /etc/network/if-up.d/openvpn starten OVPN
Routing
- OLSR /etc/olsrd.conf, Defaults mit:
UseHysteresis no LinkQualityLevel 2 Interface "eth1" { <defaults> } Hna4 { # university rostock 139.30.0.0 255.255.0.0 # ipkg repositories 195.56.146.238 255.255.255.255 212.91.225.42 255.255.255.255 # wikipedia 207.142.131.192 255.255.255.192 145.97.39.128 255.255.255.240 212.85.150.128 255.255.255.240 # www.opennet-initiative.de 212.105.204.29 255.255.255.255 # www.rostock.de 195.37.188.160 255.255.255.240 }
- WAN-Routing /etc/network/ip-up.d/gatewaysetup.sh (Kopie besorgen)
SSH-Server
- ggf. neue Schlüssel erstellen in /etc/ssh/
- RSA-Host-Key per ssh-keygen -b 2048 -t rsa -f ssh_host_rsa_key
- DSA-Host-Key per ssh-keygen -b 2048 -t dsa -f ssh_host_dsa_key
- Einige änderungen in /etc/ssh/sshd_config
PermitRootLogin without-password #RSAAuthentication yes #PasswordAuthentication no
VPN-Server
- OpenVPN:
- openvpn + openssl installieren
- zwei Instanzen aufbauen: <system> = opennet_gateways (VPN Backbone) | opennet_users (VPN Internet-Zugang für Nutzer)
- /etc/openvpn/<system>/openssl.conf anpassen (Kopie besorgen), Leserechte setzen (chmod go-rwx <system>)
- /etc/openvpn/opennet_<system>.conf anpassen (Kopie besorgen), key + cert anpassen
- Csr/Key erstellen: openssl req -days 3650 -nodes -new -keyout <hostname>.key -out <hostname>.csr -extensions server -config openssl.cnf (Common Name = <hostname>.on)
- Csr absenden und unterschreiben lassen, Crt einspielen, Leserechte setzen (chmod go-rw *.key)
- Diffie hellman PEM: openssl dhparam -out /etc/openvpn/dh2048.pem 2048
- automatische ACL Aktualisierung:
- Nutzer openvpn-acl anlegen + absichern
- SSH Schlüsselpaar erzeugen: su openvpn-acl; cd .ssh/; ssh-keygen -t rsa
- SSH Public Key (id_rsa.pub) in opennetca@ratte:.ssh/authorized_keys hinzufügen
- cronttab für openvpn-acl mit "*/10 * * * * rsync -rt --delete --safe-links opennetca@139.30.3.52:'opennet_users opennet_users_disabled' /etc/openvpn/acl"
Nameserver
- Erforderliche Pakete installieren: bind9
- falls noch kein rndc-Key - rndc absichern per rndc-conf -a
- /etc/bind/named.conf.options:
options { directory "/var/cache/bind"; forward first; forwarders { <isp-dns1>; <isp-dns2>; 192.168.0.254; }; auth-nxdomain no; # conform to RFC1035 listen-on { 127.0.0.1; <gateway-ip> }; # ignoriert unterstrich in Domainnamen vom ON check-names slave ignore; };
- /etc/bind/named.conf.local:
// on - forward (includes vpn) zone "on." { type slave; file "db.on"; masters {192.168.0.254;}; }; //on - reverse zone "168.192.in-addr.arpa" { type slave; file "db.192.168"; masters {192.168.0.254;}; }; //on-vpn - reverse zone "1.10.in-addr.arpa" { type slave; file "db.10.1"; masters {192.168.0.254;}; };
- lokale Namensauflösung /etc/resolv.conf:
search on nameserver 127.0.0.1
- Überschreiben der Namensauflösung durch ppp-Einwahl unterbinden - /etc/ppp/peers/provider:
#usepeerdns
- Nameserver starten: /etc/init.d/bind9 start
- Funktion prüfen: ps aux|grep bind und rndc status
- Fehlermeldungen suchen: grep named /var/log/daemon.log|tail -20
- Zonen-Transfer manuell durchführen: rndc retransfer on
Webserver
- apache2 installieren
- in /etc/apache2/ports.conf eintragen: Listen 80
- Default-Site deaktivieren: #RedirectMatch ^/$ /apache2-default/
- Default-Site unter /var/www/apache2-default ggf. löschen
- CGI-BIN deaktivieren: /etc/apache2/mods-enabled/cgi.load löschen; ggf. in sites-enabled/ den cgi-bin Eintrag löschen
- OpenVPN-Status-Skript anpassen unter /root/tasks/openvpn-users-status.py: host = '<hostname>.on'
NTP-Server
- ntpdate und ntpd installieren
- beide beim Systemstart starten lassen (zur Sicherheit zuerst ntpdate, dann ntpd)
- ntpd hat Probleme mit dynamisch wechselnen IP Adressen. Im Daemon Log finden sich Einträge wie ntpd[2466]: sendto(83.67.66.148): Invalid argument. Ich würde hier vorschlagen ntpdate in crontab einzutragen.
- ntpdate als cronjob hat wirklich unschöne Resultate. Ich bin dafür den ntpd ohne restart davon zu überzeugen, die neue global ip zu nutzen. Zur Nutzung des management-sockets sind zunächst keys zu erstellen:
sudo su mkdir -p /etc/ntp chmod go-rx /etc/ntp cd /etc/ntp ntp-keygen chmod go-rxw * chmod go+rx /etc/ntp ln -sf ntpkey_MD5key* keys
- In /etc/ntp.conf sind dann folgende Einträge erforderlich:
keys /etc/ntp/keys keysdir /etc/ntp/ trustedkey 10 requestkey 10 restrict 127.0.0.1
- Das Script Gateway_Installation/ntpdrehash als /usr/local/bin/ntpdrehash ablegen:
- Und schliesslich /etc/ppp/ip-up.d/70ntpdrehash anlegen:
#!/bin/sh /usr/local/bin/ntpdrehash | ntpdc &
MTA (Mail Transfer)
Es ist sinnvoll einen MTA zu konfigurieren damit Statusmeldungen per Mail an unser administratives Postfach noc@opennet-initiative.de geschickt werden können. Wir benutzen dazu einen gemeinsamen Relayhost mit SMTP Auth unter postfix auf jedem Gateway.
Benötigte Pakete: postfix libsasl2-modules postfix-tls (bei der Debian installation Satellite system auswählen)
Konfiguriert wird Postfix über /etc/postfix/main.cf.
# hostname/domain definition myhostname = <host>.opennet-initiative.de # myorigin wird an lokal generierte mails angehaengt myorigin = $myhostname # Aliase für lokale User alias_maps = hash:/etc/aliases # Postfix ist nur fuer localhost zuständig mynetworks = 127.0.0.0/8 # alle Mails sollen über unseren Relayhost gesendet werden # (mit Dynamischen IP's und ohne PTR-Record sollte man lieber keine Mails versenden) relayhost = relayhost.opennet-initiative.de # Zum authentifizieren beim Relayhost benötigen wir SMTP Auth # ''/etc/postfix/sasl_passwd'' hat folgendes Format # hostname user:pass smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd smtp_sasl_security_options =
Die Datei /etc/postfix/sasl/passwd anlegen und aktuellen Inhalt besorgen.
Zudem ist noch eine kleine Änderung an /etc/postfix/master.cf notwendig. Damit legen wir fest das Postfix nur am lo-Interface lauscht:
sed -i -e "s/\(^smtp.*smtpd.*$\)/127.0.0.1:\1/" master.cf
Damit Nachrichten an den Nutzer root generell weitergeleitet werden, in die /etc/aliases den Eintrag root: noc@opennet-initiative.de setzen.
Häufig benötigte Kommandos:
- Konfiguraion neuladen: postfix reload
- Default Konfiguration ausgeben: postconf -d
- Nach Änderungen an /etc/aliases: postalias /etc/aliases
- Warteschlange prüfen: postqueue -p oder mailq
- Warteschlange manipolieren siehe man postsuper
- Versandlogging erfolgt über mail.* nach: /var/log/mail.log
- Fehler werden nach /var/log/syslog geschrieben
- Versand prüfen: echo "testmail" > mailx -s testmail <user> (z.B. <user>=root)
Datenbank
Wir benutzen entweder PostgreSql oder MySql.
Postgre-Tunning:
- /etc/postgresql-common/autovacuum.conf : avac_sleep_base=3000
Opennet Tools
Erläuterungen sie auch Gateway_Installation/Opennet Tools Übersicht.
Teucrium (Traffic Graphen)
siehe Gateway_Installation/Teucrium Setup
Traffic Shaping
siehe Gateway_Installation/Traffic Shaping
ON Webstat (Gateway Status)
- Nuter on-webstat anlegen: useradd -m on-webstat
- /etc/sudoers ergänzen, via visudo bearbeiten: on-webstat ALL = NOPASSWD: /usr/sbin/rndc status
- aktuelles Webstat-Archiv nach /home/on-webstat übernehmen (z.B. svn checkout svn://svn.opennet-initiative.de/on_webstat/trunk/; mv trunk/* .; rm -rf trunk)
- Verzeichniss /var/www/on_webstat anlegen, Gruppe/Owner auf on-webstat
- crontab für Nutzer on-webstat einrichten
- Abhängigkeiten:
- Apache Server Status aktivieren, /etc/apache2/apache2.conf:
<Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 192.168.0.0/255.255.0.0 Allow from 127.0.0.1 </Location>
- vnstat installieren: apt-get install vnstat; vnstat -u -i eth0
- uptimed installieren via apt-get install uptimed und /etc/uptimed.conf mit:
UPDATE_INTERVAL=60 LOG_MAXIMUM_ENTRIES=50 LOG_MINIMUM_UPTIMED=1h MAIL_MINIMUM_UPTIME=1d MAIL_MINIMUM_POSITION=10 EMAIL=root@localhost SEND_EMAIL=1 SENDMAIL=/usr/lib/sendmail -t PIDFILE=/var/run/uptimed MILESTONE=1d:one day [..]
- uprecords-cgi installien:
- apt-get install uprecords-cgi (table, 10 max)
- Header und Footer Dateien in /etc/uprecords-cgi/ leeren
- Apache absichern in /etc/apache2/sites-enabled/000-default cgi-bin Pfad raus
- Leserechte für conf-Datei: chmod +r /etc/uprecords-cgi/uprecords.conf
- Leserechte für VPN-Status: chmod +r /var/log/openvpn/*status*
Trac (Projektmanagement)
siehe Gateway Installation/Trac Install
Experimentell
tinc
- Tinc installieren: apt-get install tinc; cd /etc/tinc/; mkdir on_backbone; mkdir on_backbone/hosts
- Netz zum Starten hinzufügen: "on_backbone" nach /etc/tinc/nets.boot eintragen
- Config-File tinc.conf unter /etc/tinc/on_backbone/:
Name=<gw-alias> Device=/dev/net/tun BindToAddress=<gw-external-ipaddr> ConnectTo=<remote-alias>
- Host-Files als <alias> unter /etc/tinc/on_backbone/hosts/:
Address=<fqhn> Subnet=<net>/<mask>
- ggf. neues Keypaar erzeugen: tincd -n on_backbone -K
- ggf. Host-Files mit ihren Public-Keys ergänzen
- netfilter Regeln erweitern (z.B. in ON-gatewaysetup.sh):
- TCP: iptables -A external_in -i <external-if> -p tcp --dport 655 -j RETURN
- UDP: iptables -A external_in -i <external-if> -p udp --dport 655 -j RETURN
- Starten: /etc/init.d/tinc start
- Logfile prüfen: grep tinc /var/log/daemon.log
TODO's
- Netfilter
- Wie funktioniert die ACL synchronisation?