I'm pretty new to Linux; this project is me trying to learn more. I've done login scripts before but not boot scripts, so that's one of my questions. My other question is how to get an ad-hoc network working with just terminal commands, so that I can make a boot script to do it. I'm running Fedora 18 off of a flash drive for now, but when I'm done configuring I'll be copying everything to an old laptop's hard drive. (The goal of this project is to not have to buy a better wireless router)

The most luck I've had setting up an ad-hoc was by using Gnome's "Use as Hotspot..." button in my wireless network settings, and then changing the name and WEP code (Can I use other encryption methods?) using iwconfig in the terminal, but I want it all done with terminal commands so that I can just run a script to set it all up. I think I can figure out how to use iptables to set up my port forwarding and junk myself, but first I need to get this computer able to share its internet connection wirelessly.

  • What card are you using ? Have you checked if it supports AP mode ? (post the output of iw phy to figure out ?). If AP mode is not supported, maybe IBSS-RSN (which is basically WPA2 in ad-hoc mode) is supported.
    – BatchyX
    May 29 '13 at 20:41
  • I ran "iw phy" on my newer laptop. I see a line under "Supported RX frame types:" that says "AP: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0" and immediately under is one that says "AP/VLAN: " and the same hex numbers. The laptop I'll eventually move this all onto is a Dell Latitude D630, but I don't have it with me at the moment. Its hinges are broken so I don't touch it if I don't have to.
    – Edward Alm
    May 30 '13 at 16:32
  • If there is no AP under Supported interface types, your card/driver does not support AP mode. What contains Supported RX frame types is a bit irrelevant. Check if there is a mention of IBSS-RSN anyway, in that case, you may still do WPA2 in ad-hoc mode...
    – BatchyX
    May 30 '13 at 19:01

This blogspot entry has a guide for configuring a wireless network in ad-hoc mode. On the first machine, run these commands (fill in your own network information):

 ifconfig wlan0 down
 iwconfig wlan0 channel 4
 iwconfig wlan0 mode ad-hoc
 iwconfig wlan0 essid 'fermilevel'
 iwconfig wlan0 key 1234567890
 ifconfig wlan0

On the second machine:

 ifconfig wlan0 down
 iwconfig  wlan0 channel 4
 iwconfig  wlan0 mode ad-hoc
 iwconfig  wlan0 essid 'fermilevel'
 iwconfig  wlan0 key 1234567890
 ifconfig  wlan0

The essid and key must be the same on both machines.

  • 1
    ifconfig and iwconfig are both deprecated, especially the latter which is completely obsolete. Use ip and iw instead. Using iw has the direct benefit that it gives you the option to use 802.11n in the iw ibss join command.
    – BatchyX
    May 29 '13 at 20:45
  • That blog post is trying to connect two Linux computers together; I'm just trying to set up one computer that shares its internet connection wirelessly with Windows PCs and my phone and junk. I can get the network to appear on my Windows PC by running one set of those commands on my laptop, but if I try to connect to it I get "Unidentified Network/No Internet Access".
    – Edward Alm
    May 30 '13 at 16:39
  • ad-hoc is a peer-to-peer connection. you can setup each device to connect to the box that is sharing the net. I am not sure if ad-hoc will provide simultaneously connection to all of your devices.
    – Raza
    May 30 '13 at 17:44
  • Please make sure to setup bridge or routing in order to avoid "Unidentified Network/No Internet Access" error.
    – Raza
    May 30 '13 at 17:47
  • ifconfig wlan0 up is not need?
    – Yang Yu
    Aug 5 '19 at 20:43

Creating ad-hoc Wi-Fi network used for sharing wired Internet connection using shell commands should be simple. Although I don't use Fedora setting up wireless networks should work similarly on all desktop Linux systems.

First, let's make sure that all components required to setup wireless network are available and install them if they are not:

$ command -v hostapd dnsmasq iptables ip

We'll put all configs in a dedicated ~/wireless-network-setup directory so that we can find them easily:

mkdir ~/wireless-network-setup && cd ~/wireless-network-setup

As stated on https://w1.fi/hostapd/:

hostapd is a user space daemon for access point and authentication servers. It implements IEEE 802.11 access point management, IEEE 802.1X/WPA/WPA2/EAP Authenticators, RADIUS client, EAP server, and RADIUS authentication server. The current version supports Linux (Host AP, madwifi, mac80211-based drivers) and FreeBSD (net80211).

Put this in hostapd.conf:




This will create Wi-Fi network with FREE-Wi-Fi SSID, WPA2 security and password passphrase.

dnsmasq is DHCP server. It will assign IP addresses to Wi-Fi network clients. Put this in dnsmasq.conf:


DHCP server cannot provide IP address to itself so we have to set wlan0 interface IP address manually:

sudo ip addr add dev wlan0
sudo ip link set wlan0 up

iptables is a firewall tool. We have to tell it to redirect traffic to eth0:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -P FORWARD ACCEPT

If your Internet-facing interface is not named eth0 modify its name accordingly.

That's the whole configuration. Start hostapd and dnsmasq:

sudo hostapd -B hostapd.conf
sudo dnsmasq -C dnsmasq.conf

Now you should be able to connect to Free-Wi-Fi network from other devices and access the internet.

Notice that in Fedora both dnsmasq and hostapd probably come with customized init startup scripts that you can use instead of starting them manually like that.

Also notice that if you're using some specific hardware, for example rtl8188eu you will have to use forked hostapd: https://github.com/lwfinger/rtl8188eu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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