Access & Share the internet from laptop to raspberry pizalam
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
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.
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.
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 address 192.168.111.222 # 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. netmask 255.255.255.0 # This the network on which we are about to connect. network 192.168.111.0 # Broadcasting sends a message to everyone on the network broadcast 192.168.111.255 #This is the IP address of the laptop. We have assigned the Ethernet a static IP which is as follow. gateway 192.168.111.1 # This is optional, we have specified opendns IP. dns 126.96.36.199
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" wpa-psk "WIFI_PASSWORD"
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.