How to setup Static IP on Raspberry Pi 3 Video Tutorial 2017. This tutorial including a video will configure static IP for Ethernet as well as Wifi interface on Raspberry Pi 3 while maintaining the internet connection.
You can watch the Video: How to set static IP address on Raspberry Pi 3
You can choose from two methods in this tutorial in configuring a static IP for Ethernet and Wifi interface. In this tutorial, I will set Ethernet IP as 192.168.2.200 and Wifi as 192.168.2.201
Connect Raspberry Pi to the router using Ethernet cable. Connect your computer on the same network. We need to get some information about your network so run cmd
On Command prompt type ipconfig /all
From this image, my network is around 192.168.2.x We need to take note of the default gateway and DNS servers In this example we get: Default Gateway: 192.168.2.1 DNS Servers: 192.168.2.1 On your computer, Open Putty and type in the address: rasberrypi.local and click open
Let it use the default configuration
Edit DHCPCD
Enter this code below
Ensure both service are enabled
Reboot the system
Login again and test your internet
Paste this code:
Check DHCPCD
You can leave your configuration, we will disable the service anyway Disable DHCPCD
Only Networking will be used
Reboot the system
Login again and test your internet
You can watch the Video: How to set static IP address on Raspberry Pi 3
You can choose from two methods in this tutorial in configuring a static IP for Ethernet and Wifi interface. In this tutorial, I will set Ethernet IP as 192.168.2.200 and Wifi as 192.168.2.201
Connect Raspberry Pi to the router using Ethernet cable. Connect your computer on the same network. We need to get some information about your network so run cmd
On Command prompt type ipconfig /all
From this image, my network is around 192.168.2.x We need to take note of the default gateway and DNS servers In this example we get: Default Gateway: 192.168.2.1 DNS Servers: 192.168.2.1 On your computer, Open Putty and type in the address: rasberrypi.local and click open
Network information gathering
Once you have logged in, check your Raspberry pi network. Type this command:ifconfig
The Raspberry Pi is on the same network 192.168.2.x
Let's proceed to configure static IP Address. You can choose from the two method on doing that
Method 1: DHCPCD
Edit Network interfacesudo nano /etc/network/interfaces
Let it use the default configuration
auto eth0
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Edit DHCPCD
sudo nano /etc/dhcpcd.conf
Enter this code below
interface eth0
static ip_address=192.168.2.200/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1
interface wlan0
static ip_address=192.168.2.201/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1
Ensure both service are enabled
sudo systemctl enable dhcpcd
sudo systemctl enable networking
Reboot the system
sudo reboot
Login again and test your internet
sudo apt-get update
Method 2: NETWORK INTERFACE
Edit network interfacessudo nano /etc/network/interfaces
Paste this code:
auto eth0
iface eth0 inet static
address 192.168.2.200
netmask 255.255.255.0
gateway 192.168.2.1
dns-nameservers 192.168.2.1
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.2.201
netmask 255.255.255.0
gateway 192.168.2.1
dns-nameservers 192.168.2.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Check DHCPCD
sudo nano /etc/dhcpcd.conf
You can leave your configuration, we will disable the service anyway Disable DHCPCD
sudo systemctl disable dhcpcd
Only Networking will be used
sudo systemctl enable networking
Reboot the system
sudo reboot
Login again and test your internet
sudo apt-get update
How to SSH to a Virtualbox through NAT configuration. Using NAT as your Virtualbox network connection will create a private network connected to your host network. The only way to have direct access is to port forward any traffic to port 22 of your Virtual Machine. Please follow this step:
- Start your virtual machine and login
- Get the IP address by typing ifconfig
- Poweroff your machine
- Go to settings >> Network >> Advance >> Port Forwarding
- Add new port forwarding rule
- Host IP : 127.0.0.1
- Host Port: 2222
- Guest IP: [IP of your virtual machine]
- Guest Port: 22
Raspberry Pi Auto login using SSH. Getting tired of entering the username and password when using Putty. Here is a quick tutorial on how to configure your Raspberry Pi and Putty to access the terminal without the use of username and password. Its a secure login process using SSH.
Please watch this tutorial video
What you need:
2. Move your mouse randomly over the blank area till the progress bar finish.
3. [Optional] Once key is generated, under the key comment textbox, add any word you like. Its recommended for you to remember what this key is about.
4. Protect your SSH key by adding a password or any word you’d like under Key passphrase and confirm passphrase. This will serve as your password to the SSH key so please remember it.
5. Click Save Public and Private key to your local drive.
6. For the benefit of many, lets close the Key Generator.
You can still reopen the generated key by loading the private key.
1. Open Putty Key Generator and click Load button
2. Locate the private key file from the folder you saved it. It will require you to enter your passphrase
3. Under Public key for pasting… you’ll see characters starting from ‘ssh-rsa’. This is the key that we will copy later.
1. On Host name, enter your Raspberry Pi hostname. Default is raspberrypi.local
2. On Saved Sessions, enter any name you want for this session
3. Click Save and Open and login again. We’re not done yet.
Ensure that you are in the user home directory
Create .ssh Directory and restrict permission
Create authorized_keys file and edit
Back to Putty Key Generator. Under Public key for pasting… you’ll see characters starting from ‘ssh-rsa’. Copy this key. Right click in the middle of it and click select all then right click again and click copy
On Putty console, paste the key. Right click in the middle of the console and the key will be pasted. Be careful not to type any thing as it will not work.
Save it by pressing ctrl+o and ctrl+x to exit
Restrict the permissions of the authorized_keys file
Close Putty console.
2. Click Session under the Category and Click Save Button
3. Click Open. It should login automatically.
Please watch this tutorial video
What you need:
Putty
Putty Key Generator
Peagent
Generate SSH key
1. Run Putty Key Generator and click Generate2. Move your mouse randomly over the blank area till the progress bar finish.
3. [Optional] Once key is generated, under the key comment textbox, add any word you like. Its recommended for you to remember what this key is about.
4. Protect your SSH key by adding a password or any word you’d like under Key passphrase and confirm passphrase. This will serve as your password to the SSH key so please remember it.
5. Click Save Public and Private key to your local drive.
6. For the benefit of many, lets close the Key Generator.
You can still reopen the generated key by loading the private key.
1. Open Putty Key Generator and click Load button
2. Locate the private key file from the folder you saved it. It will require you to enter your passphrase
3. Under Public key for pasting… you’ll see characters starting from ‘ssh-rsa’. This is the key that we will copy later.
Applying SSH key to your Rasberry Pi
Set your Putty to connect to Raspberry Pi
1. On Host name, enter your Raspberry Pi hostname. Default is raspberrypi.local
2. On Saved Sessions, enter any name you want for this session
3. Click Save and Open and login again. We’re not done yet.
Add the public key to the pi user
On the putty consoleEnsure that you are in the user home directory
cd
Create .ssh Directory and restrict permission
mkdir .ssh chmod 700 .ssh
Create authorized_keys file and edit
nano .ssh/authorized_keys
Back to Putty Key Generator. Under Public key for pasting… you’ll see characters starting from ‘ssh-rsa’. Copy this key. Right click in the middle of it and click select all then right click again and click copy
On Putty console, paste the key. Right click in the middle of the console and the key will be pasted. Be careful not to type any thing as it will not work.
Save it by pressing ctrl+o and ctrl+x to exit
Restrict the permissions of the authorized_keys file
chmod 600 .ssh/authorized_keys
Close Putty console.
Using Pageant
Run Peagent. On your systemtray, you can see Peagent. Click it, add Key and locate the folder where you save your Private SSH key. Enter your Key passphraseLast configuration for Putty
1. On Putty, left side under Category list, click Data. Enter the Username (pi) on Auto-login username2. Click Session under the Category and Click Save Button
3. Click Open. It should login automatically.
Please remember that auto-login will only work if Peagent is running and private key is added to it.
Reference
How to share Windows internet to Raspberry Pi through Ethernet port. In this tutorial you'll learn how to share your Laptop's internet to Raspberry Pi using an Ethernet cable.
Share your Laptop's wifi internet
Open Putty and type the hostname of your Raspberry Pi and add .local at the end. In my RasPi its raspberrypi.local
Login to your raspberry pi using the details below:
Finally, check if it has internet connection:
End of tutorial
Kyle Abad
What you need:
Ethernet cable
Ensure your Raspberry pi Ethernet has no Static IP
Step 1: Find Raspberry Pi Hostname
The default hostname is raspberrypi. The complete name will be raspberrypi.localhostname
Step 2: Configure your Laptop
Go to your Laptop and open Network Connections and ensure your Ethernet adapter set to automatically obtain IP AddressShare your Laptop's wifi internet
Step 3: Connect to Raspberry Pi using Putty
Plug the Ethernet cable to your Laptop and the other end is to your Raspberry Pi Ethernet portOpen Putty and type the hostname of your Raspberry Pi and add .local at the end. In my RasPi its raspberrypi.local
Login to your raspberry pi using the details below:
Username: pi Password: raspberry
Finally, check if it has internet connection:
sudo apt-get update
End of tutorial
Kyle Abad
How to share your iPhone's internet to your local network (LAN) using a Raspberry Pi. This project will make your Raspberry Pi your personalized home router that shares your iPhone internet (or any mobile device) to your Home Network so your Smart TV, Apple TV, Laptop and other devices can connect to the internet by wireless or by Ethernet cable.
About my Raspberry Pi:
To do this, open your terminal and type:
Open interfaces by typing:
and add this code on the last:
STEP 2: CONFIGURING DHCP service (dnsmasq)
About my Raspberry Pi:
What you'll need:
- Raspberry Pi 3
- Noobs updated
- Raspberry Pi with NOOBS loaded
- iPhone hotspot name and password
- Ethernet cable
- Putty
Step 1: Configure the Ethernet Interface
We have to assign a static IP 192.168.1.1 for Raspberry Pi Ethernet adapter.To do this, open your terminal and type:
Add this on the last linesudo nano /etc/dhcpcd.conf
Save and exit (Press ctrl + o to save and ctrl +x to exit)denyinterfaces eth0
Open interfaces by typing:
sudo nano /etc/network/interfaces
and add this code on the last:
Save and exitauto eth0 allow-hotplug eth0 iface eth0 inet static address 192.168.1.1 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255
STEP 2: CONFIGURING DHCP service (dnsmasq)
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig sudo nano /etc/dnsmasq.conf
Add this code
Save and exitinterface=eth0 listen-address=192.168.1.1 dhcp-range=192.168.1.50,192.168.1.100,12h server=8.8.8.8 bind-interfaces domain-needed bogus-priv
Reboot your device
sudo reboot
USING PUTTY TO CONFIGURE RASPBERRY
Ensure your Laptop Ethernet adapter setting is set to auto obtain IP address. Plug your Ethernet cable to your Raspberry Pi and the other end to your Laptop Ethernet port. Your Laptop should get IP address assigned by your Raspberry.
Now open Putty and type 192.168.1.1(Raspberry Pi IP Address) in Host Name, type any name you like in Save Sessions, click Save and finally click Open.
It will ask you a username and password every time you log in to Raspberry. Use the details below:
Username: pi Password: raspberry
From here we will use Putty to configure the Raspberry Pi
STEP 3: Configuring Wifi interface
In this step, we will configure the Wifi setting for the Raspberry to be able to connect to a wifi network.
sudo nano /etc/network/interfaces
Useful tip: You can just copy codes from your browser and paste it to putty by pressing right click of your mouse inside the putty window.
Paste this code at the end of the line.
Save and exitauto wlan0 allow-hotplug wlan0 iface wlan0 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Set the Wifi password
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Paste this code and edit the ssid (iPhone hotspot name) and psk (wifi password)
Save and exitctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=GB network={ ssid="***iPhone hotspot name***" psk="***Wifi password**" key_mgmt=WPA-PSK }
Reboot your Raspberry pi
sudo reboot
Check if your Wifi is connected and has internet connection
If it download and update, it means you have internetsudo apt-get update
STEP 4: SHARING THE INTERNET
We have to forward the internet connection we got from Wifi to the Ethernet port where our laptop is connected.Setup IPv4 Forwarding:
sudo nano /etc/sysctl.conf
Un-comment this line by removing #
And lets activate itnet.ipv4.ip_forward=1
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Lets reset the IP table. Write a script in a file named tablereset.sh
nano tablereset.sh
Paste this code:
Save and exit#!/bin/sh echo "Resetting the IP Tables" ipt="/sbin/iptables" ## Failsafe - die if /sbin/iptables not found [ ! -x "$ipt" ] && { echo "$0: \"${ipt}\" command not found."; exit 1; } $ipt -P INPUT ACCEPT $ipt -P FORWARD ACCEPT $ipt -P OUTPUT ACCEPT $ipt -F $ipt -X $ipt -t nat -F $ipt -t nat -X $ipt -t mangle -F $ipt -t mangle -X $ipt -t raw -F $ipt -t raw -X
And run the script
sudo sh tablereset.sh
Add firewall rules, paste the code below one at a time:
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
Check the changes we made:
sudo iptables -L -n -v
Save the rules we made
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Lets make this rules loaded automatically every time the system reboot.
sudo nano /etc/rc.local
Paste this code before "exit 0"
Let check the Firewall setting:Save and exitiptables-restore < /etc/iptables.ipv4.nat
Here is the Routing table in my Raspberryroute
pi@raspberrypi:~ $ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 172.20.10.1 0.0.0.0 UG 303 0 0 wlan0 172.20.10.0 * 255.255.255.240 U 303 0 0 wlan0 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
Let check if this works. Ensure your Raspberry pi is connected to your laptop Ethernet port and Raspberry pi is connected to your iPhone Hotspot. Disconnect your laptop from any Wifi connection. Then browse any website and see if it works.
Step 5: Configuring your router
Your router maybe different from mine. This step don't cover much details. But two thing you must do to your router:1. Dhcp should be disabled
2. It should not have IP the same as your Raspberry Pi.
If Raspberry Pi and Router has the same IP address (192.168.1.1), it is conflict and will not work. Also only one Dhcp service should run in the network. So ensure the router has no Dhcp running. Remember we configured the Raspberry Pi Dhcp service.
Once all are configure and checked, devices connected through Ethernet cable or through wifi should work.
-Mylinuxcode
Share your Raspberry Pi internet from Wifi to Ethernet Adapter. This project will make Raspberry Pi your personalized router. It translate the internet connection you get from maybe hotel's internet to your home network.
About my Raspberry Pi:
To do this, open your terminal and type:
Open interfaces by typing:
and add this code on the last:
STEP 2: CONFIGURING DHCP service (dnsmasq)
About my Raspberry Pi:
What you'll need:
- Raspberry Pi 3
- Noobs updated
- Wifi name and password
- Ethernet cable
- Putty
Step 1: Configure the Ethernet Interface
We have to assign a static IP 192.168.1.1 for Raspberry Pi Ethernet adapter.To do this, open your terminal and type:
Add this on the last linesudo nano /etc/dhcpcd.conf
Save and exit (Press ctrl + o to save and ctrl +x to exit)denyinterfaces eth0
Open interfaces by typing:
sudo nano /etc/network/interfaces
and add this code on the last:
Save and exitauto eth0 allow-hotplug eth0 iface eth0 inet static address 192.168.1.1 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255
STEP 2: CONFIGURING DHCP service (dnsmasq)
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig sudo nano /etc/dnsmasq.conf
Add this code
Save and exitinterface=eth0 listen-address=192.168.1.1 dhcp-range=192.168.1.50,192.168.1.100,12h server=8.8.8.8 bind-interfaces domain-needed bogus-priv
Reboot your device
sudo reboot
USING PUTTY TO CONFIGURE RASPBERRY
Ensure your Laptop Ethernet adapter setting is set to auto obtain IP address. Plug your Ethernet cable to your Raspberry Pi and the other end to your Laptop Ethernet port. Your Laptop should get IP address assigned by your Raspberry.
Now open Putty and type 192.168.1.1(Raspberry Pi IP Address) in Host Name, type any name you like in Save Sessions, click Save and finally click Open.
It will ask you a username and password every time you log in to Raspberry. Use the details below:
Username: pi Password: raspberry
From here we will use Putty to configure the Raspberry Pi
STEP 3: Configuring Wifi interface
In this step, we will configure the Wifi setting for the Raspberry to be able to connect to a wifi network.
sudo nano /etc/network/interfaces
Useful tip: You can just copy codes from your browser and paste it to putty by pressing right click of your mouse inside the putty window.
Paste this code at the end of the line.
Save and exitauto wlan0 allow-hotplug wlan0 iface wlan0 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Set the Wifi password
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Paste this code and edit the ssid (wifi name) and psk (wifi password)
Save and exitctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=GB network={ ssid="***HERE IS YOUR WIFI ID***" psk="***HERE IS THE WIFI PASSWORD**" key_mgmt=WPA-PSK }
Reboot your Raspberry pi
sudo reboot
Check if your Wifi is connected and has internet connection
If it download and update, it means you have internetsudo apt-get update
STEP 4: SHARING THE INTERNET
We have to forward the internet connection we got from Wifi to the Ethernet port where our laptop is connected.Setup IPv4 Forwarding:
sudo nano /etc/sysctl.conf
Un-comment this line by removing #
And lets activate itnet.ipv4.ip_forward=1
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Lets reset the IP table. Write a script in a file named tablereset.sh
nano tablereset.sh
Paste this code:
Save and exit#!/bin/sh echo "Resetting the IP Tables" ipt="/sbin/iptables" ## Failsafe - die if /sbin/iptables not found [ ! -x "$ipt" ] && { echo "$0: \"${ipt}\" command not found."; exit 1; } $ipt -P INPUT ACCEPT $ipt -P FORWARD ACCEPT $ipt -P OUTPUT ACCEPT $ipt -F $ipt -X $ipt -t nat -F $ipt -t nat -X $ipt -t mangle -F $ipt -t mangle -X $ipt -t raw -F $ipt -t raw -X
And run the script
sudo sh tablereset.sh
Add firewall rules, paste the code below one at a time:
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
Check the changes we made:
sudo iptables -L -n -v
Save the rules we made
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Lets make this rules loaded automatically every time the system reboot.
sudo nano /etc/rc.local
Paste this code before "exit 0"
Let check the Firewall setting:Save and exitiptables-restore < /etc/iptables.ipv4.nat
Here is the Routing table in my Raspberryroute
pi@raspberrypi:~ $ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.2.1 0.0.0.0 UG 304 0 0 wlan1 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 304 0 0 wlan1
Let check if this works. Ensure your Raspberry pi is connected to your laptop Ethernet port and Raspberry pi is connected to a Wifi that has internet. Disconnect your laptop from any Wifi connection. Then browse any website and see if it works.
If you plan to connect your Rapsberry Pi Ethernet to a router, please consider these two important points:
- The Router IP address should not be 192.168.1.1
- The Router Dhcp service should be disabled
How to install Raspberry Pi operating system Noobs. In this tutorial, we will going to use a Windows 7 computer. You can also watch the video of this tutorial.
What you'll need:
- Noobs image (operating system). You can download here
- SD Card Formatter software.
Step 1:
Download the Noobs image from their website. Later at step 4, you have to extract this file, copy and paste all extracted files on your SD card.
Step 2:
Download the SD Card Formatter and install it to your computer. Run the software after installation.
Insert your SD card in your computer. Select the drive letter of your SD card. Remember, this process will wipe out your SD card files. Once ready, click format button.
Step 4:
Extract the Noobs image file. Copy all the extracted files (shown below image) and paste it all on your SD card (root directory).
Step 5:
Remove your SD card from your computer and insert it in your Raspberry Pi. Please ensure that you have a good power supply for Raspberry. The device require 5 volts with 1amps or more (2amps is recommended.) Use a high quality usb cable in order for your Raspberry pi works properly. Tablet chargers are good choice. Plug your usb charger to power up the raspberry pi.
This screen shows your raspberry and sd card works. |
Select or tick the Raspbian and click Install |
Click yes to proceed the installation. This may took more than 8 minutes of installation |
Click Ok and the system will restart |
This is your Raspberry pi Noobs desktop environment |
Step 6:
Update your system by pressing ctrl+alt+t to open the Terminal. Type the following command
sudo apt-get update sudo apt-get upgrade
Congratulation! You have your Raspberry Pi with NOOBS desktop environment.
Open your Terminal by pressing ctrl+alt+t
Copy this code and paste on the terminal
Copy this code and paste on the terminal
sudo apt-get update && sudo apt-get install rar unrar
Add User and Grant Root Privileges on Ubuntu. This tutorial we will learn how to Add user and grant root privileges so you could send command like a root user. Before starting, you should be logged as root user.
Add a user
It will prompt you to enter the user details. Its optional. You can press [enter] till the last to skip Grant root privilege to demo useradduser demo
Find the following code and paste the 3rd linevisudo
Save the changes by pressing ctrl+o and exit ctrl+x You can now run command as root by using the command sudo following the command. Example :# User privilege specification root ALL=(ALL:ALL) ALL demo ALL=(ALL:ALL) ALL
sudo chmod 777 test_folder sudo visudo
Subscribe to:
Posts (Atom)