Ir ao conteúdo
  • Cadastre-se

Shell Script para encontrar MTU: alguém sabe?


arcmatrixnt

Posts recomendados

olá,

estou precisando de um shell script para que o DDWRT encontre automaticamente o melhor valor para o MTU sempre que ligar o router e, em seguida, for ligado ou plugado ao modem (conexão a cabo).

encontrei o seguinte modelo:

#!/bin/sh

h=${1:-74.125.137.147}

while wget http://$h -O /dev/null
do
sleep 15
done

for n in 1500 1464 1444 1424 1404 1384 1364 1344 1324 1304 1284 1264 1244 1224 1204
do
output=`ping -c 1 -M do -s $n $h`
echo "$output"
echo $output | grep "Frag needed"
done

tcpdump -v -n -w

não testei por não compreender corretamente a sua função, ao que eu vi ele vai diminuindo o valor do MTU enquanto não consegue a resposta do ping, mas eu tenho algumas dúvidas:

> esse script pode ser melhorado? Como?

> como grava-lo no router para que seja carregado sempre que ligar na tomada?

Link para o comentário
Compartilhar em outros sites

encontrei um shell script que configura o IPV6, pude notar que é possível fazer um comando melhor que o de cima:

#!/bin/sh

MTU=1280

# Get our external IPv4 (in case the IP isn't available, because we don't have a connection yet, retry 3 times or until we

succeed)
RETRIES=3
while [ -z ${EXTIP} ]; do
# PPPoE devices are on ppp0, all others are on vlan1 or eth1; we try all
for DEV in "ppp0" "vlan1" "eth1"; do
EXTIP=`/usr/sbin/ip -4 addr show dev ${DEV} | grep inet | awk '{print $2}' | cut -d/ -f1`
if [ -n "$EXTIP" ]; then
logger -st sixxs -- "- External IP ${EXTIP} found on device ${DEV}"
break 2
fi
done
let RETRIES-=1
if [ "$RETRIES" -gt 0 ]; then
logger -st sixxs -- "- No external IP found; trying again in 10 secs..."
sleep 10
else
logger -st sixxs -- "- No external IP found after 30 seconds; quitting"
exit 1
fi
done

# Check for optimal MTU
# Max MTU is device's MTU minus 20 (IPv6 headers are 20 bytes bigger than IPv4)
RECMTU=`ip addr show dev $DEV | grep mtu | awk '{print $5}'`
RECMTU=`expr ${RECMTU} - 20`
if [ ${MTU} -lt ${RECMTU} ]; then
logger -st sixxs -- "- Note: You could increase your MTU setting from ${MTU} to ${RECMTU} for improved performance.

Change it in ${0}, radvd.conf and in the SixXS tunnel config."
elif [ ${MTU} -gt ${RECMTU} ]; then
### TODO: What happens if MTU is too high?
logger -st sixxs -- "- WARNING: Your MTU ${MTU} is too high - it should be ${RECMTU}. Change it in ${0}, radvd.conf and

in the SixXS tunnel config."
fi

agora a dúvida é: Como tranformar isso para encontrar automaticamente o valor do MTU para conexões a cabo?

moderador: eu não sei se há uma sala mais adequada para este tópico, se for possível encontrar um mais próximo, talvez até em programação Unix porque é assunto correlato, então pode mover!!! obrigado.

Link para o comentário
Compartilhar em outros sites

  • 2 semanas depois...

no wiki do ddwrt tem esse script para manter a conexão:

#!/bin/sh
INTERVAL=10
PACKETS=1
UDHCPC="udhcpc -i vlan1 -p /var/run/udhcpc.pid -s /tmp/udhcpc"
IFACE=vlan1


ME=`basename $0`
RUNNING=`ps | awk '/'"$ME"'/ {++x}; END {print x+0}'`
if [ "$RUNNING" -gt 3 ]; then
echo "Another instance of \"$ME\" is running"
exit 1
fi

while sleep $INTERVAL
do
TARGET=`ip route | awk '/default via/ {print $3}'`
RET=`ping -c $PACKETS $TARGET 2> /dev/null | awk '/packets received/ {print $4}'`

if [ "$RET" -ne "$PACKETS" ]; then
echo "Ping failed, releasing IP address on $IFACE"
#send a RELEASE signal
kill -USR2 `cat /var/run/udhcpc.pid` 2> /dev/null
#ensure udhcpc is not running
killall udhcpc 2> /dev/null
echo "Renewing IP address: $IFACE"
$UDHCPC
echo "Waiting 10 s..."
sleep 10
else
echo "Network is up via $TARGET"
fi
done

veja neste link (Automatic Connection Repair)

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!