Sunteți pe pagina 1din 7

How to make a Wi-Fi repeater with a RaspberryPi.

In this tutrotial I will explain how to make a WiFi repeater using two wifi adapters. I will make
chapters for each part that you need to do. Also this is a compilation of other various tutorials I
found online and I mixed and matched them. A thanks to all of them!
1)
2)
3)
4)
5)
6)
7)

Initial Setup
Permanent names on your adapters
Manual Connectivity (Network Manager can eat a d*ck)
Setting up dhcp
Setting up hostapd
Setting up Forwarding between the two adapters
Lets make everything run on boot
1) Initial Setup

Get Rasbian from the website and extract it on a microSD (there is an ungodly amount of
tutorials on that). After that do a little spring cleaning! Run:
sudo raspi-config
And pick the following options
Resize
Memory split (hungry hungry graphics)
Also run sudo passwd to change the root password
Change the screensaver settings by changing settings in:
/etc/kbd/config
The following:
BLANK_TIME=0
POWERDOWN_TIME=0
Reboot
Sudo apt-get updatet
Sudo apt-get upgrade-get
Oh and also run this command:
sudo apt-get install hostapd git udhcpd

Created by Bert.
Do not alter or change it, you may share it as you see fit and make links to it upload it as a whole!

2) Permanent names on your adapters


Setup specific names for your adapters. Since one of them will be connected to the
router and give out internets while the other will be an access point. So for that we go
to the file:
/etc/udev/rules.d/70-persistent-net.rules
And we write the following commands:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{dev_id}=="0x0",
ATTR{type}=="1", KERNEL=="wlan*", NAME="GIVE_internets"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",


ATTR{address}=="xx:xx:xx:xx:xx:Xx", ATTR{dev_id}=="0x0",
ATTR{type}=="1", KERNEL=="wlan*", NAME="access_point"
Where the xx:xx:xx:xx:xx:xx is the MAC address of your adapters. To find out what
the mac address is write the command ifconfig.
Copy paste the proper MAC addresses and name them as you wish (instead of
GIVE_internets and Access_point).
Reboot!
3) Manual Connectivity
Now we need to setup our connections manually so they connect. Go and write in the
following file:
/etc/network/interfaces
And add the following commands:
allow-hotplug access_point
iface access_point inet static
address 192.168.42.1
netmask 255.255.255.0

Created by Bert.
Do not alter or change it, you may share it as you see fit and make links to it upload it as a whole!

auto GIVE_internets
allow-hotplug GIVE_internets
iface GIVE_internets inet dhcp
wpa-ssid "where_i_get_my_internet"
wpa-psk "superultrasecretwpa2key"
up iptables-restore < /etc/iptables.ipv4.nat

