working base
This commit is contained in:
53
scripts/setup-router.sh
Executable file
53
scripts/setup-router.sh
Executable 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
|
||||
Reference in New Issue
Block a user