working base

This commit is contained in:
Michal Humpula
2025-03-16 10:20:48 +01:00
parent 0ddf5f1c36
commit 5fbd72b370
19 changed files with 3261 additions and 0 deletions

53
scripts/setup-router.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/bin/sh
set -e
ROUTER_TYPE="$1"
echo "Setting up $ROUTER_TYPE router..."
# fix dns
echo "nameserver 192.168.10.1" > /etc/resolv.conf
apk add --no-cache iputils iptables
# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
sysctl -w net.ipv4.ip_forward=1
if [ "$ROUTER_TYPE" = "primary" ]; then
echo "Configuring PRIMARY router (192.168.200.11 192.168.202.11 172.17.0.2)"
ip addr show
echo "Routes:"
ip route show
# NAT for traffic from primary network to target network
iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -d 192.168.202.0/24 -j MASQUERADE
iptables -P FORWARD ACCEPT
elif [ "$ROUTER_TYPE" = "secondary" ]; then
echo "Configuring SECONDARY router (192.168.201.11 ↔ 192.168.202.12 ↔ 172.17.0.3)"
ip addr show
echo "Routes:"
ip route show
# NAT for traffic from secondary network to target network
iptables -t nat -A POSTROUTING -s 192.168.201.0/24 -d 192.168.202.0/24 -j MASQUERADE
iptables -P FORWARD ACCEPT
else
echo "Error: Invalid router type. Use 'primary' or 'secondary'"
exit 1
fi
echo "Secondary router setup complete"
echo "NAT rules:"
iptables -t nat -L POSTROUTING -n -v
# Keep container running
echo "Router is running. Monitoring interfaces..."
while true; do
echo "$(date): Router $ROUTER_TYPE status - interfaces up"
sleep 60
done