Last Updated: September 09, 2019
· benwah

Connect Raspberry PI on a wifi network via Ethernet, through your computer

I just spent a few hours figuring this out, so I thought it might be useful for other people, and serve as a reminder next time I need to do this.

Problem: You have a computer or laptop running Ubuntu that's connected to a Wifi network, and your Raspberry PI doesn't have a Wifi adapter to connect to the Wireless network, so you want to use your computer to act as a router for the Raspberry PI.

  • Set Raspberry PI's network interface to be configured by DHCP, on the raspberry PI, edit /etc/network/interfaces, mine looks like this:

# /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp


  • Edit /etc/network/interfaces on the computer running Ubuntu. The last line assumes that your wifi adapter connected to the wifi router is wlan0. Mine looks like this:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet static
        dns-search lan
        post-up /sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE


  • Install dns-masq on the computer running Ubuntu:

$ sudo apt-get install dnsmasq


  • If ubuntu firewall is enabled (ufw), allow port 53 for dhcp:

$ sudo ufw allow 53


  • Edit /etc/dnsmasq.conf, here are the lines I uncommented and modified, but honestly there might be some things that are wrong, it worked the first time so whatever:



Now connect your raspberry PI via Ethernet to your computer, ensure that computer is connected via Wifi, reboot your computer and your raspberry PI and voila! You should be online.

IMPORTANT NOTE! You don't know what IP address was assigned to your raspberry PI? You can check the DHCP lease:

$ cat /var/lib/misc/dnsmasq.leases


And you should see what IP address has been assigned to the Raspberry PI, you can also fuck around with DHCP settings to give it a static lease, or just disable DHCP alltogether and manually configure /etc/network/interfaces.

2 Responses
Add your response

This is a cool tip, but in Ubuntu you can achieve the same from the NetworkManager icon. Edit the Ethernet interface and set it to be Shared to other computers. instead of Automcatic (DHCP) or Manual, et voila!

over 1 year ago ·

I saw this was possible but (as far as i could see) it required to manually configure the raspberry PI's network interface and set its gateway to the IP address network manager decides Ubuntu should have. So next (Ubuntu) reboot your PI might lose connectivity and you'll have to plug in a keyboard and monitor to update its network configuration.

over 1 year ago ·