install the following packages
sudo apt-get update
sudo apt-get install hostapd isc-dhcp-server iptables-persistent vim
Setup DHCP Server
sudo vim /etc/dhcp/dhcpd.conf
find lines that say
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
comment them out like below
# option domain-name "example.org";
# option domain-name-servers ns1.example.org, ns2.example.org;
find lines that say
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
and uncomment it out like below
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
then scroll to the bottom and add the following lines
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
save the file
sudo vim /etc/default/isc-dhcp-server
find the lines
INTERFACESv4=""
INTERFACESv6=""
modify it like below
INTERFACESv4="wlan0"
# INTERFACESv6=""
save the file
Setup wlan0 for Static IP
sudo vim /etc/network/interfaces
make it look like below
...
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
...
save the file
assign a static IP address to the WiFi adapter by running
sudo ifconfig wlan0 192.168.42.1
Configure Access Point
sudo vim /etc/hostapd/hostapd.conf
modify the ssid= and wpa_passphrase= as necessary
interface=wlan0
ssid=Pi_AP
country_code=US
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Raspberry
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1
save the file
sudo vim /etc/default/hostapd
find the line and replace like below
DAEMON_CONF="/etc/hostapd/hostapd.conf"
save the file
sudo vim /etc/init.d/hostapd
find the line and replace like below
DAEMON_CONF=/etc/hostapd/hostapd.conf
save the file
Configure Network Address Translation
Setup IP Forwarding
sudo vim /etc/sysctl.conf
scroll to bottom and add the following line (this would start IP forwarding on bootup)
net.ipv4.ip_forward=1
save the file
run the following command to activate it immediately
sudo sh -c “echo 1 > /proc/sys/net/ipv4/ip_forward”
Network Translation between ethernet port eth0 and the wifi adaptor wlan0
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
to check what’s in the iptables
sudo iptables -t nat -S
sudo iptables -S
to make this happen on reboot run:
sudo sh -c “iptables-save > /etc/iptables/rules.v4”
Finishing Up
start servers
sudo systemctl restart isc-dhcp-serversudo systemctl restart hostapd
check status of servers
sudo systemctl status isc-dhcp-server
sudo systemctl status hostapd