Hallo zusammen,
ich möchte gerne eine Lastverteilung über iptables erzielen. Allerdings verstehe ich nicht ganz warum es bei mir so nicht funktioniert. Über VMware habe ich versucht die Lastverteilung zu simulieren und manchmal scheint der ping zu funktionieren aber in 80% der Fälle nicht. An den privaten IPs kann es wohl kaum liegen. Kann mir bitte jemand weiterhelfen?
Konfiguration:
Vielen Dank schonmal.
Gruß HltmaN
ich möchte gerne eine Lastverteilung über iptables erzielen. Allerdings verstehe ich nicht ganz warum es bei mir so nicht funktioniert. Über VMware habe ich versucht die Lastverteilung zu simulieren und manchmal scheint der ping zu funktionieren aber in 80% der Fälle nicht. An den privaten IPs kann es wohl kaum liegen. Kann mir bitte jemand weiterhelfen?
Code:
Daten:
ISP 1:
IP: 172.16.1.2
NET: 172.16.1.0/24
ISP 2:
IP: 172.16.0.2
NET: 172.16.0.0/24
Local:
eth0
NET: 192.168.3.0
über eth1 wird ISP1 erreicht
eth1 IP: 172.16.1.1
über eth2 wird ISP2 erreicht
eth2 IP: 172.16.0.1
Zunächst habe ich in /etc/iproute2/rt_tables die 2 Tabellen angelegt:
250 ISP1
249 ISP2
Konfiguration:
Code:
#!/bin/bash
# delete all
sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
# standard rules
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
# NAT
sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
sudo iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE
# chain which marks a packet (MARK) and its connection (CONNMARK) with mark 1 (for ISP1)
iptables -t mangle -N MARK-ISP1
iptables -t mangle -A MARK-ISP1 -j MARK --set-mark 1
iptables -t mangle -A MARK-ISP1 -j CONNMARK --save-mark
# chain which marks a packet (MARK) and its connection (CONNMARK) with mark 2
iptables -t mangle -N MARK-ISP2
iptables -t mangle -A MARK-ISP2 -j MARK --set-mark 2
iptables -t mangle -A MARK-ISP2 -j CONNMARK --save-mark
# If the packet is not NEW, there must be a connection for it, so get the connection
# mark and apply it to the packet
# packets from dev network
iptables -t mangle -A PREROUTING -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j CONNMARK --restore-mark
# on the other hand, it the state is NEW, we have to decide where to send it
# Use the statistics match in nth mode
# dev network
iptables -t mangle -A PREROUTING -i eth0 -m conntrack --ctstate NEW -m statistic --mode nth --every 2 --packet 0 -j MARK-ISP1
iptables -t mangle -A PREROUTING -i eth0 -m conntrack --ctstate NEW -m statistic --mode nth --every 2 --packet 1 -j MARK-ISP2
# add local routes too
ip route flush table ISP1
ip route add table ISP1 default dev eth1 via 172.16.1.2
ip route add table ISP1 172.16.1.0/24 dev eth1 src 172.16.1.1
ip route add table ISP1 172.16.0.0/24 dev eth2 src 172.16.0.1
ip route add table ISP1 192.168.3.0/24 dev eth0 src 192.168.3.1
ip route flush table ISP2
ip route add table ISP2 default dev eth2 via 172.16.0.2
ip route add table ISP2 172.16.1.0/24 dev eth1 src 172.16.1.1
ip route add table ISP2 172.16.0.0/24 dev eth2 src 172.16.0.1
ip route add table ISP2 192.168.3.0/24 dev eth0 src 192.168.3.1
ip rule del from all fwmark 2 2>/dev/null
ip rule del from all fwmark 1 2>/dev/null
ip rule add fwmark 1 table ISP1
ip rule add fwmark 2 table ISP2
ip route flush cache
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do echo 0 > "$i"; done
echo 1 > /proc/sys/net/ipv4/ip_forward
Vielen Dank schonmal.
Gruß HltmaN