2. IP - sehe den Wald vor lauter Bäumen nicht

legolas

Renowned Member
Dec 16, 2010
42
2
73
Servus,

alles was mit eth0 zu tun hat funktioniert einwandfrei. Nun möchte ich allen eingehenden Traffic für die IP 152.53.175.70 auf eth0:0 umleiten. Kann mir jemand sagen was ich falsch mache? Danke



Code:
auto lo
iface lo inet loopback



auto eth0
iface eth0 inet static
address 152.55.89.136/22
gateway 152.55.89.1
        
# zusätzliche IP



post-up ip addr add 152.53.175.70/32 dev eth0 label eth0:0
pre-down ip addr del 152.53.175.70/32 dev eth0



auto vmbr0
iface vmbr0 inet static
address 10.10.10.1/24
bridge-ports none
bridge-stp off
bridge-fd 0



post-up echo 1 > /proc/sys/net/ipv4/ip_forward



post-up iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o eth0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o eth0 -j MASQUERADE
post-up iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 10.10.10.100:80
post-down iptables -t nat -D PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 10.10.10.100:80
post-up iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j DNAT --to-destination 10.10.10.100:443
post-down iptables -t nat -D PREROUTING -i eth0 -p tcp --dport 443 -j DNAT --to-destination 10.10.10.100:443
post-up iptables -A FORWARD -p tcp -d 10.10.10.100 --dport 80 -j ACCEPT
post-down iptables -D FORWARD -p tcp -d 10.10.10.100 --dport 80 -j ACCEPT
post-up iptables -A FORWARD -p tcp -d 10.10.10.100 --dport 443 -j ACCEPT
post-down iptables -D FORWARD -p tcp -d 10.10.10.100 --dport 443 -j ACCEPT



post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1
post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1



# zusätzliche IP alles auf 10.10.10.110 umleiten



iptables -t nat -A PREROUTING -d 152.53.175.70 -j DNAT --to-destination 10.10.10.110
iptables -t nat -A POSTROUTING -d 10.10.10.110 -j MASQUERADE
 
eth0:0 kein echtes separates Interface ist, sondern nur ein Alias für eine zusätzliche IP auf eth0. Dein aktuelles Setup fügt die IP zwar korrekt hinzu, leitet aber keinen eingehenden Traffic automatisch zu einer VM oder einem anderen Ziel weiter.

Wenn du den gesamten Traffic für 152.53.175.70 z. B. an 10.10.10.2 weiterleiten möchtest, brauchst du DNAT:

iptables -t nat -A PREROUTING -d 152.53.175.70 -i eth0 -j DNAT --to-destination 10.10.10.2
iptables -A FORWARD -d 10.10.10.2 -j ACCEPT
iptables -A FORWARD -s 10.10.10.2 -j ACCEPT

Für ausgehenden Traffic der VM sollte dann ebenfalls die zusätzliche öffentliche IP verwendet werden:

iptables -t nat -A POSTROUTING -s 10.10.10.2 -o eth0 -j SNAT --to-source 152.53.175.70
Wichtig ist außerdem, dass 152.53.175.70 vom Provider tatsächlich auf deinen Server bzw. auf die MAC-Adresse von eth0 geroutet wird. Falls die IP providerseitig nicht zu deinem Server geroutet ist, können die iptables-Regeln das Problem nicht lösen.

Deine bestehende MASQUERADE-Regel für das komplette 10.10.10.0/24 solltest du außerdem prüfen, da sie mit der spezifischen SNAT-Regel kollidieren kann. Die spezifische SNAT-Regel sollte vor der allgemeinen MASQUERADE-Regel stehen.