2014년 7월 26일 토요일

[rapsberry pi] make Acesse Point

I finally succeeded in building a router with a raspberry pi.  I am embedded network engineer. and It have been taken a long time,ridiculous. However, I'm satisfied.
0.subject


The using raspberry pie, the goal is to implement a wireless router.




1.Devices





  • raspberry pi
  • RTL8185(LAN-STAR LS-NAL11)
  • RTL8188CU(Wevo U150 - ) 
  • MAX232



you can see device list. USB-wire LAN card is used for LAN, wifi-USB is used to the product with 8188CU.

When the network is initialized MAX232 ssh connection is used for console. 


USB wifi dongle is used for wifi AP (wireless router mode). In addition, Linux drivers support the product must be public.

USB wired NIC driver supports Linux as well in the price of the product.




2.Network Interface



I have planned as shown in the figure.


3.Set bridge


First thing to do is that you set the bridge. So that communication between the LAN eth1 and wlan0 available.


1)Install Bridge package
 $sudo apt-get install bridge-utils




2) /etc/network/interfaces Edit
Set the bridge br0 with wlan0,eth1.

/etc/network/interface
auto lo
auto br0
iface lo inet loopback
iface eth0 inet dhcp

iface br0 inet static
   bridge_ports eth1 wlan0
   address 192.168.0.1
   broadcast 192.168.0.255
   netmask 255.255.255.0



4.hostapd

1)Install Package
$sudo apt-get install hostapd

2)/usr/sbin/hostapd exchange
exchange old hostapd.

$wget http://www.daveconroy.com/wp3/wp-content/uploads/2013/07/hostapd.zip
$unzip hostapd.zip

Any chance that may have been in operation, hostapd to stop and exchange.

$sudo service hostapd stop
$sudo cp hostapd /usr/sbin/hostapd

3) /etc/hostapd/hostapd.conf 
lets you edit hostapd. Wlan0 is the interface, and the SSID is RPiAP. The password is PASSWORD.

rtl871xdrv is RTL8188CU hostapd of driver name. other parment so the technical part of the explanation. so I am no explain.


/etc/default/udhcpd
#created by ./install_ap.sh
interface=wlan0
bridge=br0
driver=rtl871xdrv
country_code=NZ
ctrl_interface=wlan0
ctrl_interface_group=0
ssid=RPiAP
hw_mode=g
channel=1
wpa=3
wpa_passphrase=PASSWORD
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
beacon_int=1000
auth_algs=3
macaddr_acl=0
wmm_enabled=1
eap_reauth_period=360000000
       


5.udhcpd

1)Install Package
$sudo apt-get install udhcpd

2) /etc/default/udhcpd Edit
must shold edit the file first. Otherwise, an error occurs.  
Edited by red part.

/etc/default/udhcpd
# Comment the following line to enable
DHCPD_ENABLED="yes"

# Options to pass to busybox' udhcpd.
#
# -S    Log to syslog
# -f    run in foreground

DHCPD_OPTS="-S"
       

3) /etc/udhcpd.conf

Edit the file that udhcp.conf. 

It is a real udhcp AP is the most used.  The biggest feature is that the interface will be set to br0.

Gateway address is 192.168.0.1 is the address of br0.  

Edited by red part. 


/etc/udhcpd.conf
# Sample udhcpd configuration file (/etc/udhcpd.conf)

# The start and end of the IP lease block

start        192.168.0.100    #default: 192.168.0.20
end        192.168.0.200    #default: 192.168.0.254



# The interface that udhcpd will use

interface    br0        #default: eth0



# The maximim number of leases (includes addressesd reserved
# by OFFER's, DECLINE's, and ARP conficts

#max_leases    254        #default: 254


# If remaining is true (default), udhcpd will store the time
# remaining for each lease in the udhcpd leases file. This is
# for embedded systems that cannot keep time between reboots.
# If you set remaining to no, the absolute time that the lease
# expires at will be stored in the dhcpd.leases file.

#remaining    yes        #default: yes


# The time period at which udhcpd will write out a dhcpd.leases
# file. If this is 0, udhcpd will never automatically write a
# lease file. (specified in seconds)

#auto_time    7200        #default: 7200 (2 hours)


# The amount of time that an IP will be reserved (leased) for if a
# DHCP decline message is received (seconds).

#decline_time    3600        #default: 3600 (1 hour)


# The amount of time that an IP will be reserved (leased) for if an
# ARP conflct occurs. (seconds

#conflict_time    3600        #default: 3600 (1 hour)


# How long an offered address is reserved (leased) in seconds

