[FrontPage] [TitleIndex] [WordIndex

This is a read-only archived version of wiki.centos.org

Enabling wpa_supplicant without NetworkManager, updated version

This update is a simpler method to have a wifi interface connect automatically during the boot process. The original version is available below for reference.

Why an updated version?

1. Edit /etc/sysconfig/network-scripts/ifcfg- file

Run iwconfig to find the wifi device. In this sample output, wlan0 is the only one that supports wifi.

# iwconfig 
lo        no wireless extensions.

wlan0     IEEE 802.11bgn  ESSID:"NETWORKSSID"  
          Mode:Managed  Frequency:2.462 GHz  Access Point: 68:7F:74:AD:F3:3C   
          Bit Rate=54 Mb/s   Tx-Power=16 dBm   
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on
          Link Quality=50/70  Signal level=-60 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:90   Missed beacon:0

eth0      no wireless extensions.

pan0      no wireless extensions.

virbr0    no wireless extensions.

virbr0-nic  no wireless extensions.


Edit the ifcfg for this interface. For example, using wlan0.


Verify that the ONBOOT selection is enabled.


2. Edit /etc/sysconfig/wpa_supplicant

Ensure that your device is included in the INTERFACES line in this file. In this example wlan0 is the only device supported by wpasupplicant.

# Use the flag "-i" before each of your interfaces, like so:
#  INTERFACES="-ieth1 -iwlan0"

3. Edit /etc/wpa_supplicant/wpa_supplicant.conf

Most of your networks will require a single entry in wpa_supplicant.conf that looks like this. Replace NETWORKSSID and NETWORKPSK with the proper values for each network. Put them in the order that you want them used.


Here is an example of a network which doesn't require a Pre Shared Key. If this appears before the "any" network it will be preferred to other open networks.


A final option (which you may not choose to implement) will let you connect to any network that is open. This is useful in hotels, but may allow connections to undesirable networks.


4. Create /etc/rc5.d/S09prepnet

Paste the following text to create a new file which will prepare the running services for a wifi connection.

cat > /etc/init.d/prepnet <<EoT

/etc/init.d/messagebus start
/etc/init.d/wpa_supplicant start
killall dhclient >/dev/null 2>&1
chmod a+rx /etc/init.d/prepnet
ln -s /etc/init.d/prepnet /etc/rc3.d/S09prepnet
ln -s /etc/init.d/prepnet /etc/rc5.d/S09prepnet

5. Configure services to run at boot

Paste the following commands to configure services.

chkconfig messagebus off
chkconfig wpa_supplicant off
chkconfig NetworkManager off
chkconfig network on

6. Reboot to enable

Upon the next reboot your wifi connection is enabled when network services start.

7. Adding or editing wifi networks

If you need to add or edit a wifi network, make whatever changes are needed in wpa_supplicant.conf.


Next restart wpa_supplicant and network services.

service wpa_supplicant restart
service network restart

Enabling wpa_supplicant without NetworkManager, original version

If you're like me, and you just roam between a few WPA-secured wireless networks, and you want your laptop to connect to the local wireless networks on boot, then here is a simple recipe.

Note that you can use NetworkManager for this, however it doesn't by default connect to a network on boot -- it requires a user to log in and give NetworkManager access to the keyring so that it can retrieve its WPA keys.

This is a recipe for using wpa_supplicant without NetworkManager, and making it connect on boot. It does require editing configuration files so if you're not comfortable with that then you may want to consider NetworkManager instead.

1. Edit /etc/wpa_supplicant/wpa_supplicant.conf

Most of your networks will require a single entry in wpa_supplicant.conf that looks like this:


Obviously you'll want to replace MYNETWORKSSID and MYNETWORKPSK with the SSID and PSK of the network you connect to.

2. Edit /etc/sysconfig/network-scripts/ifup-wireless

Add the following lines to the end of this file:

if [ "$WPA" = "yes" -a -x /etc/init.d/wpa_supplicant ]; then
    /sbin/service wpa_supplicant start

3. Edit /etc/sysconfig/network-scripts/ifcfg-*

There will be a number of files in /etc/sysconfig/network-scripts which describe a network, such as ifcfg-eth0 (probably your ethernet network) and one called something like ifcfg-wlan0 or ifcfg-eth1 which describes your wireless.

The one that describes your wireless network will contain the following line:


Add the following line to the end of this file:


4. Edit /etc/rc.d/rc.local

We have now configured wpa_supplicant to start when our wireless network interface starts. Unfortunately the order of script startup with CentOS is incorrect -- it tries to bring up the wireless networks (and hence wpa_supplicant) before DBUS is started, and wpa_supplicant requires DBUS to be running.

The quick and easy solution to this is to add the following line to the end of /etc/rc.d/rc.local, which will start your wireless interface last:

/sbin/ifup eth1

(or /sbin/ifup wlan0 if your wireless interface is wlan0).

This will bring up the wireless interface and also wpa_supplicant at the end of the boot process, after the necessary pre-requisite programs are running.

5. Disable interface and wpa_supplicant on boot

Because we're starting wpa_supplicant directly in the ifup script of the appropriate network interface there is no need to start it on boot from init. Disable it using:

chkconfig wpa_supplicant off

You can also disable the automatic starting of the wireless network interface (eth1 or wlan0) on boot using the Network Device Control application because we're now starting it manually with the change that we made to rc.local.

2023-09-11 07:22