1

There's plenty out there on setting up an ad-hoc network on your RPi, (Mine's an A, I believe.) but almost none on how to do it when you're using Raspbian Jessie. As such, I'm having a bit of trouble getting things working.

I've altered my /etc/network/interfaces to read

auto lo
iface lo inet loopback

iface eth0 inet dhcp

auto wlan0
iface wlan0 inet manual
    wireless-channel 1
    wireless-essid PiNet
    wireless-mode ad-hoc

#allow-hotplug wlan0
#iface wlan0 inet manual
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

To get a static IP, I altered my /etc/dhcpcd.conf by adding

interface wlan0
static ip_address=192.168.1.1/24

to the bottom of the file.

I also installed isc-dhcp-server and changed my /etc/default/isc-dhcp-server by adding wlan0 to INTERFACES=''

Finally, I changed my /etc/dhcp/dhcpd.conf by...

  • changing ddns-update-style none; to ddns-update-style interim;
  • uncommenting authoritative;
  • and adding subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.5 192.168.1.100 } to the bottom of the file.

It creates an open network PiNet, but my computer can't connect to it.

Is there anything obvious that I've missed?

CoilKid
  • 121
  • 6
  • You do it exactly the same way you always did. What you can't do is setup an ad-hoc network **AND** use `dhcpcd` to manage networks. – Milliways Jan 11 '17 at 23:00
  • @Milliways Not sure how else I'd do it. Anyway, as it turns out, I found a solution that I like *much* better than what I was trying for. Not sure if it's more elegant or will cause issues for me in the future. Lets me SSH in just fine though! – CoilKid Jan 12 '17 at 00:24

1 Answers1

1

After a bit of digging around, I found this. You can basically follow all the instructions, except ignore the bits about configuring network address translation and iptables. It won't create an ad-hoc network per se, but, if you're just trying to SSH into a RPi-based-device when you're in the middle of a field like I was, this should work well.

Generally:

  • install hostapd and dnsmasq on your RPi

  • change your /etc/network/interfaces file to read something like:

    auto lo
    iface lo inet loopback
    iface eth0 inet dhcp
    
    allow-hotplug wlan0
    iface wlan0 init static
     address 192.168.0.1
     netmask 255.255.255.0
     wireless-mode ad-hoc
    
    #allow-hotplug wlan0
    #iface wlan 0 inet manual
    #    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    
  • open your dnsmasq config file (/etc/dnsmasq.conf) and uncomment #dhcp-range=192.168.0.50,192.168.0.150,12h

  • create a hostapd config file (sudo nano /etc/hostapd/hostapd.conf) and enter something to the effect of

    interface=wlan0
    driver=nl80211
    ssid=PiNet
    country_code=US
    hw_mode=g
    channel=6
    macaddr_acl=0
    auth_algs=1
    ignore_broadcast_ssid=0
    wpa=2
    wpa_passphrase=Raspberry
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=CCMP
    wpa_group_rekey=86400
    ieee80211n=1
    wme_enabled=1
    

(Obviously change the ssid and passphrase, and you might have to find the correct driver for your wifi adapter. The guide suggested that you can leave off the driver= line if you're using a RPi 3, I don't know if that's true.)

  • Make sure hostapd knows about the config file. Open /etc/default/hostapd and replace #DAEMON_CONF="" with DAEMON_CONF="/etc/hostapd/hostapd.conf". Open /etc/init.d/hostapd and replace DAEMON_CONF= for DAEMON_CONF=/etc/hostapd/hostapd.conf.

  • Reboot your RPi, connect to it with your favourite device and SSH away!

CoilKid
  • 121
  • 6
  • You are doing things incorrectly. You need to set your ip address in `/etc/network/interfaces` and NOT in `/etc/dhcpcd.conf`. You are attempting to provide the dhcp server with `dhcpd` while also using a dhcp client (`dhcpcd`). You should not be using a dhcp client on the same interface when you yourself are the server. The only reason this works now is because you're not an authoritative dhcp server thus you do not deny the ip requested by `dhcpcd`. – Hydranix Jan 12 '17 at 01:03
  • Also this is not an ad-hoc network. This is an access point. – Hydranix Jan 12 '17 at 01:11
  • @Hydranix Fair points to both, but I tried to set the static IP from `interfaces`. Didn't work. It only seems to have a static IP when I do it from `dhcpcd`. As to the other one... True, but it works better than what I wanted. I only wanted a way to SSH into a rover I'm building when I'm not near my LAN. If I did it right, it should do just that. And it's password protected! – CoilKid Jan 12 '17 at 01:48
  • @Hydranix Whoops, that's why it wouldn't work. I had a typo! Thanks for making me double check that. Got it working with just `interfaces` edit. I'll correct that in my answer now. Anything else you noticed? – CoilKid Jan 12 '17 at 02:02
  • `wireless-mode ad-hoc` should be `wireless-mode Master` – Hydranix Jan 12 '17 at 13:26
  • If you use NetworkManger at all, you'll want to tell it to ignore the wireless itnerface. Edit the file `/etc/NetworkManager/NetworkManager.conf` and add this key-value pair under the `[keyfile]` section: `unmanaged-devices=mac:` – Hydranix Jan 12 '17 at 13:28
  • @Hydranix `wireless-mode Master`? Is there a page that describes the different modes? I glanced through the `interfaces` page, but I didn't see anything about the different wireless modes. Also, what does making it ignore the wireless interface do? – CoilKid Jan 13 '17 at 19:54
  • Master mode makes your wireless card act like an AP, ad-hoc mode requires both cards be preconfigured very carefully. [This page](http://www.vias.org/wirelessnetw/wndw_05_04.html) is old but has good information of four of the modes. Also, disabling NetworkManager will stop it from trying to configure your wireless card, potentially breaking your hostapd and dnsmasq configuration in doing so. – Hydranix Jan 14 '17 at 08:10
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year. – Ingo Apr 27 '20 at 11:37