Sunday, July 8, 2018

Configuring Raspberry PI as your Ethernet router

Configure your WiFi
  • sudo raspi-config
  • select "2 Network Options      Configure network settings"
  • then select "N2 Wi-fi                   Enter SSID and passphrase"
  • enter your access point and password
  • you are done
 
 
Install a lightweight network (DHCP, DNS) infrastructure 
  • sudo apt-get install dnsmasq

Stop the service until we configure if fully 
  • sudo systemctl stop dnsmasq
 
Configure Static WiFi for dhcp client
  • sudo vi /etc/dhcpcd.conf
     
Type the following statements
  • interface eth0
  • static ip_address=192.168.10.1/24
  • static domain_name_servers=192.168.0.1 8.8.8.8
 
Restart the dhcp client daemon
  • sudo service dhcpcd restart
 
Let us configure the dhcp server
  • sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig 
  • sudo vi /etc/dnsmasq.conf
 
type the following 
  • interface=eth0
  • dhcp-range=192.168.10.2,192.168.10.20,255.255.255.0,24h
 
 
Add a Routing and Masqueraed 
  • Edit /etc/sysctl.conf and uncomment this line:
    • net.ipv4.ip_forward=1
       
  • Add a masquerade for outbound traffic on wlan0:
    • sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE 
  • Save the iptables rule.
    • sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
  • Edit /etc/rc.local and add this just above "exit 0" to install these rules on boot.
    • iptables-restore < /etc/iptables.ipv4.nat
 
 
 
Reboot
 
Your raspberrypi is now ready as a WiFi ==> Ethernet router