This would also fit in the Scripting Language board as well, but I think it's more fitting here.
In the past, I've used wicd, NetworkManager, and things of that nature. However, I always had issues with both of them disconnecting constantly and hardware compatibility or whatever. This was a long time ago. Ever since I've simply been using wpa_supplicant + dhcpcd, or netctl on Arch. Simple is better, and I've never had connection issues doing it manually. The only trouble is that it's not always so convenient to do this when you are on the move connecting to public wifi here and there. So I wrote a simple bash script to automate this. It takes the ssid and password as command-line arguments.
wifi_util Jimwifi password123
For some reason, even though it appears to do the same thing as when I connect to my home network with wpa_supplicant and dhcpcd, it fails with varied results. Here's the code first:
#!/bin/bash
# Quick public wifi connect tool
CONFIG=/home/user/dir/dir/wpa_supplicant.conf
# Clean up dhcp leases and process files
rm /var/lib/dhcpcd/* &>/dev/null
rm /var/run/dhcpcd-* &>/dev/null
rm /var/run/wpa_supplicant/*
# Easy creation of wpa_supplicant
echo "ctrl_interface=/var/run/wpa_supplicant" > $CONFIG
echo -e "ctrl_interface_group=root\n" >> $CONFIG
wpa_passphrase "$1" "$2" >> $CONFIG
# Connect
wpa_supplicant -B -Dwext -i wlan0 -c $CONFIG
dhcpcd wlan0
This is what I normally see:
dhcpcd[2065]: version 6.0.5 starting
dhcpcd[2065]: wlan0: waiting for carrier
dhcpcd[2065]: wlan0: carrier acquired
dhcpcd[2065]: wlan0: soliciting an IPv6 router
dhcpcd[2065]: wlan0: soliciting a DHCP lease
dhcpcd[2065]: wlan0: offered 172.20.1.7 from 172.20.1.1
dhcpcd[2065]: wlan0: leased 172.20.1.7 for 86400 seconds
dhcpcd[2065]: wlan0: adding host route to 172.20.1.7 via 127.0.0.1 < these seem related
dhcpcd[2065]: wlan0: ipv4_addroute: Network is unreachable < and significant
dhcpcd[2065]: wlan0: adding route to 172.20.1.0/24
dhcpcd[2065]: wlan0: adding default route via 172.20.1.1
dhcpcd[2065]: forked to background, child pid 2107
The rest of the time it times out with this:
dhcpcd[1994]: version 6.0.5 starting
dhcpcd[1994]: wlan0: waiting for carrier
dhcpcd[1994]: timed out
dhcpcd[1994]: allowing 8 seconds for IPv4LL timeout
dhcpcd[1994]: wlan0: carrier acquired
dhcpcd[1994]: wlan0: soliciting an IPv6 router
dhcpcd[1994]: wlan0: soliciting a DHCP lease
dhcpcd[1994]: timed out
dhcpcd[1994]: exited
I'm not sure why this isn't working. Right before any error messages, I see that it successfully initializes wpa_supplicant, every time. So the problem seems to lie with DHCP somehow. Normally, I would connect simply with /etc/rc.d/rc.local:
#!/bin/sh
#
# /etc/rc.d/rc.local: Local system initialization script.
# Put scripts you want executed on shutdown in:
# /etc/rc.d/rc.local_shutdown
# Load alternative modules
modprobe rtl8188ee
# Connect to wireless internet
wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant.conf < Same thing my script does
dhcpcd wlan0 <
As you can see it's the same thing really. It just initializes wpa_supplicant and runs dhcpcd on startup. Both /etc/wpa_supplicant.conf and my custom wpa_supplicant.conf file are valid and get initialized successfully. I don't get it.