4) Setting up dhcp
To do that comment (#) or uncomment all the needed parts in this file:
/etc/udhcpd.conf
so the uncommented parts are ONLY these:
start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices.
end 192.168.42.20
interface access_point # The device uDHCP listens on.
remaining yes
opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use.
opt subnet 255.255.255.0
opt router 192.168.42.1 #
opt lease 86400 # 1 day DHCP lease time in seconds
Also edit the file:
/etc/default/udhcpd
And comment (add a #) to the line:
DHCPD_ENABLED="no"
So it looks like this:
#DHCPD_ENABLED="no"

Created by Bert.
Do not alter or change it, you may share it as you see fit and make links to it upload it as a whole!

5) Setting up hostapd
I spent hours and hours fighting with this piece of sh*t to get it working properly.
Unfortunately a huge issue is related with what kind of Wifi USB adapter chipset you
have. So I used a generic RTL8188 (those nano wifi adaters) which was a huge pain in
the ass and then I chose the 8192cus . Since hostapd is not as generic as I would hope you
might have to search the net to find another tutorial how to set it up depending on your
Wi-Fi usb chipset. I will write down the procedure for my 8192cus (which can be
modified for any realtek chipset)
So this part is for 8192cus

The 8192cu wireless chipset has a custom method which is another pain in the sphincter but it
works. So we need the kernel supplied driver and we go with:
sudo apt-get install linux-headers-... (Aaaand we wait)
Avoid the supplied driver by blacklisting it in (new file) /etc/modprobe.d/8192cu.conf
By writing:
blacklist rtl8192cu
unplug it, and remove the rtl8192cu driver by writing the command
modprobe -r rtl8192cu (on my latest upgrade and redoing it because I am an idiot and didnt
backup an image file, it gave me an error on this command. So dont worry about it continue and
it will work sunshine)
Now we need to get the hostapd by realtek to make it work.
Go to this page and download the proper file for you model (RTL8192CU and Unix Linux in
case you forgot) here:
http://www.realtek.com/downloads/downloadsView.aspx?Langid=1&PNid=48&PFid=48&Level
=5&Conn=4&DownTypeID=3&GetDown=false&Downloads=true#RTL8192CU
then start cranking out these commands:
unzip RTL8192xC_USB_linux_*.zip
tar zxvf RTL8188C_8192C_USB_linux_*/wpa_supplicant_hostapd/wpa_supplicant_hostapd0.8_rtw_*.tar.gz
cd wpa_supplicant_hostapd-0.8_*/hostapd/
make
sudo cp hostapd hostapd_cli /usr/local/sbin/
And now you SHOULD have hostapd working for you
Created by Bert.
Do not alter or change it, you may share it as you see fit and make links to it upload it as a whole!

Next step is configuring hostapd.conf to our desire. Here is mine (any of the two adapters):
interface= access_point
driver=rtl871xdrv
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=NAME_ME
hw_mode=g
channel=8
wpa=2
wpa_psk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#wpa_passphrase=xxxxxxxxxx
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
beacon_int=100
auth_algs=3
wmm_enabled=1
Make sure there are no empty lines in this it is a very sensitive file with a lot of feelings (but no
seriously make sure no spaces and nothing that shouldnt be there uncommented.

A second note here, I noticed it works if you put your wpa_key as a psk (HEX version). So go to
a website that converts WPA2 passphrases to WPA2 keys like: http://jorisvr.nl/wpapsk.html
Change the file:
/etc/default/hostapd
And change the line from:
#DAEMON_CONF=""
To:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
6) Setting up Forwarding between the two adapters
Start cranking these commands one by one:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Created by Bert.
Do not alter or change it, you may share it as you see fit and make links to it upload it as a whole!

To set this up automatically on boot, edit the file /etc/sysctl.conf and add the following line to the
bottom of the file:
net.ipv4.ip_forward=1
Second, to enable NAT in the kernel, run the following commands:
sudo iptables -t nat -A POSTROUTING -o GIVE_internets -j MASQUERADE
sudo iptables -A FORWARD -i GIVE_internets -o access_point -m state --state
RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i access_point -o GIVE_internets -j ACCEPT
To make this permanent so you don't have to run the commands after each reboot, run the
following command:
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

And to have everything run on boot (in theory) write the following command:
sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable
So as I said the only problem is you need to boot up your Raspberry open a terminal and write
this in order have hostapd (it wont load on boot):
sudo hostapd dd /etc/hostapd/hostapd.conf
7) Lets make everything run on boot
So to get everything up and running in order to be one lazy couch potato (like myself) we need
to do the following:
Create a file in /etc/init.d/
Write the following
#!/bin/sh
sudo hostapd dd /etc/hostapd/hostapd.conf
Created by Bert.
Do not alter or change it, you may share it as you see fit and make links to it upload it as a whole!

Save it any name you want. Then run the following command
ln s /etc/init.d/(name of file) /etc/rc5.d/S99(name of file)
(For all of you whining about this being old school bite me!)
99 is not a must but it should be the last number within the the directory (so if your last one is
S04 you will put S05. Also the name of the file MUST be the same.
Reboot and enjoy!
REFERENCES:
Initial Setup (not the screen saver part): http://www.daveconroy.com/turn-your-raspberry-piinto-a-wifi-hotspot-with-edimax-nano-usb-ew-7811un-rtl8188cus-chipset/
Screen saver: https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=57552
Hostapd8192: https://bogeskov.dk/UsbAccessPoint.html
NAT Forwarding: http://elinux.org/RPI-Wireless-Hotspot
Startup boot and runlevels: https://www.linux.com/news/introduction-services-runlevels-andrcd-scripts

Created by Bert.
Do not alter or change it, you may share it as you see fit and make links to it upload it as a whole!

S-ar putea să vă placă și