Access & Share the internet from laptop to raspberry pi

Access & Share the internet from laptop to raspberry pi

The Raspberry Pi is automatically set to obtain an IP address from your wired or wireless network. Why does the Raspberry Pi need an IP address? This address is needed so that any traffic destined for your Raspberry Pi will be able to find it on the network.
This is method of obtaining an IP address is called DHCP or Dynamic Host Configuration Protocol. It is sometimes referred to as a dynamic IP. Your router will normally distribute these IP addresses but it isn’t guaranteed that it will get the same IP address every time. This can cause problems if you are trying to connect to your Raspberry Pi remotely.
To get the IP address, enter the following command to retrieve your existing IP address and network information.

sudo ifconfig

Enter the following to get gateway/interface information

sudo route -nee

So how do you set a static IP address?
Two steps are requried. You would have to setup network on laptop and also on raspberry.
Laptop Configuration
Change the IP address to static for your Ethernet connection by which your raspberry pi is connected.

WiFi should be connected to the internet.
Open the WiFi connection properties and go into second tab “Sharing”. Check “Allow other network users to through this computer’s internet connection”. Select Ethernet from drop-down.
Raspberry Pi
You need to edit the interfaces file to set this static information.

sudo nano /etc/network/interfaces

Remove/comment the line that reads

# The line below is referring to the eth0 interface and that is should use DHCP.
# iface eth0 inet dhcp

Add the following lines

# eth0 is assigned static and now it would not assign ip automatically.
iface eth0 inet static
#Static IP address of the local machine
# It is called a subnet mask because it is used to identify network address of an IP address by perfoming a bitwise AND operation on the netmask.
# This the network on which we are about to connect.
# Broadcasting sends a message to everyone on the network
#This is the IP address of the laptop. We have assigned the Ethernet a static IP which is as follow.
# This is optional, we have specified opendns IP.

You can additionally add usb WiFi dongle and connect to a network.

iface eth0 inet dhcp
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-ssid "WIFI_SSID_NAME"

You can scan WiFi networks by issuing this command and replace the ESSID in the above configuration “wpa-ssid”.

sudo iwlist wlan0 scan

Save the file by pressing CTRL-X and select Y to save the changes.
You can now restart your network by issuing this command.

service networking restart

You can ping from the laptop to check if raspberry pi is accessible via laptop.


You can also connect via putty to check, if that IP address is accessible.

Share this post