Take the 2-minute tour ×
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'm making a gui application which will control my laptop in order to make it act as a wifi hotspot. I may change distributions so I want to find a solution which will work generally for all distributions. I am currently doing this on Fedora 17.

Using NetworkManager's "Use as Hotspot" button works very well to create an ad-hoc hotspot: enter image description here

I want to recreate this functionality with terminal commands.

Below are two methods I tried to accomplish this but I havn't found a solution yet.


Method 1: iwconfig
Using research from accross the web, I tried the following command:

# ifconfig wlan0 10.42.0.1 netmask 255.555.255.0 broadcast 10.42.0.255 up
# iwconfig wlan0 essid my-lappy mode ad-hoc key 0123456789
# iptables-restore < saved-hotspot-iptables
# echo 1 > /proc/sys/net/ipv4/ip_forward
# dhclient wlan0

where saved-hotspot-iptables is a file which I generated with iptables-save > saved-hotspot-iptables with the iptables set by the "Use as Hotspot" function.

Method 1 Problem
Devices can see the SSID but are unable to connect. Running ip a reveals the following about wlan0:

...
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state DORMANT qlen 1000
...

Notice NO-CARRIER is present, and the state is DORMANT instead of UP.

Running ifconfig wlan0 shows the following:

...
wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
...

Notice that RUNNING is missing as one of the flags.


Method 2: nmcli
If NetworkManager's "Use as Hotspot" button is pressed at least once on the system, /etc/sysconfig/network-scripts/ifcfg-Hotspot is created and I can use the following command to start a working hotspot:

# ifconfig wlan0 up
# nmcli con up id Hotspot
# iwconfig wlan0 essid my-lappy key 0123456789

Method 2 Problem
If the user has never pressed "Use as Hotspot" on NetworkManager before, nmcli con up id Hotspot won't work. I've looked at nm-connection-editor --create but couldn't find much information. I've also looked into manually creating /etc/sysconfig/network-scripts/ifcfg-Hotspot but this method does not seem elegant or extendible to other distributions.

share|improve this question
    
Please don't crosspost. –  mgorven Jun 23 '12 at 0:20
1  
Try wicd. It is similar to NetworkManager but has a text mode interface. I don't know if it has a hotspot feature. –  Gilles Jun 23 '12 at 0:40
    
Thanks for the tip Gilles, I'm going to try it out right away. –  Daniel K Jun 27 '12 at 13:34
    
@Gilles I tried wicd but it appears to have even less functionality then nmcli. –  Daniel K Jul 6 '12 at 15:07

1 Answer 1

up vote 0 down vote accepted

A DHCP server was needed to assign IP addresses to wifi connections. I used dnsmasq, a DNS and DHCP server.

The following are the commands to start an ad-hoc wifi hotspot:

# ifconfig wlan0 10.42.0.1 netmask 255.555.255.0 broadcast 10.42.0.255 up
# iwconfig wlan0 essid my-lappy mode ad-hoc key 0123456789
# iptables-restore < saved-hotspot-iptables
# echo 1 > /proc/sys/net/ipv4/ip_forward
# dnsmasq -C /dev/null >/dev/null 2>&1 --bind-interfaces --listen-address=10.42.0.1 --dhcp-range=10.42.0.10,10.42.0.200,12h
share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.