Option 1
Just edit /etc/network/interfaces
and write:
auto wlan0
iface wlan0 inet dhcp
wpa-ssid {ssid}
wpa-psk {password}
After that write and close file and use command:
sudo dhclient wlan0
Replace {ssid} and {password} with your respective WiFi SSID and password.
Option 2
Provided you replace your Wireless network card, Wi-Fi Network name, and Wi-FI Password this should also work.
I am using:
- Wireless network card is wlan0
- Wireless network is "Wifi2Home"
- Wireless network key is ASCII code ABCDE12345
First, get your WiFi card up and running:
sudo ifconfig wlan0 up
Now scan for a list of WiFi networks in range:
sudo iwlist wlan0 scan
This will show you a list of wireless networks, pick yours from the list:
sudo iwconfig wlan0 essid Wifi2Home key s:ABCDE12345
To obtain the IP address, now request it with the Dynamic Host Client:
sudo dhclient wlan0
You should then be connected to the WiFi network. The first option is better, because it will be able to run as a cron
job to start up the wifi whenever you need it going. If you need to turn off your WiFi for whatever reason, just type:
sudo ifconfig wlan0 down
FYI
I have also seen people using alternative commands. I use Debian, Solaris and OSX, so I'm not 100% sure if they are the same on Ubuntu. But here they are:
sudo ifup wlan0
is the same as sudo ifconfig wlan0 up
sudo ifdown wlan0
is the same as sudo ifconfig wlan down
In Debian's /etc/network/interfaces
(or any other distribution using Debian's ifupdown utility), a backslash-newline sequence is removed, and backslash is not special anywhere else. A double quote character is not special either. The character #
starts a comment if it's the first non-whitespace character on a (non-continuation) line. Null bytes are treated as newline characters (I think — the parser uses C strings and has no special handling for null bytes, so they might cause additional mischief).
Configuration lines take the form of an option name followed by a value, separated by whitespace. Leading and trailing whitespace is ignored. Some built-in options further parse the line into words; the value of options to iface
always runs to the end of the line.
For example, the line
wpa-ssid "a b" "cd"
sets the option wpa-ssid
to the 12-character string "a b" "cd"
(internal whitespace is preserved).
WPA Supplicant's ifupdown script strips double quotes at the beginning and at the end of the wpa-ssid
configuration string, the line above is equivalent to wpa-ssid a b" "cd
. This way, you can have leading and trailing whitespace in the SSID.
I can't find a quoting issue in the WPA Supplicant ifupdown scripts, so it looks like anything that ifupdown will produce is safe.
Thus you can allow any string as an SSID to be injected into /etc/network/interfaces
, provided that it does not contain any newline or null byte. Add double quotes around the string (if you don't, SSIDs with leading or trailing whitespace, or that end with \
, or that begin or end with "
, will be mangled).
Best Answer
This is what worked for me. That's quite a dirty fix, I hope someone can improve this answer.
wlp3s0
is my wifi network interface, DIR-300NRU is the ssid. Adjust those to your case.My interface config in
/etc/network/interfaces
:I run:
(next step is not a part of the solution)
I check my wifi device:
While DHCP is trying to connect, I run the following in another terminal:
Now wifi is working until I restart my system. I can see that the output of
sudo iw dev wlp3s0 info
changes to: