Configuring raspberry Pi as a gateway of an ad-hoc network

I am trying to configure multiple Wireless interface in Raspberry Pi Stretch. The objective is to allow an ad-hoc network to access the internet through that Pi device. For that I need to configure the in-built wlan0 in ad-hoc mode, whereas, an external wlan adapter, wlan1 to connect to the available wifi AP. The information here actually allows me to activate the ad-hoc mode but causes the dhcp service to stop working. I need the dhcp client enabled on wlan1. So far I have found that modifying /interfaces file causes problem with the dhcp service. In that case, how can I activate the ad-hoc mode and solve the above mentioned scenario?

• See How to set up networking/WiFi you have provided insufficient information for a detailed answer. – Milliways Jul 19 '19 at 12:41
• You asked how to modify dhcpcd.conf. I only use systemd-networkd so I have a setup with it. Could this also be a solution for you? Please address me with @Ingo, otherwise I won't see your reply. – Ingo Jul 19 '19 at 15:33
• @Ingo, Hi, Any solution is ok with me. The objective is, I need to formulate an ad-hoc network with n number of pi's. And a gateway that forwards the traffic to the internet. Earlier I did it using only /interfaces file, even most of the helps available online points me that way. I just can't figure out how to do it in Strech or even with the latest release. – se7en Jul 22 '19 at 5:13
• @Milliways, I've gone through the information but if I haven't missed it, I am still lacking the info about how to activate the ad-hoc mode without touching the file, \interfaces. Any guidance is much appreciated. – se7en Jul 22 '19 at 6:39
• I am not sure whether it is possible to enable ad-hoc on the on-board interface. You stated "stretch uses dhcpcd.conf for assigning static IP that is required for the ad-hoc network. How do I modify the dhcpcd.conf for the above purpose?" and the link answers that. You have provided virtually no information. – Milliways Jul 22 '19 at 7:01

As you noted in a comment you are also comfortable with using systemd-networkd. Any device conforming to IEEE 802.11 must provide the ad-hoc Independent Basic Service Set (IBSS) so it is possible to use it by just configuring the WiFi driver. In addition you can also use wpa_supplicant to setup an IBSS ad-hoc network. IBSS was initial specified only without encryption because it was thought to be done by higher protocol levels. Later encryption was also added to IBSS but it must be supported by the WiFi device. Raspberry Pi does not support encryption on IBSS. Maybe your external wlan adapter will do it? How to setup all of this you can look at Configuring 2 wifi interfaces, one DHCP and the other ad-hoc, in Stretch.

• I tried with that but unfortunately it didn't work for me. – se7en Jul 25 '19 at 8:56

I've solved it by a simple approach that has been used here. I have created two files, wlan0 and wlan1 in /interfaces.d/. Then, I have configured each of them accordingly. For instance, the ad-hoc network was configured as,

auto wlan0
iface wlan0 inet static
wireless-channel 1


And wlan1 as

auto wlan1
allow-hotplug wlan1
iface wlan1 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp


This is necessary so that wlan1 can connect to the specific AP on boot. The network information can now be put in wpa_supplicant.conf

Finally, I have modified the dhcpcd.conf to ignore both wlan0 as well as wlan1.

On rebooting, only eth0 and wlan1 were getting IP addresses from the DHCP server as expected.