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.

Enter the following to get gateway/interface information

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.

Remove/comment the line that reads

Add the following lines

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

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

Save the file by pressing CTRL-X and select Y to save the changes.

You can now restart your network by issuing this command.

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.