Encargado: Andrés Ambrois (aa) andresambrois@gmail.com
Secuaz: Francisco Castro (fcr) fcr@adinet.com.uy
Bruno Iglesias (bjifas) bjifas@gmail.com
#!/bin/sh IFACES="ppp0 ppp1" ip rule flush hops= for iface in $IFACES do addr=`ifconfig $iface | grep -o 'inet addr:[^ ]*' | sed 's/.*:\(.*\)/\1/'` nm=`ifconfig $iface | grep -o 'Mask:[^ ]*' | sed 's/.*:\(.*\)/\1/'` gw=`ip route show dev $iface | head -n 1 | cut -d' ' -f1` table=$((${iface#ppp} + 1)) ip route flush dev $iface ip route flush table $table ip route add $gw dev $iface src $addr table $table ip route add default via $gw dev $iface table $table ip route add $gw dev $iface src $addr ip rule add from $addr table $table hops="$hops nexthop via $gw dev $iface weight 1" done ip route del default ip route add default scope global $hops
auto eth0
iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
broadcast 192.168.1.255
auto eth2
iface eth2 inet static
address 192.168.0.1
netmask 255.255.255.0
broadcast 192.168.0.255
auto eth1
iface eth1 inet manual
auto dsl-provider
iface dsl-provider inet ppp
pre-up /sbin/ifconfig eth1 up # line maintained by pppoeconf
provider dsl-provider
#!/bin/sh SQUIDIP=192.168.0.1 SQUIDPORT=3128 LAN_INSTALL=192.168.1.0/24 LAN_GENERAL=192.168.0.0/24 WAN_IFACES="ppp0 ppp1" # Limpieza iptables -F iptables -t nat -F iptables -X iptables -P INPUT DROP # Aceptar lo iptables -A INPUT -i lo -j ACCEPT # Aceptar conexiones establecidas y nuevas desde la lan iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT for iface in $WAN_IFACES do iptables -A INPUT -m state --state NEW -i $iface -j DROP done iptables -A INPUT -m state --state NEW -j ACCEPT iptables -t nat -A PREROUTING -d $SQUIDIP -j ACCEPT iptables -t nat -A PREROUTING -s $SQUIDIP -p tcp --dport 80 -j ACCEPT iptables -t nat -A PREROUTING -s $LAN_INSTALL -p tcp --dport 80 -j REDIRECT --to-ports $SQUIDPORT iptables -t nat -A PREROUTING -s $LAN_GENERAL -p tcp --dport 80 -j REDIRECT --to-ports $SQUIDPORT for iface in $WAN_IFACES do iptables -t nat -A POSTROUTING -o $iface -j MASQUERADE done
[13:18:24] root@flisol:~# sed '/^\(#\|$\)/d' /etc/dhcp3/dhcpd.conf
ddns-update-style none;
default-lease-time 600;
max-lease-time 3600; # 1h
authoritative;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option domain-name-servers 192.168.1.1;
range 192.168.1.20 192.168.1.254;
}
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.0.255;
option domain-name-servers 192.168.0.1;
range 192.168.0.20 192.168.0.254;
}
El servidor responderá al nombre local “flisol” en la IP 192.168.0.1 para las peticiones entrantes desde la subred General, y 192.168.1.1 para la subred de instalaciones.
#!/bin/sh IFACE=eth2 REDGRAL=192.168.0 RATETOTAL=4mbit # En Intel tenemos 100 ticks por segundo. La máxima tasa se da cuando # se envían $burst bytes en cada tick. Para lograr $RATETOTAL (en bytes), # necesitamos un burst de $RATETOTAL/(100*8). Ver man tc-htb. # No hace falta, tenemos NO_HZ=y en el server. Lo dejo como referencia. # MINBURST=`dc -e "${RATETOTAL%mbit} 1048576 * 100 8 * / p"` RATEGRALCLI=100kbit # lsmod | grep -q '^sch_htb ' || insmod sch_htb # lsmod | grep -q '^cls_u32 ' || insmod cls_u32 # Bueno, borramos los qdiscs y todos sus amigos: tc qdisc del dev $IFACE root # Agregamos el qdisc ra'iz en donde marcamos la clase por omisi'on para # los paquetes que salen (1:1): tc qdisc add dev $IFACE root \ handle 1: \ htb default 1 ################################ Clases ################################ # # Clase ra'iz: 1:1 # .---------^---------. # | | # Clases hijas: (general) 1:2 1:3 (instalaciones) # .--^--. .---^--. # .0.2 | |.0.254 .1.2| |.1.254 # Clases recontrahijas: 1:3 .. 1:255 1:256 1:508 # #Clase = IP +: +1 +254 # # Creamos la clase ra'iz ilimitada, ya que es un fast ethernet: tc class add dev $IFACE parent 1: \ classid 1:1 \ htb rate 1000mbit burst $MINBURST # Burst debe ser mayor o igual # a la más alta de sus hijos # Creamos la clase hija para General: tc class add dev $IFACE parent 1:1 \ classid 1:2 \ htb rate $RATETOTAL prio 10 burst $MINBURST for IP in `seq 2 254` do #### GENERAL #### # Clase recontrahija, ac'a van a ir a parar los paquetes que vayan a # clientes. Limito a $RATE y se le baja la prioridad: #10: tc class add dev $IFACE parent 1:2 \ classid 1:$((IP + 1)) \ htb rate $RATEGRALCLI prio 10 ceil $RATETOTAL burst $MINBURST # Esto es un filtro que permite colocar los paquetes con destino a # clientes dentro de la clase 10. N'otese que la prio del filtro nada # tiene que ver con la prioridad de la clase, el objetivo de la # prioridad del filtro es simplemente para definir el orden de testeo # de las reglas: tc filter add dev $IFACE parent 1: \ protocol ip prio 10 \ u32 match ip dst $REDGRAL.$IP flowid 1:$((IP + 1)) done # Este filtro permite saltear el filtro a aquellos paquetes cuyo origen # se encuentre dentro de la lan: tc filter add dev $IFACE parent 1: \ protocol ip prio 5 \ u32 classid 1:1 match ip src $REDGRAL.0/24