FreeBSD Wireless Quickstart

This is being written for the person who just installed FreeBSD and needs to quickly set up a wireless connection. It covers wireless with no authentication, WEP, and WPA/WPA2 personal setup. It assumes that you've already gotten your card recognized by the system.

Most of this is taken from the Handbook's wireless page, just leaving out most of the explanations and opinions. In most examples, we'll use an Intel card, which your FreeBSD system sees as iwm, (or possibly iwi) and is one of the more common cards.

Does the sytem see your card?
In FreeBSD-10.x and below, try the command ifconfig. Hopefully, it shows your card. If not, that's beyond the scope of this article, but you can start by trying to figure out the model and seeing if it's supported, or finding a USB wireless that works. It may be as simple as loading a module a boot. Each version of FreeBSD supports more cards. See below for FreeBSD-11 and up.

IMPORTANT NOTE:
In FreeBSD-11, doing ifconfig or ifconfig -l will no longer show said iwi0 (or whatever designation your card uses.) Instead, you can run sysctl net.wlan.devices, which should show you if the system has seen your card. If so, then proceed to the next step.

ANOTHER IMPORTANT NOTE:
Sometimes, even if the system sees your card, you will have to edit /boot/loader.conf or other file to get it working. Once you know your card, for example, iwm, check the man page for it. For example, anything using the urtwn driver, such as the little Edimax 7811-UN, require two lines in /boot/loader.conf
if_urtwn_load="YES"
legal.realtek.license_ack=1

Most Intel cards, using the iwm or iwi driver, will also require lines to be added to /boot/loader.conf, so, once the driver is determined, run, for example, if it's using iwm, man iwm to see if anything is needed in /boot/loader.conf.

Setting up the LAN device
First, one creates device wlan0. Assuming the card is iwm0, the command is
ifconfig wlan0 create wlandevice iwm0

This seems to have changed in 12.x. Now the command, at least for my Intel card is :
ifconfig wlan create wlandev iwm0

You should see that the device has been created. To make this happen automatically upon boot, add the following to /etc/rc.conf
wlans_iwm0="wlan0"

Connecting to an open network
So, you live in NYC, and you're at the New York Public Library, which has an open network called NYPL. (I think--I'm in the middle of writing this, and I'm not going downstairs to check right now---ahh, First World Problems). You've created your wlan0 device as described, so let's connect it to NYPL's network.

First let's get the name of the network.
ifconfig wlan0 up scan

This looks for available networks and will return a listing of them. In this case, we want to connect to the NYPL network so we'll use
ifconfig wlan0 ssid NYPL

Hopefully you will see that it's joined, and running ifconfig iwm0 will show that it's associated. Get an address.
dhclient wlan0

You should see that it has an address.

WEP
WEP is pretty insecure, and you should probably not use it,but if you are using it, then, first create the wlan0 device as described above.

Assuming your WEP ssid is mywep and has a password of 1234, the command would then be
ifconfig wlan0 ssid mywep wepmode on wepkey 0x8787887878 webextkey 1

That is using the hex version of the key. I'm not sure how to specifiy the ASCII version on the command line, and as I've not seen a WEP network in years, when 2 minutes of google didn't find it, I gave up. :) In Linux, I think that one used to use -s (as in string, to preface it, so doing something like
ifconfig wlan0 ssid mywep wepmode on wepkey -s mywepkey webextkey 1

may work, but I really don't know. Generally, you REALLY shouldn't use WEP anyway.

WPA/WPA2/Personal
This is the default for most home routers. Assuming your network is called mywpa and your password is 1234, once again, first create the device with ifconfig wlan0 create wlandev iwm0. Then create a wpa_supplicant.conf file. For now, the wpa_supplicant.conf file can stay in your $HOME directory while you test.
network={
	ssid="mywpa"
	psk="1234"
}

If your router has the network hidden, as some of the older Linksys routers do by default, then it should be slightly different.
network={
	scan_ssid=1
	ssid="mywpa"
	psk="1234"
}

To run this from command line (you'll need root privilege or use sudo)
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf

(Assuming you've put wpa_supplicant.conf in /etc. This will show you what's going on. Once you're sure it's working, you can run it in the background, by adding the -B option.
wpa_supplicant -B -i wlan0 -c wpa_supplicant.conf

Once it's associated with the network, you can use dhclient to get an address. (Running ifconfig wlan0 should show that it's associated.)
dhclient wlan0

To make this one automatic, move your wpa_supplicant.conf to /etc and add the following to /etc/rc.conf. (We're assuming you already have the wlans0_iwm0="wlan0" in /etc/rc.conf)
ifconfig_wlan0="WPA SYNCDHCP"

If you then run
service netif restart

It may also be necessary to run
service routing restart

your wpa configuration should associate your card with the network and get it an address through DHCP.

While this next part goes beyond being a quickstart, if you're saving a wpa_supplicant.conf file, you can use the wpa_passphrase command to create said file. (I think it requires an 8 character password, which is a Good Thing(TM), so we'll use that in this example.)
wpa_passphrase mywpa 12345678 > wpa_supplicant.conf

This produces a file that will read
network={
ssid="mywpa"
	#psk="12345678"
	psk=271e5385c39a01edd8c0de9e62b1f3f392271df59365508935f6815234817736
}

You can then remove the commented out #psk="12345678" line, and copy the file over to /etc/wpa_supplicant.conf. (Again, if it's a hidden network, insert the scan_ssid=1 above the ssid="mywpa" line.)

Remember sudo doesn't do redirect, so if you wish to use sudo (taken from a post by vermaden on FreeBSD forums)
wpa_passphrase "mywpa" "12345678" |sudo tee /etc/wpa_supplicant.conf