Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active November 24, 2021 21:22
Show Gist options
  • Save miguelmota/8201618 to your computer and use it in GitHub Desktop.
Save miguelmota/8201618 to your computer and use it in GitHub Desktop.
Raspberry Pi Raspbian OS wifi interface settings.
# vim /etc/network/interfaces
#
# it would be a good idea to update before:
#
# sudo apt-get update
# sudo apt-get upgrade
# sudo rpi-update
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
nameserver 127.0.0.1
wpa-ssid "MyNetworkName"
wpa-psk "secretpassword"
# using wpa_supplicant (recommended)
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
allow-hotplug wlan0
auto wlan0
#iface wlan0 inet manual
iface wlan0 inet dhcp
wpa-ssid "MyNetworkName"
wpa-psk "secretpassword"
auto lo
iface lo inet loopback
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.222
netmask 255.255.255.0
gateway 192.168.0.1
broadcast 192.168.0.255
dns-nameservers 192.168.0.1
wpa-ssid "myhomenetwork"
wpa-psk "mysharedkey"
You can verify whether it has successfully connected using `ifconfig wlan0`.
If the inet addr field has an address beside it, the Raspberry Pi has connected to the network.
If not, check your password and ESSID are correct.
If you have two networks in range, you can add the priority option to choose between them. The network in range, with the highest priority, will be the one that is connected.
# selet network based on higher priority number
network={
ssid="MyNetworkName"
psk="secretpassword"
id_str="location1"
priority=1
}
# scan_ssid connects to hidden ssid, however it ignores priority and prioritizes based on order.
# set value to 1 if you are trying to connect to hidden network or if you have more than one wireless access point; each with different ssid (suggest you enter value of 1)
# alternatively, set value of 0 will do the opposite of value 1 (for home networks that broadcasts ssid)
network={
ssid="WIFI SSID"
psk="WIFI PASSWORD"
id_str="location2"
priority=2
scan_ssid=1
}
# add to bottom of list; connect to any open wifi
network={
key_mgmt=NONE
priority=-999
}
# reload wifi
ifdown --force wlan0
ifup wlan0
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid="MyNetworkName"
psk="secretpassword"
key_mgmt=WPA-PSK
}
@pantasio
Copy link

You save my day. Thank you
For newbie: This's note is applied to wpa_supplicant.conf
Some info: https://raspberrypi.stackexchange.com/questions/37920/how-do-i-set-up-networking-wifi-static-ip-address-on-raspbian-raspberry-pi-os/37921#37921

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment