Script connexion fibre orange derrière ONT

Tags: #<Tag:0x00007f63f2a17090> #<Tag:0x00007f63f2a16fc8>

Hello à toutes et tous,
Avec ce scripts, j’aimerais lancer ma connexion en dhcp derrière l’ont d’Orange .
Je suis loin de maîtriser l’écriture de scripts.
La preuve j’ai besoin d’aide :stuck_out_tongue:

#!/bin/bash
#Converti le fti
USERNAME=$1
AUTHSTRING=00:00:00:00:00:00:00:00:00:00:00:66:74:69:2f

for (( i=0; i<${#USERNAME}; i++ )); do
  HEXCHAR=$(echo -n ${USERNAME:$i:1} | od -An -txC | xargs)
  AUTHSTRING=${AUTHSTRING}:${HEXCHAR}
done

echo ${AUTHSTRING};

#Fichier dhclient
#Ecriture
echo 'option rfc3118-authentication code 90 = string;" >> /diagbox/web/tmp/dhclient.conf
echo "interface \"orange\" {" >> /diagbox/web/tmp/dhclient.conf
echo "send vendor-class-identifier \"sagem\";" >> /diagbox/web/tmp/dhclient.conf
echo "send user-class \"+FSVDSL_livebox.Internet.softathome.Livebox3\";" >> /diagbox/web/tmp/dhclient.conf
echo "send rfc3118-authentication ${AUTHSTRING} ;" >> /diagbox/web/tmp/dhclient.conf
echo 'request subnet-mask, routers,' >> /diagbox/web/tmp/dhclient.conf
echo 'domain-name, broadcast-address, dhcp-lease-time,' >> /diagbox/web/tmp/dhclient.conf
echo 'dhcp-renewal-time, dhcp-rebinding-time,' >> /diagbox/web/tmp/dhclient.conf
echo 'rfc3118-authentication;' >> /diagbox/web/tmp/dhclient.conf
echo 'supersede domain-name-servers 8.8.8.8, 8.8.4.4;' >> /diagbox/web/tmp/dhclient.conf
echo '}' >> /diagbox/web/tmp/dhclient.conf
done

#Deplacement
if sudo cp /diagbox/web/tmp/dhclient.conf /etc/dhcp/dhclient.conf; then
	echo 'fichier dhclient modifie';
else
	echo "Echec déplacement fichier dhclient" >> /diagbox/web/tmp/error.log
	exit
fi

#iptables
if sudo cp /etc/iptables.ipv4.nat.backup_rescue_dhcp /etc/iptables.ipv4.nat; then
	echo 'fichier iptables modifié';
else
	echo "Echec déplacement fichier iptables" >> /diagbox/web/tmp/error.log
	exit
fi
sudo iptables -t mangle -I POSTROUTING -o orange -j CLASSIFY --set-class 0:1

#Modification interfaces eth0
if sudo ifdown eth0; then
	echo 'arret eth0';
else
	echo "Echec arret ethO" >> /diagbox/web/tmp/error.log
	exit
fi

if sudo cp /etc/network/interfaces_RESCUE_DHCP /etc/network/interfaces; then
	echo 'configuration interfaces modifié';
else
	echo "Echec modification configuration ethO" >> /diagbox/web/tmp/error.log
	exit
fi

if sudo ifup eth0; then
	echo 'activation eth0';
else
	echo "Echec activation ethO" >> /diagbox/web/tmp/error.log
	exit
fi

#Test 8 pings
sudo ping 8.8.8.8 -c8 -q
if [ $? != 1 ]; then
	echo "connexion derrière ont opérationnel" >> /diagbox/web/tmp/ping.txt
else
	echo "nok" >> /diagbox/web/tmp/ping.txt
fi

en cherchant sur la toile, j’ai trouvé comment remplacer la Livebox en utilisant le protocole DHCP.
Quand je le fais manuellement, ça fonctionne.
Mais mon script me sort une erreur :slight_smile:

 root@diagbox:~# bash /diagbox/scripts_sh/speedtest_ont.sh adsl@adsl
/diagbox/scripts_sh/cnx_ont.sh: line 5: $'\r': command not found
/diagbox/scripts_sh/cnx_ont.sh: line 6: syntax error near unexpected token                                       `$'do\r''
/diagbox/scripts_sh/cnx_ont.sh: line 6: `for (( i=0; i<${#USERNAME}; i++ )                                      '; do

Et je ne sais pas à quoi ça correspond lol.
Merci d’avance pour votre aide.

Je me réponds à moi-même :slight_smile:
Vu que j’édite mes scripts sur notepad++ ( windows),
la solution que j’ai trouvé est :

dos2unix et le nom du script :stuck_out_tongue:

Autre petit problème :slight_smile:
Le script passe bien mais à la fin j’ai besoin de lancé les interfaces : eth0,wlan0 et la nouvelle interface orange ( la connexion en dhcp)
Je fais un ifup -a mais je suis obligé de rebooter la carte pour que ca prenne en compte.

Voici le script modifié :slight_smile:

#!/bin/bash
#Effacer les fichier tempo si presents
if [ -f "/diagbox/web/tmp/dhclient.conf" ];then
	echo "Le fichier de configuration existe !";
	if sudo rm /diagbox/web/tmp/dhclient.conf; then
		echo "fichier dhclient efface"	
	else
		echo "Echec suppression tempo dhclient deja existant" >> /diagbox/web/tmp/error.log
		exit
	fi
fi

if [ -f "/diagbox/web/tmp/iperf_upload.txt" ];then
	echo "Le fichier de iperf upload existe !";
	if sudo rm /diagbox/web/tmp/iperf_upload.txt; then
		echo "fichier iperf upload efface"	
	else
		echo "Echec suppression tempo iperf upload deja existant" >> /diagbox/web/tmp/error.log
		exit
	fi
fi

if [ -f "/diagbox/web/tmp/iperf_download.txt" ];then
	echo "Le fichier de iperf download existe !";
	if sudo rm /diagbox/web/tmp/iperf_download.txt; then
		echo "fichier iperf download efface"	
	else
		echo "Echec suppression tempo iperf download deja existant" >> /diagbox/web/tmp/error.log
		exit
	fi
fi

#fti conversion
USERNAME=$1
AUTHSTRING=00:00:00:00:00:00:00:00:00:00:00:66:74:69:2f
for (( i=0; i<${#USERNAME}; i++ )); do
  HEXCHAR=$(echo -n ${USERNAME:$i:1} | od -An -txC | xargs)
  AUTHSTRING=${AUTHSTRING}:${HEXCHAR}
done
echo ${AUTHSTRING} 

#Fichier dhclient
#Ecriture
echo 'option rfc3118-authentication code 90 = string;' >> /diagbox/web/tmp/dhclient.conf
echo "interface \"orange\" {" >> /diagbox/web/tmp/dhclient.conf
echo "send vendor-class-identifier \"sagem\";" >> /diagbox/web/tmp/dhclient.conf
echo "send user-class \"+FSVDSL_livebox.Internet.softathome.Livebox3\";" >> /diagbox/web/tmp/dhclient.conf
echo "send rfc3118-authentication ${AUTHSTRING} ;" >> /diagbox/web/tmp/dhclient.conf
echo 'request subnet-mask, routers,' >> /diagbox/web/tmp/dhclient.conf
echo 'domain-name, broadcast-address, dhcp-lease-time,' >> /diagbox/web/tmp/dhclient.conf
echo 'dhcp-renewal-time, dhcp-rebinding-time,' >> /diagbox/web/tmp/dhclient.conf
echo 'rfc3118-authentication;' >> /diagbox/web/tmp/dhclient.conf
echo 'supersede domain-name-servers 8.8.8.8, 8.8.4.4;' >> /diagbox/web/tmp/dhclient.conf
echo '}' >> /diagbox/web/tmp/dhclient.conf


#Deplacement
if sudo cp /diagbox/web/tmp/dhclient.conf /etc/dhcp/dhclient.conf; then
	echo 'fichier dhclient modifie';
else
	echo "Echec déplacement fichier dhclient" >> /diagbox/web/tmp/error.log
	exit
fi

#iptables
if sudo cp /etc/iptables.ipv4.nat.backup_rescue_dhcp /etc/iptables.ipv4.nat; then
	echo 'fichier iptables modifié';
else
	echo "Echec déplacement fichier iptables" >> /diagbox/web/tmp/error.log
	exit
fi
sudo iptables-restore < /etc/iptables.ipv4.nat

#Modification interfaces eth0
if sudo ifdown eth0; then
	echo 'arret eth0';
else
	echo "Echec arret ethO" >> /diagbox/web/tmp/error.log
	exit
fi

if sudo cp /etc/network/interfaces_RESCUE_DHCP /etc/network/interfaces; then
	echo 'configuration interfaces modifié';
else
	echo "Echec modification configuration ethO" >> /diagbox/web/tmp/error.log
	exit
fi

if sudo ifup -a; then
	echo 'activation des interfaces';
else
	echo "Echec activation interfaces" >> /diagbox/web/tmp/error.log
	exit
fi

Je me réponds à nouveau, je ne me suis pas montré assez patient :slight_smile:

Du coups j’ai mis un test de 15 pings en fin et des que le ping sort positif, tout est bon.

Par contre du coups j’ai un autre problème : un probleme en cache un autre qui en cache un autre :stuck_out_tongue:

Quand je fais mes tests de débit derrière ma livebox j’ai comme valeurs :
download : 980M
Upload : 240M
(Avec un meilleur débit pour iperf3 que speedtest-cli, mais ça reste en moyenne ça)

Par contre, quand je fais le test de débit directement derrière un ont, que je sois en pppoe ou en dhcp
j’ai ça :

PPPOE

root@diagbox:~# speedtest-cli --server 4661
Retrieving speedtest.net configuration...
Testing from Orange (90.87.121.108)...
Retrieving speedtest.net server list...
Retrieving information for the selected server...
Hosted by Orange (Marseille) [662.05 km]: 27.018 ms
Testing download speed................................................................................
Download: 133.72 Mbit/s
Testing upload speed................................................................................................
Upload: 60.43 Mbit/s
root@diagbox:~# iperf3 -c bouygues.iperf.fr -4 -p 5202
Connecting to host bouygues.iperf.fr, port 5202
[  4] local 90.87.121.108 port 33782 connected to 89.84.1.222 port 5202
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  11.5 MBytes  96.6 Mbits/sec    0    176 KBytes
[  4]   1.00-2.00   sec  9.99 MBytes  83.8 Mbits/sec    0    117 KBytes
[  4]   2.00-3.00   sec  9.42 MBytes  79.0 Mbits/sec    0    169 KBytes
[  4]   3.00-4.00   sec  12.2 MBytes   102 Mbits/sec    0    153 KBytes
[  4]   4.00-5.00   sec  9.70 MBytes  81.3 Mbits/sec    0    149 KBytes
[  4]   5.00-6.00   sec  11.4 MBytes  96.0 Mbits/sec    0    200 KBytes
[  4]   6.00-7.00   sec  12.8 MBytes   107 Mbits/sec    0    127 KBytes
[  4]   7.00-8.00   sec  10.2 MBytes  85.3 Mbits/sec    0    179 KBytes
[  4]   8.00-9.00   sec  13.7 MBytes   115 Mbits/sec    0    229 KBytes
[  4]   9.00-10.00  sec  14.2 MBytes   119 Mbits/sec    0    200 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec   115 MBytes  96.5 Mbits/sec    0             sender
[  4]   0.00-10.00  sec   115 MBytes  96.3 Mbits/sec                  receiver

iperf Done.
root@diagbox:~# iperf3 -c bouygues.iperf.fr -4 -p 5202 -R
Connecting to host bouygues.iperf.fr, port 5202
Reverse mode, remote host bouygues.iperf.fr is sending
[  4] local 90.87.121.108 port 33786 connected to 89.84.1.222 port 5202
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-1.00   sec  17.7 MBytes   148 Mbits/sec
[  4]   1.00-2.00   sec  20.9 MBytes   176 Mbits/sec
[  4]   2.00-3.00   sec  20.8 MBytes   174 Mbits/sec
[  4]   3.00-4.00   sec  17.7 MBytes   149 Mbits/sec
[  4]   4.00-5.00   sec  20.3 MBytes   171 Mbits/sec
[  4]   5.00-6.00   sec  19.2 MBytes   161 Mbits/sec
[  4]   6.00-7.00   sec  19.9 MBytes   167 Mbits/sec
[  4]   7.00-8.00   sec  16.7 MBytes   140 Mbits/sec
[  4]   8.00-9.00   sec  14.5 MBytes   121 Mbits/sec
[  4]   9.00-10.00  sec  17.8 MBytes   150 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec   187 MBytes   157 Mbits/sec   85             sender
[  4]   0.00-10.00  sec   186 MBytes   156 Mbits/sec                  receiver

iperf Done.

DHCP
root@diagbox:/diagbox# iperf3 -c bouygues.iperf.fr -4 -p 5202 -R
Connecting to host bouygues.iperf.fr, port 5202
Reverse mode, remote host bouygues.iperf.fr is sending
[ 4] local 90.87.121.108 port 33970 connected to 89.84.1.222 port 5202
[ ID] Interval Transfer Bandwidth
[ 4] 0.00-1.00 sec 18.4 MBytes 155 Mbits/sec
[ 4] 1.00-2.00 sec 17.3 MBytes 145 Mbits/sec
[ 4] 2.00-3.00 sec 20.3 MBytes 170 Mbits/sec
[ 4] 3.00-4.00 sec 17.9 MBytes 150 Mbits/sec
[ 4] 4.00-5.00 sec 20.1 MBytes 169 Mbits/sec
[ 4] 5.00-6.00 sec 16.8 MBytes 141 Mbits/sec
[ 4] 6.00-7.00 sec 14.5 MBytes 122 Mbits/sec
[ 4] 7.00-8.00 sec 17.9 MBytes 150 Mbits/sec
[ 4] 8.00-9.00 sec 20.9 MBytes 175 Mbits/sec
[ 4] 9.00-10.00 sec 22.3 MBytes 187 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-10.00 sec 189 MBytes 158 Mbits/sec 84 sender
[ 4] 0.00-10.00 sec 187 MBytes 157 Mbits/sec receiver

iperf Done.
root@diagbox:/diagbox# iperf3 -c bouygues.iperf.fr -4 -p 5202
Connecting to host bouygues.iperf.fr, port 5202
[  4] local 90.87.121.108 port 33974 connected to 89.84.1.222 port 5202
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  5.29 MBytes  44.4 Mbits/sec    0    105 KBytes
[  4]   1.00-2.00   sec  8.86 MBytes  74.3 Mbits/sec    0    156 KBytes
[  4]   2.00-3.00   sec  12.2 MBytes   103 Mbits/sec    0    208 KBytes
[  4]   3.00-4.00   sec  11.6 MBytes  97.7 Mbits/sec    0    193 KBytes
[  4]   4.00-5.00   sec  11.2 MBytes  93.6 Mbits/sec    0    125 KBytes
[  4]   5.00-6.00   sec  7.55 MBytes  63.4 Mbits/sec    0    132 KBytes
[  4]   6.00-7.00   sec  10.6 MBytes  89.0 Mbits/sec    0    184 KBytes
[  4]   7.00-8.00   sec  14.0 MBytes   118 Mbits/sec    0    235 KBytes
[  4]   8.00-9.00   sec  15.1 MBytes   127 Mbits/sec    0    141 KBytes
[  4]   9.00-10.00  sec  11.1 MBytes  93.2 Mbits/sec    0    191 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec   108 MBytes  90.3 Mbits/sec    0             sender
[  4]   0.00-10.00  sec   107 MBytes  90.0 Mbits/sec                  receiver

iperf Done.

J’ai essayé la même chose avec une autre carte qui est moins puissant et moins bonne : bananapi m2 avec comme os bananian et j’ai presque les mêmes valeurs que derrière ma Livebox.

Je ne vois pas d’où ç pourrait venir :slight_smile:

Petite info qui pourrait être important l’os de ma carte ( tinkerboard) est armbian basé sur Debian jessie