EuReKaLoS
Posts: 9
Joined: Tue Nov 28, 2017 6:07 pm

Raspberry Pi Model A Debian 9 into wireless bridge

Fri Dec 01, 2017 5:56 pm

English below:

Bonsoir,
Je vous expose mon problème avec ma Raspberry Pi.
Je souhaite faire de ce petit bébé une passerelle wifi sur un Hotspot "Freewifi".

J'ai plug une carte wifi AlfaNetwork RTL8187 (AWUS036H) en USB qui se connecte sans soucis au Hotspot de façon automatique.
Mais je n'arrive pas a faire de l'ethernet:
-Un serveur DHCP.
-Un pont pour l'accès web.
-Un serveur NoIp (optionnel)

Ma Raspberry tourne sous Raspbian (Debian 9).
J'ai testé "hostapd" avec différent tuto pour faire l'inverse, ethernet vers wifi mais ou j'ai fait des modifications.
Serveur DHCP avec ISC-DHCP-Server, utilisation des iptables, de sysctl et modification des configuration dans /etc/network/interfaces.

Pour faire mes tests je suis sur un Raspberry Pi Model A (oui c'est vieu) et je souhaite juste connecté un laptop en ethernet pour testé l'attribution d'IP etc via mon propre réseau wifi avant de basculer sur le HotSpot)
Je souhaiterais faire un DHCP compatible Windows/linux :)

Configuration ici:
sudo nano /etc/sysctl.conf

Code: Select all

net.ipv4.ip_forward=1
sudo nano /etc/dhcp/dhcpd.conf

Code: Select all

#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

#For the wlan0 who's my AlfaNetwork Card
subnet 192.168.10.0 netmask 255.255.255.0 {
 range 192.168.10.10 192.168.10.20;
 option broadcast-address 192.168.10.255;
 option routers 192.168.10.1;
 default-lease-time 600;
 max-lease-time 7200;
 option domain-name "local-network";
 option domain-name-servers 8.8.8.8, 8.8.4.4;
}
Je parle pas de mon Iptables ici car je n'es pas du tout de connaissance dedans mais si besoin je peux m'y mettre
Si vous avez des pistes des idées ou autres je suis preneur :)

Merci d'avance pour vos réponses :)

Hello

I expose here my problem about my Raspberry Pi.
I want to turn this little baby into a wireless bridge on an open Hotspot called "Freewifi"

I put a wireless usb card AlfaNetwork RTL8187 (AWUS036H) who's connected to the Hotspot automatised.
But i'm not able to turn the ethernet:
-Into a DHCP server
-A bridge for the web.
-A NoIp server (optionnal)

My Raspberry is running on raspbian (Debian 9)
I've tested "hostapd" with differents tuto but it's for ethernet to wireless but i've made some modifications.
DHCP server with ISC-DHCP-Server, using the iptables, sysctl and modifications of the configuration into /etc/network/interfaces.

To run my tests, i'm on a Raspberry Pi Model A (quiet older) and i'd like to connect my laptop to the ethernet for testing the ip pool ect from my personnal wirelesss network before the Htspot tests.
I want a windows/linux working DHCP

Configuration here:
sudo nano /etc/sysctl.conf

Code: Select all

net.ipv4.ip_forward=1
sudo nano /etc/dhcp/dhcpd.conf

Code: Select all

#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

#For the wlan0 who's my AlfaNetwork Card
subnet 192.168.10.0 netmask 255.255.255.0 {
 range 192.168.10.10 192.168.10.20;
 option broadcast-address 192.168.10.255;
 option routers 192.168.10.1;
 default-lease-time 600;
 max-lease-time 7200;
 option domain-name "local-network";
 option domain-name-servers 8.8.8.8, 8.8.4.4;
}
I do not put my iptables here because i'm a rookie with.
But if it needed i can learn.
If you ahve some idea, sugestion or other i'm open :)
Thanks a lot for reading my bad english lol

fruitoftheloom
Posts: 23549
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Fri Dec 01, 2017 7:12 pm

Rather than negativity think outside the box !
RPi 4B 4GB (SSD Boot) RaspiOS64 ARM64
Asus ChromeBox 3 Celeron is my other computer...

EuReKaLoS
Posts: 9
Joined: Tue Nov 28, 2017 6:07 pm

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Sun Dec 03, 2017 1:34 am

Hum i want to do the opposite.

DHCP on eth0 (lan) and wlan0 on the web (wan).

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Sun Dec 03, 2017 2:27 am

No problem. You should use dnsmasq for your dhcp server.