#offer_time    60        #default: 60 (1 minute)

# If a lease to be given is below this value, the full lease time is
# instead used (seconds).

#min_lease    60        #defult: 60


# The location of the leases file

#lease_file    /var/lib/misc/udhcpd.leases    #defualt: /var/lib/misc/udhcpd.leases

# The location of the pid file
#pidfile    /var/run/udhcpd.pid    #default: /var/run/udhcpd.pid

# Everytime udhcpd writes a leases file, the below script will be called.
# Useful for writing the lease file to flash every few hours.

#notify_file                #default: (no script)

#notify_file    dumpleases    # <--- useful for debugging

# The following are bootp specific options, setable by udhcpd.

#siaddr        192.168.0.22        #default: 0.0.0.0

#sname        zorak            #default: (none)

#boot_file    /var/nfs_root        #default: (none)

# The remainer of options are DHCP options and can be specifed with the
# keyword 'opt' or 'option'. If an option can take multiple items, such
# as the dns option, they can be listed on the same line, or multiple
# lines. The only option with a default is 'lease'.

#Examles
opt    dns    8.8.8.8 8.8.8.4
option    subnet    255.255.255.0
opt    router    192.168.0.1
#opt    wins    192.168.10.10
#option    dns    129.219.13.81    # appened to above DNS servers for a total of 3
option    domain    local
option    lease    864000        # 10 days of secon
ds


# Currently supported options, for more info, see options.c
#opt subnet
#opt timezone
#opt router
#opt timesrv
#opt namesrv
#opt dns
#opt logsrv
#opt cookiesrv
#opt lprsrv
#opt bootsize
#opt domain
#opt swapsrv
#opt rootpath
#opt ipttl
#opt mtu
#opt broadcast
#opt wins
#opt lease
#opt ntpsrv
#opt tftp
#opt bootfile
#opt wpad

# Static leases map
#static_lease 00:60:08:11:CE:4E 192.168.0.54
#static_lease 00:60:08:11:CE:3E 192.168.0.44


After editing lets restart a service.

$sudo service udhcpd restart

6.iptables & ip4 forwarding

Linux iptable modification or rejection of the packet by the firewall or to provide services available. 
This is the /proc file are the same.  Linux, which application the user is to control the level in the Linux network capabilities.


1)iptable NAT
$sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

 2)ipv4 ip_forward
This sounds crazy, but, ip_forwarding  was denied permission to sudo . So let super user to activate ip_forwarding.
 
$su
#echo 1 > /proc/sys/net/ipv4/ip_forward




7.Extra edition

Every time you restart the Raspberry Pi, iptable command to that forwarding is suck. I edit the init file that  a boot command to be solved.


/etc/init.d/rc.local
#! /bin/sh
### BEGIN INIT INFO
# Provides:          rc.local
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Run /etc/rc.local if it exist
### END INIT INFO


PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
        if [ -x /etc/rc.local ]; then
                [ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local"
                /etc/rc.local
                ES=$?                                                                          
                [ "$VERBOSE" != no ] && log_end_msg $ES                                        
                return $ES                                                                     
        fi                                                                                     
}                                                                                              
                                                                                               
case "$1" in                                                                                   
    start)                                                                                     
        do_start                                                                               
        ;;                                                                                     
    restart|reload|force-reload)                                                               
        echo "Error: argument '$1' not supported" >&2                                          
        exit 3                                                                                 
        ;;                                                                                     
    stop)                                                                                      
        ;;                                                                                     
    *)                                                                                         
        echo "Usage: $0 start|stop" >&2                                                        
        exit 3                                                                                 
        ;;                                                                                     
esac                                                                                           
echo 1 > /proc/sys/net/ipv4/ip_forward                                                         
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 

       


8. network switch


Finally, connect eth1(RTL8185-USB internet adapter) to switch. end this work.


9.costs


list raspberry pi Ap generally AP
wireless LAN USB Card RTL8188CU[wlan0] $17 $0
wire LAN USB Card RTL8185[eth1] $12.7 $0
5port 100Mbps Switch $7.7 $0
Body $25 $12.7
Sum $62.4 $12.7


Raspberry AP is pefectly Crazy Idea.
if calculate the time,wage and added cost that. It is  over the $300.



10.Ending

It is characterized by many in South Korea utilizing multicast IP TV is. The AP that the Raspberry Pi is a traditional router performs multicast snooping and proxy in the proxy is thought possible. Further more that is going to run the daemon.

Also, when it comes to measuring the performance of AP Raspberry Pi is going to try.







댓글 없음:

댓글 쓰기