Linux/Wireless: Difference between revisions
From charlesreid1
| Line 54: | Line 54: | ||
This method uses wpa_supplicant, and has been tested and works on a Rasbperry Pi. | This method uses wpa_supplicant, and has been tested and works on a Rasbperry Pi. | ||
===Set wireless network configuration=== | |||
First add network configuration to <code>/etc/wpa_supplicant/wpa_supplicant.conf</code> | First add network configuration to <code>/etc/wpa_supplicant/wpa_supplicant.conf</code> | ||
| Line 75: | Line 77: | ||
<pre> | <pre> | ||
# ------- DHCP ------------ | # ------- DHCP ------------ | ||
iface wlan0 inet manual | iface wlan0 inet manual | ||
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf | wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf | ||
iface default inet dhcp | iface default inet dhcp | ||
</pre> | |||
===Reset network device=== | |||
Bring network device down and back up: | |||
<pre> | |||
ifdown wlan0 | |||
ifup wlan0 | |||
</pre> | |||
You should see the wireless network you specified in your wpa supplicant file when you run iwconfig: | |||
<pre> | |||
iwconfig | |||
</pre> | |||
You should also see an IP address when you run ifconfig: | |||
<pre> | |||
ifconfig | |||
</pre> | |||
To start wpa_supplicant manually: | |||
<pre> | |||
# sudo /sbin/wpa_supplicant \ | |||
-i wlan0 \ | |||
-P /var/run/wpa_supplicant.wlan0.pid \ | |||
-D nl80211,wext -c /etc/wpa_supplicant/wpa_supplicant.conf | |||
</pre> | </pre> | ||
Revision as of 06:24, 15 April 2017
This page covers methods of connecting to wifi from Linux.
The methods break down as follows:
- Use
/etc/network/interfaces - Use wpa supplicant
- How to connect to encrypted vs. unencrypted wifi
Joining Wireless Networks
Using /etc/network/interfaces
Joining network with WPA encryption
NOTE: This method is working on Raspberry Pi platform as of April 2017.
Main Page: Linux/Wireless/2
To set the wireless network you want a Linux box to join, you can add the network name and passphrase to /etc/network/interfaces. Better yet, you can create one file for each network you want to have ready to go, and swap them in and out by sourcing them or not from the /etc/network/interfaces file.
First, put the wifi configuration information into a file. This will be called mynetwork.cfg, and will be stored in /etc/network/interfaces.d/mynetwork.cfg.
auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid NetName wpa-psk NetPassword
The next step is to reference this configuration file from the /etc/network/interfaces file. Here is what that file looks like:
source /etc/network/interfaces.d/mynetwork.cfg
The /etc/network/interfaces.d/ folder would contain credentials for several networks, and could be swapped out by editing /etc/network/interfaces.
Joining an open network
Repeat the above steps, but this time your wifi network's config file will look a little different for the open network:
auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid LocalCoffeeShop
WPA Supplicant Method
NOTE: This is for WPA- and WPA2-encrypted networks only.
Main Page: Linux/Wireless/1
This method uses wpa_supplicant, and has been tested and works on a Rasbperry Pi.
Set wireless network configuration
First add network configuration to /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="Your SSID Here"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="YourPresharedKeyHere"
}
Then edit /etc/network/interfaces and modify the wireless device to set the interface, and the wpa supplicant configuration file. Here is an example for a network with dynamic DHCP. This is the /etc/network/interfaces file:
# ------- DHCP ------------ iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp
Reset network device
Bring network device down and back up:
ifdown wlan0 ifup wlan0
You should see the wireless network you specified in your wpa supplicant file when you run iwconfig:
iwconfig
You should also see an IP address when you run ifconfig:
ifconfig
To start wpa_supplicant manually:
# sudo /sbin/wpa_supplicant \ -i wlan0 \ -P /var/run/wpa_supplicant.wlan0.pid \ -D nl80211,wext -c /etc/wpa_supplicant/wpa_supplicant.conf