Code: Select all

sudo apt-get install dnsmasq
Then move the original /etc/dnsmasq.conf file.

Code: Select all

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

Open a new /etc/dnsmasq.conf file (empty) and insert this

Code: Select all

interface=eth0
dhcp-range=192.168.4.20,192.168.4.100,255.255.255.0,12h
Open /etc/dhcpcd.conf and add this.

Code: Select all

interface eth0
static ip_address=192.168.4.1/24
Remove any othe static assignments for eth0 if there are any.
Reboot.
You can check to see if dnsmasq is running ok with this.

Code: Select all

sudo service dnsmasq status
It should show active (running).

Edit: I know you have done it, but for others

Code: Select all

sudo nano /etc/sysctl.conf
Uncomment this line

Code: Select all

net.ipv4.ip_forward=1

EuReKaLoS
Posts: 9
Joined: Tue Nov 28, 2017 6:07 pm

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Sun Dec 03, 2017 11:33 pm

Well "SurferTim" i can't clearly said "it works" but i think it works.


I'm just stuck with the wifi connection and get:

Code: Select all

sudo iwconfig wlan0 essid hotspot key off
sudo dhclient -v vlan0
...
No DHCPOFFERS received.
No working leases in persistent database - sleeping.
I'm a little confused with that because sometimes my script connection the hotspot without problem.
To test the "SurferTim" i had a routeur conf in open wireless at 1-3cm of my pi but ??!! isn't working :/

Same problem with the real "FreeWifi" hotspot..
I've test with my RTL8187 and the wlan0 of the Raspberry Pi 3, same problem...

I digging right now...

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Mon Dec 04, 2017 12:08 am

You are much less confused than I am. I don't have a clue what you are trying to do. I thought you were using the wireless as a client to bridge the ethernet interface to an internet connection.

If that is so, you should connect the RPi wireless to your router's ap. That is all that should be required on the wireless end.

Otherwise, you must do a better job of explaining what you want.

EuReKaLoS
Posts: 9
Joined: Tue Nov 28, 2017 6:07 pm

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Mon Dec 04, 2017 2:57 am

Here i try to connect my Rapsberry to a wireless hotspot.
Share the wireless connection through the wlan0 for eth0.

Here eth0 work well like a DHCP server (thanks for that) to connect later my router or just a client (like my laptop).
Currently it work nice and my laptop had an IP from the DHCP server of eth0 (Rapsberry Pi).
But i'm stuck on wireless connection (command prompt only).
He return a "No DHCPOFFER" for the moment.

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Mon Dec 04, 2017 11:32 am

The wireless info should go in /etc/wpa_supplicant/wpa_supplicant.conf.

Code: Select all

network={
   ssid="MySSID"
   psk="MyPassphrase"
}
Check the connection with iwconfig.

Edit: Don't delete the default header info in that file. It won't connect without it. Change the country code to yours.

Code: Select all

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

EuReKaLoS
Posts: 9
Joined: Tue Nov 28, 2017 6:07 pm

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Wed Dec 06, 2017 3:09 pm

Thanks SurferTim for the reply but no password is requiered for the acces :)

Currently it's working for the wireless connection i think my power supply is just Game Over to power Raspberry Pi Model A+Wireless board.
On the USB 3.0 of my laptop it's working perfectly.

I think i gonna add a power board to power rasp pi and the additionnal USB ;)

PS: this is not a power supply problem.
I'm suck a noob -.-
in "/etc/network/interfaces"

Code: Select all

allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
Make the wireless connection work but cancel the server DHCP on the eth0...

EuReKaLoS
Posts: 9
Joined: Tue Nov 28, 2017 6:07 pm

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Wed Dec 06, 2017 6:29 pm

