From charlesreid1

Making the Raspberry Pi into a wireless router



installing software

first install a daemon for taking care of access point and authentication server details:

$ apt-get install hostapd

then install a dhcp server:

$ apt-get install isc-dhcp-server

dhcp config

edit the file /etc/dhcp/dhcp.conf:

remove the lines

# ------------------------------------
# option definitions common to all supported networks...
##### option domain-name "";
##### option domain-name-servers,;
# ------------------------------------

change the line:

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

add the lines:

# Next we need to define the network and network addresses
# that the DHCP server will be serving. This is done by adding
# the following block of configuration to the end of file:

subnet netmask {
    option broadcast-address;
    option routers;
    default-lease-time 600;
    max-lease-time 7200;
    option domain-name "local-network";
    option domain-name-servers,;

isc dhcp server config

we just set some general, system-wide dhcp settings, so now we set things specific to the isc-dhcp-server software we'll be using to create a dhcp server.

edit the file /etc/default/isc-dhcp-server

change the following line:

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".

static ip in network config

finally, edit the network configuration for the pi to give it a static ip address (since it will be defining its own private network, it hands out its own ip addresses, so it needs an address.)

start by taking your wireless card down:

$ ifconfig wlan0 down

now edit the file /etc/network/interfaces and add:

iface wlan0 inet static

hostapd config

Now configure hostapd:

edit the file /etc/hostapd/hostapd.conf

standard config creates a new wireless network called wifi with password YourPassPhrase. Change parameter "ssid=wifi" to your desired wireless network name, change parameter "wpa_passphrase=YourPassword" to set a wpa2 passphrase.

$ cat /etc/hostapd/hostapd.conf

setup NAT network address translation

Next is setting up NAT, edit /etc/sysctl.conf

add the line


start the NAT translation:

sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

fire up the wifi card

ifconfig wlan0 up

ip table rules

set up a few iptables rules that will allow you to forward packets from the wlan0 interface to the eth0 interface. run these commands on the command line:

$ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
$ iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
$ iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

fire it up

now you're ready to fire this thing up. run the dhcp server:

$ service isc-dhcp-server start


Mar 04 23:43:44 kali dhcpd[1549]: No subnet declaration for wlan0 (no IPv4 addresses).
Mar 04 23:43:44 kali dhcpd[1549]: ** Ignoring requests on wlan0.  If this is not what
Mar 04 23:43:44 kali dhcpd[1549]: you want, please write a subnet declaration
Mar 04 23:43:44 kali dhcpd[1549]: in your dhcpd.conf file for the network segment
Mar 04 23:43:46 kali isc-dhcp-server[1540]: Starting ISC DHCP server: dhcpdcheck syslog for diagnostics. ... failed!
Mar 04 23:43:46 kali isc-dhcp-server[1540]: failed!
Mar 04 23:43:46 kali systemd[1]: isc-dhcp-server.service: control process exited, code=exited status=1
Mar 04 23:43:46 kali systemd[1]: Failed to start LSB: DHCP server.
Mar 04 23:43:46 kali systemd[1]: Unit isc-dhcp-server.service entered failed state.

resolved by fixing typo in /etc/network/interfaces


Even when I got it all running with no problems, I'm left without a working wireless network.

abandon ship



Useful links: