Schnell und kurz – für OpenBSD bis Version 3.8
Voraussetzungen
Eine ADSL Verbindung ;o), einen PC mit zwei Netzwerkkarten, einen zweiten PC (ohne dem braucht man ja nicht wirklich einen Router) und Basiswissen wie man OpenBSD installiert, die diversen Dateien editiert, Packete extrahiert und wie man über „ports“ installiert.
Installation von PPTP
Als erstes muss man PPTP (ab OpenBSD 3.9 gibt es Probleme) installieren. Am einfachsten geht das über ports (/usr/ports/net/pptp). Falls ports noch nicht installiert ist, einfach runterladen und in z.B. unter /usr entpacken. Um nun PPTP zu installieren einfach in den Ordner wechseln und make install eintippen. Somit werden auch alle „Abhänigkeiten“ heruntergeladen und installiert. Mit pkg_info kann man nachschauen welche Packete installiert sind.
Einen neuen Kernel bauen
Um PPTP mit OpenBSD nutzen zu können, muss man sich einen neuen Kernel bauen. Dies hört sich schlimm an, ist aber einfacher als man glaubt. Als erstes braucht man die Source – dazu die tars src.tar.gz und sys.tar.gz herunterladen und z.B. in den Ordner /usr/newkernel entpacken. Dann wie folgt vorgehen:
# cd /usr/newkernel/sys/conf # cp GENERIC ADSLkernel # vi ADSLkernel > hier nach "gre" suchen und auskommentieren # cd /usr/newkernel/sys/arch/i386/conf # cp GENERIC ADSLkernel # vi ADSLkernel > hier die Zeile "include ../../../conf/GENERIC" auf "include ../../../conf/ADSLkernel" ändern. # cp ADSLkernel /ADSLkernel # cd /ADSLkernel # config -s /usr/newkernel/sys -b . ADSLkernel > überprüft ob die Konfiguration in Ordnung ist # make clean && make depend && make # cd / # cp bsd bsd.old > macht eine Sicherungskopie # cp /ADSLkernel/bsd . > überschreibt den alten Kernel # reboot
PPTP Konfigurieren
Nun ohne „gre“-Support muss noch die Datei /etc/ppp/options wie folgt geändert werden. LOGINNAME und PASSWORT wie vom ISP zugesandt ändern!
# /etc/ppp/options name "LOGINNAME" noauth noipdefault defaultroute debug
Danach die pap-secrets Datei.
# /etc/ppp/pap-secrets LOGINNAME 10.0.0.138 PASSWORT
Um nun eine Internetverbindung aufzumachen einfach /usr/local/bin/pptp 10.0.0.138 & in die Shell schreiben. Um die Verbindung zu trennen einfach den Prozess per ps -ax finden und kill -9 PID .
NAT und PF einrichten
Mein Netzwerk sieht ca. so aus:
ADSL-------Router-------Hub-------PC1
|
---------PC2
IP Router: 192.168.1.250/24
IP PC1: 192.168.1.100/24
IP PC2: 192.168.1.110/24
In diesem Beispiel heißt PC1 in meiner Konfigurationsdatei clemens. Zuerst muss man net.inet.ip.forwarding in /etc/sysctl.conf aktivieren. Für die pf.conf kann man meine Datei verwenden, jedoch weise ich darauf hin, dass ich keine Verantwortung dafür übernehmen kann. Falls jemand Fehler findet – bitte melden.
pf.conf
# our defines
ext_if="ppp0"
int_if="vr0"
if_to_ext_if="vr1"
domain_if="xl0"
internal_net="192.168.1.0/24"
domain_net="www.xxx.yyy.zzz/29"
table { 127.0.0.1/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, !$internal_net, !$domain_net, 255.255.255.255/32 }
# make stats for the ADSL-connection
set loginterface $ext_if
# close inactive connections faster - less memory is needed
set optimization aggressive
# clean fragmented packets
scrub on $ext_if all fragment reassemble random-id
# force packets to conform to specifications. You can miss off the
# no-df if you don't intend to use IPSec.
scrub in all no-df
scrub out all no-df
# enable forwarding
nat on $ext_if from $internal_net to any -> $ext_if
nat on $ext_if from $domain_net to any -> $ext_if
# ... in the filtering section of pf.conf ...
# predefined workstations and servers
clemens = "192.168.1.100"
dns2 = "aaa.bbb.ccc.ddd"
# ports that should be able to reach from outside
ssh_ports = "{ 2222 }"
im_ports = "{ 1863 5190 5222 }"
bittorrent_ports = "{ 6969, 6881:6999 }"
service_ports = "{ 21 80 }"
dns_port = "{ 53 }"
mail_ports = "{ 25 110 143 }"
# bittorrent stuff
rdr on $ext_if proto tcp from !$internal_net to any port 6969 -> $clemens port 6969
rdr on $ext_if proto tcp from !$internal_net to any port 6881:6999 -> $clemens port 6881:6999
# we don't want IPv6
block quick inet6
# don't allow IP spoofing
block in log quick on $ext_if inet from to any
block in log quick on $ext_if inet from any to
# allow to ping this server
pass in quick on $ext_if inet proto icmp all icmp-type 8 code 0 keep state
# filter rules for $ext_if inbound
block in on $ext_if all
pass in on $ext_if inet proto tcp from any to $dns2 port $mail_ports flags S/SA keep state
pass in on $ext_if inet proto tcp from any to $clemens port $bittorrent_ports flags S/SAFR keep state
pass in on $ext_if inet proto tcp from any to any port $service_ports flags S/SA keep state
pass in on $ext_if inet proto tcp from any to any port $ssh_ports flags S/SA keep state
pass in on $ext_if inet proto { udp tcp } from any to any port $dns_port flags S/SA keep state
pass in on $ext_if from $domain_net to any
# filter rules for $ext_if outbound
block out on $ext_if all
pass out on $ext_if inet proto tcp from $ext_if to any flags S/SA keep state
pass out on $ext_if inet proto { udp icmp } from $ext_if to any keep state
pass out on $ext_if inet proto { tcp udp } from $ext_if to any port domain keep state
pass out on $ext_if inet proto tcp from $ext_if to any port $ssh_ports flags S/SA keep state
pass out on $ext_if inet proto tcp from $ext_if to any port $im_ports flags S/SA keep state
pass out on $ext_if from $clemens to any
# filter rules for $int_if inbound
block in on $int_if all
pass in on $int_if from $internal_net
# filter rules for $int_if outbound
block out on $int_if all
pass out on $int_if from any to $internal_net
# filter rules for $domain_if inbound
block in on $domain_if all
pass in on $domain_if from $domain_net
# filter rules for $domain_if outbound
block out on $domain_if all
pass out on $domain_if from any to $domain_net
Nachdem die Firewall konfiguriert ist, einfach per Befehl /usr/sbin/pfctl -e Fall -f /etc/pf.conf starten.
Autostart
Um automatisch die PPTP-Verbindung aufrecht zu erhalten, braucht man ein Reconnect-Script, z.B.:
reconnect.sh
while true ; do
# Test if connection is really ok
/sbin/ping -c 1 www.google.at >/dev/null
if [ $? != 0 ]
then
echo "#############################################"
echo "#connection is not ok - trying once again...#"
echo "#############################################"
# Here I am using the IP-address from my ISP's gateway
/sbin/ping -c 1 213.229.45.253 >/dev/null
if [ $? != 0 ]
then
echo "######################################"
echo "#connection is dead - reconnecting...#"
echo "######################################"
# define log file
LOG=/var/log/adsl
echo "#########################################"
echo "#starting connection, or reconnecting...#"
echo "#########################################"
/usr/bin/pkill -9 /usr/local/sbin/pptp
/usr/local/sbin/pptp 10.0.0.138 &
sleep 30
echo " "
echo "####################################"
echo "#starting or restarting firewall...#"
echo "####################################"
/sbin/pfctl -d
/sbin/pfctl -e -Fall -f /etc/pf.conf
/bin/date >> $LOG
echo "### connection lost and restartet ###" >> $LOG
fi
fi
sleep 60 # wait one minute and then check again
done
Ich weiß es ist nicht das Beste. Falls jemand ein besseres hat, bitte ich ihn/sie es mir zu schicken damit ich es hier veröffentlichen kann. Wenn das Reconnect-Script fertig ist einfach rc.local in /etc editieren. Meine sah ca. so wie hier aus:
rc.local
# $OpenBSD: rc.local,v 1.34 2004/03/17 01:33:50 deraadt Exp $
# site-specific startup actions, daemons, and other things which
# can be done AFTER your system goes into securemode. For actions
# which should be done BEFORE your system has gone into securemode
# please see /etc/rc.securelevel
# site-specific startup actions, daemons which can be run
# Add your local changes additions to this file
echo -n 'starting local daemons:'
# run ntpdate prior to ntpd
if [ $securelevel -le 1 -a X"${ntpdate_flags}" != X"NO" \
-a -x /usr/local/sbin/ntpdate ]; then
echo -n ' ntpdate'
/usr/local/sbin/ntpdate -b ${ntpdate_flags} >/dev/null
fi
if [ X"${ntpd}" == X"YES" -a -x /usr/local/sbin/ntpd \
-a -e /etc/ntp.conf ]; then
ntpd_flags="-p /var/run/ntpd.pid"
if [ $securelevel -ge 1 ]; then
ntpd_flags="${ntpdflags} -x"
fi
echo -n ' ntpd'; /usr/local/sbin/ntpd ${ntpd_flags}
fi
if [ -x /usr/local/sbin/cfsd ]; then
if ps auxc | grep -q '^ *root .* mountd$'; then
echo -n ' cfsd'; /usr/local/sbin/cfsd >/dev/null 2>&1
mount -o port=3049,nfsv2,intr localhost:/null /crypt
else
echo -n ' cfsd (failed, no mountd running)'
fi
fi
#if [ -x /usr/local/sbin/snmpd ]; then
# echo -n ' snmpd'; /usr/local/sbin/snmpd
#fi
echo '.'
# Netatalk stuff
#if [ -f /etc/netatalk/rc.atalk ]; then
# . /etc/netatalk/rc.atalk
#fi
# start caching nameserver
if [ -x /usr/local/sbin/dnsmasq ]; then
echo "starting caching nameservice"
/usr/local/sbin/dnsmasq -i vr0 -z
fi
# start ADSL connection
if [ -x /usr/local/sbin/pptp ]; then
echo "starting ADSL connection"
/usr/local/sbin/pptp 10.0.0.138 &
fi
sleep 10
# start pf
if [ -e /etc/pf.conf ]; then
if [ -x /sbin/pfctl ]; then
echo "loading pf rules and starting pf-daemon"
/sbin/pfctl -e -Fall -f /etc/pf.conf
fi
fi
# start reconnection script
if [ -x /etc/reconnect.sh ]; then
echo "starting ADSL reconnection script"
/etc/reconnect.sh &
fi
Kommentare