CRUX : Home

Home :: Documentation :: Download :: Development :: Community :: Wiki :: Ports :: Bugs :: Links :: About

Back to wiki start page

Categories: Network

How to setup a wifi network

Authors

Jose V Beneyto
Tilman Sauerbeck

Description

This articles is an example of configuration for an Intel Corporation PRO/Wireless 3945ABG

Instructions

This howto assumes that you're running Linux 2.6.24 or greater. First of all, enable the iwl3945 driver in the kernel:

Next, install the firmware files:

# sudo ports -u contrib
# sudo prt-get install iwlwifi-3945-ucode

Install wireless tools:

# sudo ports -u opt
# sudo prt-get install wireless-tools

Then configure your network daemon script:

 #!/bin/sh
 #
 # /etc/rc.d/net: start/stop wifi network
 #

 IFACE="wlan0"
 IP="192.168.100.2"
 NETMASK="255.255.255.0"
 GW="192.168.100.1"
 ESSID="<your-essid>"
 KEY="<your-key>"

 case $1 in
   start)
     /sbin/ifconfig $IFACE $IP netmask $NETMASK
     /sbin/route add default gw $GW
     /usr/sbin/iwconfig $IFACE essid $ESSID
     /usr/sbin/iwconfig $IFACE key open s:$KEY
     /usr/sbin/iwconfig $IFACE mode managed
     ;;
   stop)
     /sbin/ifconfig $IFACE down
     ;;
   restart)
     $0 stop
     $0 start
     ;;
   *)
     echo "usage: $0 [start|stop|restart]"
     ;;
  esac

 # End of file

Using WPA2 encryption, and dhcpcd

Wireless networking can also be achieved using dhcpcd. Further, if using an encryption method like WPA2, wpa_supplicant calls can be run directly from the init script.

As described in the README for wpa_supplicant, first populate your /etc/wpa.conf for the appropriate SSID:

# wpa_passphrase <ssid> <your_secret> >> /etc/wpa.conf

Then, add the wpa_supplicant command directly into the init script. For example:

#!/bin/sh
#
# /etc/rc.d/wifi: start/stop network
#

case $1 in
start)
	# loopback
	/sbin/ip addr add 127.0.0.1/8 dev lo broadcast + scope host
	/sbin/ip link set lo up
	# wpa_supplicant + wlan0 connection
	/usr/sbin/wpa_supplicant -B -Dwext -iwlan0 -c/etc/wpa.conf
	/sbin/dhcpcd -t 10 -h $HOSTNAME wlan0
	;;
stop)
	/usr/bin/killall -q /sbin/dhcpcd
	/usr/bin/killall -q /usr/sbin/wpa_supplicant
	/sbin/ip link set lo down
	/sbin/ip addr del 127.0.0.1/8 dev lo
	;;
restart)
	$0 stop
	$0 start
	;;
*)
	echo "usage: $0 [start|stop|restart]"
	;;
esac

# End of file

Finally, to automatically bring up the wireless interface at boot, edit /etc/rc.conf adding wifi to list of services, for example:

#
# /etc/rc.conf: system configuration
#

FONT=default
KEYMAP=us
HOSTNAME=cruxbox
SYSLOG=sysklogd
SERVICES=(lo net crond wifi) # <---- added wifi so it comes up at boot

# End of file