Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I am using ArchLinux and want to create an AdHoc network automatically when the connection to the home network drops (or the home network can't be connected to on startup). How can I achieve this?

I found this on the internet what would resolve the problem on startup but not when the network is disconnected from:

# RPi Network Conf Bootstrapper

    echo "Creating ad-hoc network"
    ifconfig wlan0 down
    iwconfig wlan0 mode ad-hoc
    iwconfig wlan0 key aaaaa11111 #WEP key
    iwconfig wlan0 essid RPi      #SSID
    ifconfig wlan0 netmask up
    /usr/sbin/dhcpd wlan0
    echo "Ad-hoc network created"

echo "================================="
echo "RPi Network Conf Bootstrapper 0.1"
echo "================================="
echo "Scanning for known WiFi networks"
ssids=( 'MyWlan' 'MyOtherWlan' )
for ssid in "${ssids[@]}"
    if iwlist wlan0 scan | grep $ssid > /dev/null
        echo "First WiFi in range has SSID:" $ssid
        echo "Starting supplicant for WPA/WPA2"
        wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf     > /dev/null 2>&1
        echo "Obtaining IP from DHCP"
        if dhclient -1 wlan0
            echo "Connected to WiFi"
            echo "DHCP server did not respond with an IP lease (DHCPOFFER)"
            wpa_cli terminate
        echo "Not in range, WiFi with SSID:" $ssid

if ! $connected; then

exit 0

wicd on the other side provides (pre/post)(dis)connect scripts but I have no idea for the startup

share|improve this question
What networkmanager do you use? Wicd, netctl, any DE-specific? – uzsolt Apr 22 '13 at 16:03
I used Wicd. I Know there are (pre/post)(dis)connect scripts so I could use them to create an adhoc after an connection is dropped. But then I have no idea when it comes to the startup. Wicd normally tries to connect automatically to a known network but if it won't find any, how can then tell my computer to create an adhoc? So I thought maybe there would be another solution for that without using wicd, netcf, etc. but instead configuring it with ifconfig, iwconfig, etc. ... – Leonardo Apr 22 '13 at 17:03
Does nobody have an idea? – Leonardo Apr 24 '13 at 14:01
Sorry, I don't use wicd, maybe others (and sorry for "answer" :) ). But a possible solution: if you run wicd-curses, try press 'O' (check README.curses:… ) – uzsolt Apr 25 '13 at 5:27
No problem ;) Yeah but that means I do it manually ... – Leonardo Apr 26 '13 at 8:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.