Skip to content

Instantly share code, notes, and snippets.

@notdodo
Created February 7, 2018 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notdodo/a884112afdd01ae15418e64d954bad88 to your computer and use it in GitHub Desktop.
Save notdodo/a884112afdd01ae15418e64d954bad88 to your computer and use it in GitHub Desktop.
Share WIFI network with a wired device (i.e.: RaspberryPI) using dnsmasq
#!/usr/bin/env zsh
INTERFACE_WIRED="enp6s0"
INTERFACE_INTERNET="wlp2s0"
sudo ip addr add 192.168.2.1/24 dev ${INTERFACE_WIRED}
# NAT
sudo iptables -A FORWARD -o eth0 -i ${INTERFACE_WIRED} -s 192.168.2.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -F POSTROUTING
sudo iptables -t nat -A POSTROUTING -o ${INTERFACE_INTERNET} -j MASQUERADE
sudo sysctl -w net.ipv4.ip_forward=1
# Example
# interface=enp6s0
# dhcp-range=192.168.2.10,192.168.2.11,1h
sudo $EDITOR /etc/dnsmasq.conf
sudo systemctl restart dnsmasq; sudo systemctl status dnsmasq
cat /var/lib/misc/dnsmasq.leases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment