PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Portweiterleitung mit iptables



imox
30.07.13, 08:49
Hallo,

Ich möchte den localhost mysql Port 3306 auf eine andere IP im Netzwerk dauerhaft weiterleiten. Ich denke das geht nur mit iptables oder? Und kann mir jemand sagen welche regeln ich dafür erstellen muss?

Vielen Dank

Imox

muell200
30.07.13, 09:52
willkommen auf dem board


Ich denke das geht nur mit iptables oder?

stichwort: PREROUTING, Forward

imox
30.07.13, 09:59
habe ich auch schon gesehen aber wie genau müssen die regeln aussehen? Die Beispiele die ich finde sind immer mit nat daher gehe ich davon aus das die bestimmt sind über WAN zu gehen. Das brauche ich ja aber nicht weil ich im Netzwerk bleibe.

imox
30.07.13, 19:33
Also ich bekomms nicht hin.

ich habe das hier ausprobiert aber kann die regeln nicht mal eintragen:

iptables -t nat -A PREROUTING --dst $EXTERNAL_IP -p tcp --dport 3306 -j DNAT --to-destination 192.168.178.12:3306
iptables -t nat -A POSTROUTING --dst 192.168.178.12 -p tcp --dport 3306 -j SNAT --to-source $EXTERNAL_IP
iptables -t nat -A OUTPUT --dst $EXTERNAL_IP -p tcp --dport 3306 -j DNAT --to-destination 192.168.178.12:3306

kann mir jemand bitte helfen?

nopes
30.07.13, 21:07
Hi,

also gemäß diversen Anleitungen, nehmen wir diese (http://www.debuntu.org/how-to-redirecting-network-traffic-to-a-new-ip-using-iptables/), sind diese Ding nötig:
The first thing to do is do enable IP forwarding...
Then, we will add a rule telling to forward the traffic on port 1111 to ip 2.2.2.2 on port 1111...
and finally, we ask IPtables to masquerade...
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -p tcp –dport 1111 -j DNAT –to-destination 2.2.2.2:1111
iptables -t nat -A POSTROUTING -j MASQUERADE
Du siehst den Unterschied?

imox
30.07.13, 22:53
iptables -I FORWARD -p tcp -d 192.168.178.11 --dport 3306 -j ACCEPT
iptables -t nat -A PREROUTING -i lo -p tcp --dport 3306 -j DNAT --to-destination 192.168.78.11:3306
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

das funktioniert nicht. was nun?

marce
31.07.13, 07:49
"es geht nicht" ist keine Fehlermeldung.

Abgesehen davon - wie versuchst Du denn, auf den "lokalen" MySQL zuzugreifen?

imox
31.07.13, 15:37
hab es jetzt mit xinit.d gelöst


service mysql3306
{
type = UNLISTED
flags = REUSE
socket_type = stream
protocol = tcp
user = root
wait = no
instances = UNLIMITED
port = 3306
redirect = 192.168.178.12 3306
disable = no
}

zugriff auf den mysql server ganz normal -> mysql -h 127.0.0.1 -u USER -p