Raspberry Pi 3 Raspbian hotspot sharing wired Internet connection wirelessly

Want to use Raspberry Pi as hotspot access point?

The following tested and verified  on Raspbian Jessie.

1. Install dnsmasq and hostapd:

  • sudo apt-get install dnsmasq hostapd

2. Ensure your wlan0 is enabled

  • sudo nano /etc/network/interfaces

allow-hotplug wlan0

iface wlan0 inet manual

  • sudo nano /etc/dhcpcd.conf

3. Give your wlan0 static IP.

  • sudo nano /etc/dhcpcd.conf

interface wlan0

static ip_address=192.168.4.1/24

static routers=192.68.4.1

static domain_name_servers=192.168.1.1 8.8.8.8 #point it to your Internet router and use free Google DNS

4. Configure hostapd.

  • sudo nano /etc/hostapd/hostapd.conf
  • copy the following

driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
auth_algs=1
wpa_key_mgmt=WPA-PSK
beacon_int=100
ssid=RPiHotSpot
channel=1
hw_mode=g
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
wpa_passphrase=susususu
interface=wlan0
wpa=2
wpa_pairwise=TKIP CCMP
country_code=AF
ignore_broadcast_ssid=0

5. Give your client appropriate IP addresses

  • sudo nano /etc/dnsmasq.conf

interface=wlan0 # Use interface wlan0
bind-dynamic # Bind to the interface to make sure we aren’t sending things$
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=192.168.4.100,192.168.4.110,12h # Assign IP addresses between 172.24$

6. Now reboot. You should be able to connect to your new wifi hotspot: RPiHotSpot

password: susususu

7. Try ssh into it:

  • ssh pi@192.168.4.1

Now you can share internet connection off your eth0 port.

8. Enable IP Forwarding.

  • sudo nano /etc/sysctl
  • uncomment this line: net.ipv4.ip_forward=1

9. Firewall and routing setup:

  • 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”
  • Enable after each boot, load it:
    • sudo nano /etc/rc.local
    • iptables-restore < /etc/iptables.ipv4.nat

10. Start evertyhing:

  • sudo service dhcpd start
  • sudo service hostapd start
  • sudo service dnsmasq start
  • sudo reboot now

 

(Visited 230 times, 1 visits today)