Problem solve (i'm a really big noob lol)

Into the: /etc/network/interfaces

for wlan0 to the connection on the open hotspot "FreeWifi":
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp

for eth0 sharing the wireless connection:
allow-hotplug eth0
iface eth0 inet static
address 192.168.4.1
netmask 255.255.255.0
network 192.168.4.0
broadcast 192.168.4.255

EuReKaLoS
Posts: 9
Joined: Tue Nov 28, 2017 6:07 pm

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Sat Mar 03, 2018 5:45 am

Hello, a little update.

With the help of liberio (the author of the first script) i'm able to launch a connexion with my logs on the Free Wifi hotspot, the connexion is share through ethernet without trouble.
I had sometimes somes "No DHCPOFFER" i think it's the power of the signal (too low)

So what's working:
-Auto connect Free Wifi.
-Shared connection through ethernet.


Currently i'm not able to launch the script at the boot of the Pi

Code: Select all

chmod 755 FreeWifi.sh
update-rc.d FreeWifi.sh defaults .
I post my final script here, i've made minor modification for the name of the interface used (on my rpi3 wlan1 and wlan0 on my rpi model A):

Code: Select all

#!/bin/sh
#Utilisation: sudo ./freewifi.sh
#Source: http://forum.ubuntu-fr.org/viewtopic.php?id=325891&p=2

LOGIN='YourLoginHere'
PASSWORD='YourPasswordHere'
URL_FREE='https://wifi.free.fr'
URL_FREE_AUTH='https://wifi.free.fr/Auth'
URL_GOOGLE='www.google.com'
CONNEXION_FREE='CONNEXION AU SERVICE'
DEJA_CONNECTE_FREE="Site accessible uniquement &agrave partir d'une Freebox"
PAS_CONNECTE_FREE='Login manquant'
CONNEXION_REUSSIE_FREE='CONNEXION AU SERVICE REUSSIE'
CHECK_INTERVAL=10
INTERFACE='wlan0' 

#
# Fonction qui nous connecte au FreeWifi
#
do_start()
{
	# Retourne
	#   0 si le Wifi a ete demarre
	#   1 si le Wifi n'a pas pu etre demarre
	#   Autre si une erreur survient

	while true; do
		echo "Activation de l'interface ${INTERFACE}..."
                rfkill unblock wifi
                sleep 5
		ifconfig ${INTERFACE} up
		echo "Association de l'interface ${INTERFACE} avec le reseau FreeWifi..."
		iwconfig ${INTERFACE} essid FreeWifi
		[ ! -f /sbin/iwconfig -o ! -x /sbin/iwconfig ] && return 1
		[ $(iwconfig 2>&1 | grep -i 'freewifi' | wc -l) -eq 0 ] && echo "${INTERFACE} n'est pas associee a FreeWifi." && return 1
		echo "L'interface ${INTERFACE} est associee au reseau FreeWifi."
		echo "Obtention d'une adresse IP par DHCP..."
		dhclient ${INTERFACE}
		if [ $(ifconfig ${INTERFACE} | grep -i 'inet' | wc -l) -eq 0 ]; then 
			echo "Aucune IP n'est disponible pour l'instant."
		else
			echo "Une IP vient de nous etre affectee : $(ifconfig ${INTERFACE} | sed -n 's/.*inet \([^.]*.[^.]*.[^.]*.[^ ]*\).*$/\1/p')"
			#while true; do
				TEST_PAGE=$(wget -SO- -T 1 -t 1 ${URL_FREE} 2>&1)
				sleep 3
				IS_FREE=$(echo "${TEST_PAGE}" | grep -i "${CONNEXION_FREE}" | grep -i "FreeWifi")
				if [ "X$IS_FREE" != "X" ]; then
					do_connect
					if [ $? -eq 0 ]; then
                				return 0
					fi
				else 
					echo "Nous n'avons pas trouve la chaine '${CONNEXION_FREE}' dans la page ${URL_FREE}."
					echo "Voici le contenu de la page de connexion : ${TEST_PAGE}".
				fi
			#done
		fi
		echo "Nous allons re-essayer dans ${CHECK_INTERVAL} secondes."
		sleep ${CHECK_INTERVAL}
	done
}

#
# Fonction qui arrete le Wifi
#
do_stop()
{
	# Retourne
	#   0 si le Wifi a ete arretee
	#   1 si le Wifi n'a pas pu etre arretee
	#   2 si une autre erreur survient

	echo "Arret de la connexion Wifi..."
	ifconfig ${INTERFACE} down
        rfkill block wifi
        sleep 5
	if [ $? -eq 0 ]; then
		echo "La connexion Wifi a ete arretee."
		return 0
	elif [ $? -eq 1 ]; then 
		echo "La connexion Wifi n'a pas pu etre arretee."
		return 1
	else
		return 3
	fi
}
#
# Fonction qui teste la connection Wifi
#
do_status()
{
	# Retourne
	#   0 si nous sommes deja connecte a FreeWifi
	#   1 si nous sommes deja connecte mais pas en FreeWifi, ou si ping n'a pas recu assez de paquets en réponse 
	#   2 si nous ne sommes pas connecte en Wifi
	#   3 si une autre erreur survient

	TEST_PAGE=$(wget -SO- -T 1 -t 1 ${URL_FREE_AUTH} 2>&1)
	IS_FREE=$(echo "${TEST_PAGE}" | grep -i "${DEJA_CONNECTE_FREE}")
	ping -q -c2 ${URL_GOOGLE} 2>&1
	if [ $? -eq 0 ]; then
		if [ "X${IS_FREE}" != "X" ]; then
			echo "Nous sommes deja connecte a FreeWifi."
			return 0
		elif [ "X$(echo "${TEST_PAGE}" | grep -i "${PAS_CONNECTE_FREE}")" != "X" ] && [ $(ifconfig ${INTERFACE} | grep -i 'inet adr' | wc -l) -ne 0 ] && [ "$(wget -q -T 1 -t 1 ${URL_FREE})" ]; then
			echo "Nous sommes deja connecte, mais pas en FreeWifi."
			return 1
		else
			echo "Un de nos tests de connexion a echoue."
			return 3
		fi
	elif [ $? -eq 1 ]; then
		echo "Ping n'a pas recu assez de paquets en reponse."
		return 1
	elif [ $(ifconfig ${INTERFACE} | grep -i 'inet adr' | wc -l) -eq 0 ]; then 
		echo "Nous ne sommes pas connecte en Wifi."
		return 2
	else 
		return 3
	fi
}

#
# Fonction qui connecte a FreeWifi
#
do_connect()
{
	# Retourne
	#   0 si la connexion s'est bien passee
	#   1 si la connexion s'est mal passee 

	while true; do
	echo "Envoi des identifiants a l'interface FreeWifi..."
	WGET_OUT=$(wget -qO - --post-data="login=${LOGIN}&password=${PASSWORD}" "${URL_FREE_AUTH}" 2>/dev/null | grep -c "${CONNEXION_REUSSIE_FREE}")				
	echo "Les identifiants ont ete envoyes."
	ping -q -c2 ${URL_GOOGLE} 2>&1
	if [ $? -eq 0 ] && [ ${WGET_OUT} -eq 0 ]; then
		echo "Modification du MTU de l'interface ${INTERFACE}..."
		ifconfig ${INTERFACE} mtu 1460 2>/dev/null
		echo "Le MTU a ete modifie : $(ifconfig ${INTERFACE} | sed -n 's/.*mtu \([0-9]*\).*$/\1/p')"
		echo "La connexion a FreeWifi s'est bien passee."
		return 0
		exit 0
	else
		echo "La connexion s'est mal passee, les identifiants n'ont pas ete acceptes."
	fi
	done
}


case "$1" in
  start)
	do_status
	case "$?" in
		0)
			echo "Nous sommes deja connecte en FreeWifi."
			exit 0
			;;
		1|2)
			do_stop
			do_start
			case "$?" in
				0)
					exit 0
					;;
				1)
					exit 1
					;;
				*)
					echo "Une erreur s'est produite dans start !"
					exit 3
					;;
			esac
			;;
		*)
			echo "Une erreur s'est produite dans start !"
			exit 3
			;;
	esac
	;;
  stop)
	do_stop
	case "$?" in
		0)
			exit 0
			;;
		1)
			exit 1
			;;
		*)
			echo "Une erreur s'est produite dans stop !"
			exit 2
			;;
	esac
	;;
  restart)
	do_stop
	do_start
	case "$?" in
		0)
			exit 0					
			;;
		1)  
			exit 1					
			;;
		2)  
			exit 2				
			;;
		*) 
			echo "Une erreur s'est produite dans restart !"
			exit 3				
			;;
	esac
	;;
  status)
	do_status
	case "$?" in
		0)
			exit 0
			;;
		1)
			exit 1
			;;
		2)
			exit 2
			;;
		*)
			echo "Une erreur s'est produite dans status !"
			exit 3
			;;
	esac
	;;
  connect)
	do_connect
	case "$?" in
		0)
			exit 0
			;;
		1)
			exit 1
			;;
		*)
			echo "Une erreur s'est produite dans connect !"
			exit 3
			;;
	esac
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status|connect}" >&2
	exit 3
	;;
esac

exit 0
If anyone see a litttle mistake or something it's welcome :D

EuReKaLoS
Posts: 9
Joined: Tue Nov 28, 2017 6:07 pm

Re: Raspberry Pi Model A Debian 9 into wireless bridge

Tue Mar 20, 2018 12:34 am

Hello, little update currently i'm stuck.
The script works good in a crontab but i'm flood of dhcpclient -v wlan0...

The memory is flooded and my RPI froze every times i restart her.

For example when i test it on my RPI 3:
Image

Return to “Networking and servers”