Raspberry Pi 2 Wifi Adapters

To do this we're going to use dnsmasq to set up the RPi to be a DHCP server and set up some custom DNS settings. This will allow the device connected to the RPi through ethernet to get an IP address from the RPi and also to for the RPi to pass DNS queries.

All the above Panda Wireless branded Adapters are plug and play on Linux Mint 18, Ubuntu 16.04 TLS, Fedora 24 and Raspberry Pi 1/2/3 running the latest Raspbian Wheezy and Jessie. Patriot Memory PCUSBW1150 Wireless 11N USB adapter (uses Realtek RTL8188CUS) Install using Micronet script. Setting up a Raspberry Pi as a WiFi access point Created by lady ada Last updated on 2018-08-22 03:36:03 PM UTC.

We'll also configure some iptables settings to make a NAT between the ethernet adapter and the Wifi connection.

First, install dnsmasq:

sudo apt-get install dnsmasq

Set your ethernet adapter to a static IP address

This will serve as a gateway for the device that you want to connect to the RPi ethernet port. Most Wifi routers use what's called a Private Network and set the IP range to something similar to:

192.168.1.1

For the ethernet adapter on your RPI you'll want to set that to an address that won't interfere with the routers ability to assign addresses, so we'll increment the subnet of the PRi to be:

192.168.2.1

Along with that you'll need to set up the the netmask to:

255.255.255.0

Raspberry pi 2 wifi

As well as the DCHP settings to broadcast what IP address are available:

network 192.168.2.0
broadcast 192.168.2.255


Raspberry Pi 2 Wifi Dongle

Raspberry Pi 2 Wifi Adapters

Use iptables to configure a NAT setting to share the Wifi connection with the ethernet port
NAT stands for Network Address Translation. This allows a single IP address to server as a router on a network. So in this case the ethernet adapter on the RPi will serve as the router for whatever device you attach to it. The NAT settings will route the ethernet requests through the Wifi connection.

There are several commands to run here:

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

Configure the dnsmasq settings

The first thing to do is to turn on IP forwarding. This is done by putting a single number 1 in the /proc/sys/net/ipv4/ip_forward file:

sudo nano /proc/sys/net/ipv4/ip_forward

Put a 1 on the first line and then exit and save. Hint: you also may have to edit /etc/sysctl.conf and uncomment this line:

net.ipv4.ip_forward=1

Raspberry

Next set up ip routing:

Raspberry Pi 2 Projects

sudo ip route del 0/0 dev eth0 &> /dev/null
a=`route | awk '/${wlan}/'{print $5+1;exit}'`
sudo route add -net default gw 192.168.2.1 netmask 0.0.0.0 dev eth0 metric $a

The last thing to do is edit your /etc/dnsmasq.conf file and include these settings;

interface=eth0
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.2.2,192.168.2.100,12h

Raspberry Pi 2 Wifi Setup

Then run this command to start your dnsmasq services:

sudo systemctl start dnsmasq

Raspberry Pi Usb Wifi

Now plug a CAT5 network cable into the device you want to include on the network and put the other end of the cable into the ethernet port on the RPi and you should be good to go! When we set up the ethernet interface we made it hot pluggable, so you should see the ethernet interface come up when you plug the device into the RPi.