Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
iptables, nat & vnc Fernsteuerung
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
Gucky_der_Mausbiber
Guru
Guru


Joined: 10 Apr 2005
Posts: 359
Location: Wetzlar, Hessen

PostPosted: Mon Mar 02, 2009 1:25 pm    Post subject: iptables, nat & vnc Fernsteuerung Reply with quote

Moinsen,
also ich habe da ein Problem mit VNC, iptables und NAT. Aber fangen wir mal bei der Ausgangssituation an.

Ich habe in unserer Firma ein kleines Netzwerk, bestehend aus einem gentoo 64 Bit Server (hardened profil & sources) der als SambaPDC läuft und 6 x Windows XP Clients.
Auf dem gentoo Server läuft natürlich noch iptables, gleichzeitig fungiert der Server auch als DSL-Router für das Netzwerk.

Mein Plan war jetzt folgender. Ich habe auf allen WinXP-Clients den VNC-Server im "Service"-Mode installiert (Service-Mode deshalb, damit ich die Clients auch fernsteuern kann, wenn niemand eingeloggt ist). Desweiteren habe ich natürlich dem vnc-server auf allen Clients unterschiedliche Ports zugeordnet. Die Einstellungen des VNC-Servers kann man auch nochmal auf den folgenden 7 Screenshots sehen:
1. http://www.kraus-automaten.de/vnc/vnc1.jpg
2. http://www.kraus-automaten.de/vnc/vnc2.jpg
3. http://www.kraus-automaten.de/vnc/vnc3.jpg
4. http://www.kraus-automaten.de/vnc/vnc4.jpg
5. http://www.kraus-automaten.de/vnc/vnc5.jpg
6. http://www.kraus-automaten.de/vnc/vnc6.jpg
7. http://www.kraus-automaten.de/vnc/vnc7.jpg

Danach habe ich das ganze erstmal lokal, aus dem Netzwerk heraus, getestet und wunderbar, alles lief, ich könnte per vnc-viewer jeden VNC-Server erreichen und mich erfolgreich verbinden.

Damit das ganze aber eben auch "remote" von zuhause aus geht habe ich dann noch entsprechende Iptables-Regeln hinzugefügt. Siehe hier :
Code:
    # VNC pc-agenda
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27461 -j DNAT --to-destination 192.168.16.5:27461
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27461 -j LOG --log-level warn --log-prefix "ipt VNC:"

    # VNC pc-kraft
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27465 -j DNAT --to-destination 192.168.16.105:27465
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27465 -j LOG --log-level warn --log-prefix "ipt VNC:"

    # VNC pc-cramer
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27469 -j DNAT --to-destination 192.168.16.110:27469
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27469 -j LOG --log-level warn --log-prefix "ipt VNC:"

    # VNC pc-hauss
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27467 -j DNAT --to-destination 192.168.16.115:27467
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27467 -j LOG --log-level warn --log-prefix "ipt VNC:"

    # VNC pc-boehm
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 5900 -j DNAT --to-destination 192.168.16.125:5900
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 5900-j LOG --log-level warn --log-prefix "ipt VNC:"

