Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.