Raspberry Pi: Difference between revisions
No edit summary |
No edit summary |
||
Line 24: | Line 24: | ||
The file should contain, everything else can be commented out or deleted: | The file should contain, everything else can be commented out or deleted: | ||
auto lo | |||
iface lo inet loopback | iface lo inet loopback | ||
allow-hotplug eth0 | |||
allow-hotplug eth0 | iface eth0 inet dhcp | ||
iface eth0 inet dhcp | allow-hotplug wlan0 | ||
iface wlan0 inet static | |||
allow-hotplug wlan0 | address 10.1.1.1 | ||
iface wlan0 inet static | netmask 255.255.255.0 | ||
network 10.1.1.0 | |||
broadcast 10.1.1.255 | |||
Install hostapd, and configure it. | Install hostapd, and configure it. | ||
Line 43: | Line 41: | ||
<code>$ sudo vi /etc/hostapd/hostapd.conf</code> | <code>$ sudo vi /etc/hostapd/hostapd.conf</code> | ||
interface=wlan0 | |||
driver=nl80211 | driver=nl80211 | ||
ssid=Hackers & Designers | ssid=Hackers & Designers | ||
hw_mode=g | hw_mode=g | ||
channel=6 | channel=6 | ||
ieee80211n=1 | ieee80211n=1 | ||
wmm_enabled=1 | wmm_enabled=1 | ||
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] | ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] | ||
macaddr_acl=0 | macaddr_acl=0 | ||
ignore_broadcast_ssid=0 | ignore_broadcast_ssid=0 | ||
<code>$ sudo vi /etc/default/hostapd</code> | <code>$ sudo vi /etc/default/hostapd</code> | ||
Line 64: | Line 62: | ||
<code>$ sudo apt-get install dnsmasq</code> | <code>$ sudo apt-get install dnsmasq</code> | ||
interface=wlan0 | |||
listen-address=10.1.1.1 | listen-address=10.1.1.1 | ||
bind-interfaces | bind-interfaces | ||
server=8.8.8.8 | server=8.8.8.8 | ||
domain-needed | domain-needed | ||
bogus-priv | bogus-priv | ||
dhcp-range=10.1.1.50,10.1.1.250,12h | dhcp-range=10.1.1.50,10.1.1.250,12h | ||
For the purposes of the Frankenstein "hovel" bot, also uncomment: | For the purposes of the Frankenstein "hovel" bot, also uncomment: | ||
log-queries | |||
log-dhcp | log-dhcp | ||
Setup IPv4 forwarding. | Setup IPv4 forwarding. | ||
Line 87: | Line 85: | ||
Execute the following. | Execute the following. | ||
$ 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</code> | |||
$ sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT</code> | |||
$ sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"</code> | |||
To ensure the forwarding persists beyond restarts. | To ensure the forwarding persists beyond restarts. |
Revision as of 10:09, 14 July 2016
The scope of this article is the installation steps taken to produce a local area network using a RaspberryPi 3, running Raspbian Jessy Lite, with a bridged internet connection via an Ethernet cable to facilitate both the Hackers & Designers workshops around basic Unix and program skills for designers, and the Frankenstein Bot workshop by Constant.
Code blocks that begin with "$" denote terminal, command line instructions, all other code blocks denote configuration files and/or program source code.
In all locations where "vi" is used, feel free to use another text editor of your choice (ex. nano).
Setting up the network
These instructions are taken largely from here, but are reiterated in the case article disappears from the internet.
We need to tell dhcpcd to ignore the wlan0 interface.
$ sudo vi /etc/dhcpcd.conf
Add the following line to the bottom of the file:
denyinterfaces wlan0
wlan0 will need a static ip address.
$ sudo vi /etc/network/interfaces
The file should contain, everything else can be commented out or deleted:
auto lo iface lo inet loopback allow-hotplug eth0 iface eth0 inet dhcp allow-hotplug wlan0 iface wlan0 inet static address 10.1.1.1 netmask 255.255.255.0 network 10.1.1.0 broadcast 10.1.1.255
Install hostapd, and configure it.
$ sudo apt-get install hostapd
$ sudo vi /etc/hostapd/hostapd.conf
interface=wlan0 driver=nl80211 ssid=Hackers & Designers hw_mode=g channel=6 ieee80211n=1 wmm_enabled=1 ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] macaddr_acl=0 ignore_broadcast_ssid=0
$ sudo vi /etc/default/hostapd
Uncomment and set the following value:
DAEMON_CONF="/etc/hostapd/hostapd.conf
Install and configure dnsmasq.
$ sudo apt-get install dnsmasq
interface=wlan0 listen-address=10.1.1.1 bind-interfaces server=8.8.8.8 domain-needed bogus-priv dhcp-range=10.1.1.50,10.1.1.250,12h
For the purposes of the Frankenstein "hovel" bot, also uncomment:
log-queries log-dhcp
Setup IPv4 forwarding.
$ sudo vi /etc/sysctl.conf
Uncomment the following line.
net.ipv4.ip_forward=1
Execute the following.
$ 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 $ sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
To ensure the forwarding persists beyond restarts.
$ sudo vi /etc/rc.local
Add the following line before exit(0).
iptables-restore < /etc/iptables.ipv4.nat
Restart and verify the network is working.
$ sudo reboot