Doch leider klappt das damit nicht. :(
Ich habe jetzt echt schon stunden im Internet gesucht, auch habe ich verschiedene "Tips" gefunden, aber keiner hat funktioniert. Sowie ich mich über das Internet mit den vnc-servern verbinden will sagt mit der viewer "connection refused" und das war es dann auch schon. Aus dem lokalen Netz geht alles wunderbar.

Hiernochmal meine "kompletten" iptables-Regeln:
Code:
#!/bin/bash
# ---------------------------------------------------------------------
# Linux-iptables-Firewallskript, Copyright (c) 2009 under the GPL
# Autogenerated by iptables Generator v1.22 (c) 2002-2009 by Harald Bertram 
# Please visit http://harry.homelinux.org for new versions of
# the iptables Generator (c).
#
# This Script was generated by request from:
# boehm@kraus-automaten.de on: 2009-1-19 0:22.2 MET.
#
# If you have questions about the iptables Generator or about
# your Firewall-Skript feel free to take a look at out website or
# send me an E-Mail to webmaster@harry.homelinux.org.
#
# My special thanks are going to Lutz Heinrich (trinitywork at hotmail dot com)
# who made lots of Beta-Testing and gave me lots of well qualified
# Feedback that made me able to improve the iptables Generator.
# --------------------------------------------------------------------
#
### BEGIN INIT INFO
# Provides: IP-Paketfilter
# Required-Start: $network $local_fs
# Required-Stop: $local_fs
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Short-Description: Harry's IP-Paketfilter
# Description: Harry's IP-Paketfilter provides reasonable
#      IP-Security for Home-Computers and small networks
### END INIT INFO
#

case "$1" in
  start)
    echo "Starte IP-Paketfilter"

    # iptables-Modul
    # modprobe ip_tables
    # Connection-Tracking-Module
    # modprobe ip_conntrack
    # Das Modul ip_conntrack_irc ist erst bei Kerneln >= 2.4.19 verfuegbar
    # modprobe ip_conntrack_irc
    # modprobe ip_conntrack_ftp

    # Tabelle flushen
    iptables -F
    iptables -t nat -F
    iptables -t mangle -F
    iptables -X
    iptables -t nat -X
    iptables -t mangle -X

    # Default-Policies setzen
    iptables -P INPUT DROP
    iptables -P OUTPUT DROP
    iptables -P FORWARD DROP

    # MY_REJECT-Chain
    iptables -N MY_REJECT

    # MY_REJECT fuellen
    iptables -A MY_REJECT -p tcp -j REJECT --reject-with tcp-reset
    iptables -A MY_REJECT -p udp -j REJECT --reject-with icmp-port-unreachable
    iptables -A MY_REJECT -p icmp -j DROP
    iptables -A MY_REJECT -j REJECT --reject-with icmp-proto-unreachable

    # MY_DROP-Chain
    iptables -N MY_DROP
    iptables -A MY_DROP -j DROP

    # Korrupte Pakete zurueckweisen
    iptables -A INPUT -m state --state INVALID -j DROP
    iptables -A OUTPUT -m state --state INVALID -j DROP
    iptables -A FORWARD -m state --state INVALID -j DROP

    # Stealth Scans etc. DROPpen
    # Keine Flags gesetzt
    iptables -A INPUT -p tcp --tcp-flags ALL NONE -j MY_DROP
    iptables -A FORWARD -p tcp --tcp-flags ALL NONE -j MY_DROP

    # SYN und FIN gesetzt
    iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j MY_DROP
    iptables -A FORWARD -p tcp --tcp-flags SYN,FIN SYN,FIN -j MY_DROP

    # SYN und RST gleichzeitig gesetzt
    iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j MY_DROP
    iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN,RST -j MY_DROP

    # FIN und RST gleichzeitig gesetzt
    iptables -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j MY_DROP
    iptables -A FORWARD -p tcp --tcp-flags FIN,RST FIN,RST -j MY_DROP

    # FIN ohne ACK
    iptables -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j MY_DROP
    iptables -A FORWARD -p tcp --tcp-flags ACK,FIN FIN -j MY_DROP

    # PSH ohne ACK
    iptables -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j MY_DROP
    iptables -A FORWARD -p tcp --tcp-flags ACK,PSH PSH -j MY_DROP

    # URG ohne ACK
    iptables -A INPUT -p tcp --tcp-flags ACK,URG URG -j MY_DROP
    iptables -A FORWARD -p tcp --tcp-flags ACK,URG URG -j MY_DROP

    # Loopback-Netzwerk-Kommunikation zulassen
    iptables -A INPUT -i lo -j ACCEPT
    iptables -A OUTPUT -o lo -j ACCEPT

    # Maximum Segment Size (MSS) für das Forwarding an PMTU anpassen
    iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

    # Connection-Tracking aktivieren
    iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
    iptables -A FORWARD -i ! ppp0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
    iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
    iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

    # Squid
    iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128

    # VNC pc-agenda
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27461 -j DNAT --to-destination 192.168.16.5:27461
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27461 -j LOG --log-level warn --log-prefix "ipt VNC:"

    # VNC pc-kraft
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27465 -j DNAT --to-destination 192.168.16.105:27465
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27465 -j LOG --log-level warn --log-prefix "ipt VNC:"

    # VNC pc-cramer
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27469 -j DNAT --to-destination 192.168.16.110:27469
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27469 -j LOG --log-level warn --log-prefix "ipt VNC:"

    # VNC pc-hauss
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27467 -j DNAT --to-destination 192.168.16.115:27467
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 27467 -j LOG --log-level warn --log-prefix "ipt VNC:"

    # VNC pc-boehm
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 5900 -j DNAT --to-destination 192.168.16.125:5900
    iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --dport 5900-j LOG --log-level warn --log-prefix "ipt VNC:"

    # ICMP Echo-Request (ping) zulassen und beantworten
    iptables -A INPUT -m state --state NEW -p icmp --icmp-type echo-request -j ACCEPT

    # LAN-Zugriff auf eth0
    iptables -A INPUT -m state --state NEW -i eth0 -j ACCEPT

    # Default-Policies mit REJECT
    iptables -A INPUT -j MY_REJECT
    iptables -A OUTPUT -j MY_REJECT
    iptables -A FORWARD -j MY_REJECT

    # Forwarding/Routing
    echo "Aktiviere IP-Routing"
    echo 1 > /proc/sys/net/ipv4/ip_forward 2> /dev/null

    # Masquerading
    iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

    # SYN-Cookies
    # echo 1 > /proc/sys/net/ipv4/tcp_syncookies 2> /dev/null

    # Stop Source-Routing
    for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/accept_source_route 2> /dev/null; done

    # Stop Redirecting
    for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/accept_redirects 2> /dev/null; done

    # Reverse-Path-Filter
    for i in /proc/sys/net/ipv4/conf/*; do echo 2 > $i/rp_filter 2> /dev/null; done

    # Log Martians
    for i in /proc/sys/net/ipv4/conf/*; do echo 1 > $i/log_martians 2> /dev/null; done

    # BOOTP-Relaying ausschalten
    for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/bootp_relay 2> /dev/null; done

    # Proxy-ARP ausschalten
    for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/proxy_arp 2> /dev/null; done

    # Ungültige ICMP-Antworten ignorieren
    echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses 2> /dev/null

    # ICMP Echo-Broadcasts ignorieren
    echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts 2> /dev/null

    # Max. 500/Sekunde (5/Jiffie) senden
    echo 5 > /proc/sys/net/ipv4/icmp_ratelimit

    # Speicherallozierung und -timing für IP-De/-Fragmentierung
    echo 262144 > /proc/sys/net/ipv4/ipfrag_high_thresh
    echo 196608 > /proc/sys/net/ipv4/ipfrag_low_thresh
    echo 30 > /proc/sys/net/ipv4/ipfrag_time

    # TCP-FIN-Timeout zum Schutz vor DoS-Attacken setzen
    echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout

    # Maximal 3 Antworten auf ein TCP-SYN
    echo 3 > /proc/sys/net/ipv4/tcp_retries1

    # TCP-Pakete maximal 15x wiederholen
    echo 15 > /proc/sys/net/ipv4/tcp_retries2

    ;;

  stop)
    echo "Stoppe IP-Paketfilter"
    # Tabelle flushen
    iptables -F
    iptables -t nat -F
    iptables -t mangle -F
    iptables -X
    iptables -t nat -X
    iptables -t mangle -X
    echo "Deaktiviere IP-Routing"
    echo 0 > /proc/sys/net/ipv4/ip_forward

    # Default-Policies setzen
    iptables -P INPUT ACCEPT
    iptables -P OUTPUT ACCEPT
    iptables -P FORWARD ACCEPT
    ;;

  status)
    echo "Tabelle filter"
    iptables -L -vn
    echo "Tabelle nat"
    iptables -t nat -L -vn
    echo "Tabelle mangle"
    iptables -t mangle -L -vn
    ;;

  *)
    echo "Fehlerhafter Aufruf"
    echo "Syntax: $0 {start|stop|status}"
    exit 1
    ;;

esac


Ich habe diese Frage auch schonmal im linuxforen gepostet, doch leider konnte mir da niemand helfen. Deswegen hoffe ich jetzt inständig das ihr mir sagen könnt was ich falsch mache, bzw. wie ich meine iptables-Regeln derart ändern kann, damit es geht.
Vielen Dank schonmal im Vorraus



PS: Die WinXP Firewall ist es nicht, die habe ich zu Testzwecken ausgeschaltet.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum