Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Weiterleitung über IP-Tables
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
jew.de
Apprentice
Apprentice


Joined: 25 Sep 2002
Posts: 226
Location: Frankfurt/Main

PostPosted: Thu Oct 31, 2002 9:00 am    Post subject: Weiterleitung über IP-Tables Reply with quote

Hallo,

habe gestern, nachdem ich durch meinen Mozilla fix und fertich war, ein kleines Netz, bestehend aus 3 Rechnern, aufgebaut.

1. Rechner (Router) hängt mit einem Bein am DSL-Anschluss und mit dem anderen am Hub
2. Rechner (Desktop) hängt ebenfalls am Hub (wer hätte es gedacht?), und holt fleißig meine Mails ab. Ebenfalls läuft squirrelmail auf der Kiste, und stellte mir bisher meine Mails über's Netz zur Verfügung (Arbeit).

Wie kann ich meinem Router nun beibringen, dass wenn ich mich auf Port 3333 auf ihn connecte, dass er mich innerhalb meines Netzen an den Rechner mit der IP 192.168.1.251 auf Port 80 weiterleitet? Ich will keine zusäzlichen Dienste auf dem Router laufen lassen, ich bin ja schon froh, dass er überhaupt läuft, und das war schon ein riesen Akt ;-)

Ich blocke normalerweise jede Verbindung, die nicht von innen aktiviert wurde, oder zu einer bestehenden Verbindung gehört.

Hier meine firewall_set, die beim booten ausgeführt wird, und soweit auch brav ihre Dienste bringt:


Code:
#! /bin/sh

##############################################################################

# Konstanten
EXT_DEV="ppp0"
INT_IP="192.168.1.1"

##############################################################################

# Chains flushen
iptables -F
iptables -F -t nat

# IP forwarding aktivieren
echo "1" > /proc/sys/net/ipv4/ip_forward

# Default policies setzen
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

##############################################################################

# INPUT chain

# Verbindungen nur akzeptieren, wenn sie zu einer bestehenden gehoeren...
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# ...oder von innen kommen
iptables -A INPUT -m state --state NEW -i ! $EXT_DEV -j ACCEPT

# Einige Aussnahmen:
#SSH
iptables -A INPUT -m state --state NEW -p tcp --dport 22 -j ACCEPT
#SMTP
iptables -A INPUT -m state --state NEW -p tcp --dport 25 -j ACCEPT
#HTTP/SSL
iptables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
#IMAP/SSL
iptables -A INPUT -m state --state NEW -p tcp --dport 993 -j ACCEPT
#OPENVPN
iptables -A INPUT -m state --state NEW -p udp --dport 5000 -j ACCEPT

# TUN/TAP FUER OPENVPN
iptables -A INPUT -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A INPUT -i tap+ -j ACCEPT
iptables -A FORWARD -i tap+ -j ACCEPT

##############################################################################

# FORWARD chain

# Verbindungen nur akzeptieren, wenn sie zu einer bestehenden gehoeren...
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
# ...oder von innen kommen
iptables -A FORWARD -m state --state NEW -i ! $EXT_DEV -j ACCEPT

##############################################################################

# NAT und Masquerading

# NAT auf externem Device
iptables -A POSTROUTING -t nat -o $EXT_DEV -j MASQUERADE

# Source NAT auf interne IP
iptables -A POSTROUTING -t nat -o $EXT_DEV -j SNAT --to $INT_IP

##############################################################################

# Ports fuer Server in FORWARD chain oeffnen

# Port fuer Webserver auf 192.168.64.
#iptables -A FORWARD -m state --state NEW -d 192.168.1.251 -p tcp --dport 3333 -j ACCEPT

##############################################################################

# Port forwarding

# Port 3333 --> 192.168.64.2:80
#iptables -A PREROUTING -t nat -p tcp --dport 80 -j DNAT --to 192.168.1.251:80

##############################################################################

# DROP an INPUT und FORWARD chains anhaengen

iptables -A INPUT -j DROP
iptables -A FORWARD -j DROP



Das Script wurde von einem Freund geschrieben, und ich habe es so übernommen. Leider habe ich nicht wirklich DIE Ahnung von iptables...
Warscheinlich ist es eh nur eine oder zwei Zeilen, die mann ändern muss, oder :roll:

Danke,
Tobi
Back to top
View user's profile Send private message
de4d
Apprentice
Apprentice


Joined: 12 Sep 2002
Posts: 181
Location: fr. i. br. (ger)

PostPosted: Thu Oct 31, 2002 10:06 am    Post subject: Reply with quote

wenn du connections von 'aussen' meinst
soweit ich mich erinnere:
Code:

iptables -A INPUT -p tcp --dport 3333 -j ACCEPT
iptables -A PREROUTING -t nat -i ppp0 -p tcp --dport 3333 --to <ip>:80


damit das auch von 'innen' funktioniert fuer die andere richtung noch ein extra rule einbauen. habs das mangels sinn nie ausprobiert. vielleicht weiss das aber jemand anders.

[edit: koennte jetzt stimmen]
_________________
void main(){fork();main();}


Last edited by de4d on Thu Oct 31, 2002 10:08 am; edited 1 time in total
Back to top
View user's profile Send private message
A.Stranger
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2002
Posts: 148
Location: Dortmund

PostPosted: Thu Oct 31, 2002 10:06 am    Post subject: Reply with quote

Hi,

Du änderst einfach diesen Passus:
Quote:

# Port forwarding
# Port 3333 --> 192.168.64.2:80
#iptables -A PREROUTING -t nat -p tcp --dport 80 -j DNAT --to 192.168.1.251:80
##############################################################################

nach:
Quote:

# Port forwarding
# Port 3333 --> 192.168.64.2:80
iptables -A PREROUTING -t nat -p tcp --dport 3333 -j DNAT --to 192.168.1.251:80
##############################################################################


Zudem muss Du noch unter dem Forwarding eine Regel einfügen, die diesen Trasfer überhaupt erlaubt. z.B.
Quote:

iptables -A FORWARD -p tcp --sport 1024: -d 192.168.1.251 --dport 80 -j ACCEPT

_________________
Bis denn...
A.Stranger
_________________________
System: findet Ihr hier
Back to top
View user's profile Send private message
jew.de
Apprentice
Apprentice


Joined: 25 Sep 2002
Posts: 226
Location: Frankfurt/Main

PostPosted: Thu Oct 31, 2002 10:20 am    Post subject: Reply with quote

Hallo,

ich habe das mal so ausprobiert, und muss sagen: Ich verstehe da einiges nicht!
Wenn ich jetzt auf die IP meines Routers gehe, dann werde ich automatisch durchgereicht. Wenn ich stattdessen auf die IP:3333 gehe, gibt es einen Timeout....

Ich habe die Lösung von A.Stranger ausprobier.
Ich glaube, ich müsste mal wieder mit einem schönen Buch in die Ecke setzen und iptables Regeln lernen.....

Danke,

Tobi
Back to top
View user's profile Send private message
A.Stranger
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2002
Posts: 148
Location: Dortmund

PostPosted: Thu Oct 31, 2002 10:24 am    Post subject: Reply with quote

Hi,

mhh, hast Du in der NAT-Regel auch wirklich denn Port 3333 geschrieben. Da stand vorher Port 80. Wenn Du dass nicht korekt geändert hast, würde das erklären, warum im Moment nur mit der IP durchkommst, da die normale Webseite ja darauf vermutet wird.
_________________
Bis denn...
A.Stranger
_________________________
System: findet Ihr hier
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