Skip to content

Instantly share code, notes, and snippets.

@vldmitrofanov
Last active June 10, 2023 21:05
Show Gist options
  • Save vldmitrofanov/7f76b1bc7b11ff37487282291e82bc09 to your computer and use it in GitHub Desktop.
Save vldmitrofanov/7f76b1bc7b11ff37487282291e82bc09 to your computer and use it in GitHub Desktop.
Setting up Raspberry Pi as WiFi adapter for non-wifi computer
#!/bin/bash
# Setting up raspberry as a WiFi access point
# make sure dnsmasq is already installed
echo 1 > /proc/sys/net/ipv4/ip_forward
ifconfig eth0 10.1.0.1 netmask 255.255.255.0
sudo ufw allow ssh
sudo ufw enable
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
echo "interface=eth0" > /etc/dnsmasq.conf
echo "bind-interfaces" >> /etc/dnsmasq.conf
echo "server=8.8.8.8" >> /etc/dnsmasq.conf
echo "domain-needed" >> /etc/dnsmasq.conf
echo "bogus-priv" >> /etc/dnsmasq.conf
echo "dhcp-range=10.1.0.2,10.1.0.100,12h" >> /etc/dnsmasq.conf
systemctl restart dnsmasq
ROUTE_CHECK=$(ip route show | grep -c 10.1.0.0)
if [ "$ROUTE_CHECK" -eq 0 ]; then
ip route add 10.1.0.0/24 dev eth0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment