5.2 KiB
Raspberry Pi Access Point
For the Raspberry Pi 3, I used this page except for the /etc/network/interface which I did as below.
Of course, first I had to do Basic Raspberry Pi Set-up.
So I wanted to see the state of the USB card and driver
dmesg | grep rtl
[ 6.875478] usbcore: registered new interface driver rtl8192cu
lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
Next was installing hostapd and some utilities
sudo apt-get install hostapd bridge-utils iw iptables-persistent
I wanted to run a wireless router, so followed, well adapted, the instructions at http://qcktech.blogspot.com/2012/08/raspberry-pi-as-router.html and http://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/overview and http://secsup.net/index.php/shaded_grey/comments/comcast_consumer_ipv6_configuration_raspberry_pi_as_bridge_base_station/
Edit/create /etc/hostapd/hostapd.conf as follows:
interface=wlan0
driver=nl80211
ssid=rgnet-pi3
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=arbitrarykeys
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
And hack /etc/default/hostapd to the following (and be sure to remove the #ash)
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Then configure /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet static
address 100.64.64.1/24
Running an access point requires a dhcp server
sudo apt-get install isc-dhcp-server
In /etc/dhcp/dhcpd.conf, make it authoritative by uncommenting
#authoritative;
and then hack
default-lease-time 3600;
max-lease-time 7200;
option domain-name "psg.com rg.net";
option domain-name-servers 8.8.8.8, 8.8.4.4;
option ntp-servers 24.16.172.3;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
subnet 192.168.2.0 netmask 255.255.255.0 {
}
subnet 100.64.64.0 netmask 255.255.255.0 {
range 100.64.64.10 100.64.64.100;
option broadcast-address 100.64.64.255;
option routers 100.64.64.1;
}
Network 192.168.2.0 is the ether over which I am working doing the install.
And then start the dhcpd to test it
sudo service isc-dhcp-server start
Get autostart scripts
sudo ln -s /etc/init.d/networking /etc/rc2.d/S00networking
sudo ln -s /etc/init.d/hostapd /etc/rc2.d/S02hostapd
sudo ln -s /etc/init.d/isc-dhcp-server /etc/rc2.d/S02isc-dhcp-server
That last may already exist from the apt-get install.
To allow forwarding, in /etc/sysctl.conf, uncomment
net.ipv4.ip_forward=1
Set up the NAT in iptables
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
And the IPTABLE entry for the NAT
sudo iptables-save | tee /etc/iptables/rules.v4
The iptables-persistent will see this id loaded on boot.
It would be wise to test with
# sudo iptables -t nat -S
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-A POSTROUTING -o eth0 -j MASQUERADE
# sudo iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
Sad news
# sudo /usr/sbin/hostapd -B -P /var/run/hostapd.pid /etc/hostapd/hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
Could not set channel for kernel driver
Interface initialization failed
wlan0: interface state UNINITIALIZED->DISABLED
wlan0: AP-DISABLED
wlan0: Unable to setup interface.
wlan0: interface state DISABLED->DISABLED
wlan0: AP-DISABLED
hostapd_free_hapd_data: Interface wlan0 wasn't started
nl80211: deinit ifname=wlan0 disabled_11b_rates=0
This hack helped
cat > /etc/dnsmasq.conf << EOF
interface=wlan0 # Use interface wlan0
listen-address=100.64.64.1 # Explicitly specify the address to listen on
bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere
server=8.8.8.8 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
bogus-priv # Never forward addresses in the non-routed address spaces.
dhcp-range=100.64.64.10,100.64.64.99,12h # Assign IP addresses between 100.64.64.10 and100.64.64.99 with a 12 hour lease time
EOF
Set hostapd to auto-start, though I am not sure that this is needed
sudo update-rc.d hostapd enable
2019.04.04