1

I'm trying to use my Raspberry Pi 2 to broadcast an ad-hoc network that my laptop can connect to and use for file transfer and SSH. This connection does not need to provide internet access to the laptop. I have succeeded at creating this ad-hoc network by modifying /etc/network/interfaces and running a DHCP server on wlan0. I am using isc-dhcp-server to accomplish this.

This is my /etc/network/interfaces setup:

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet static
    address 192.168.1.1
    netmask 255.255.255.0
    gateway 192.168.1.2
    wireless-channel 3
    wireless-essid Test-Network
    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

This is my /etc/dhcp/dhcpd.conf setup:

ddns-update-style none;

option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

authoritative;

log-facility local7;

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.1 192.168.1.50;
option broadcast-address 192.168.1.1;
option routers 192.168.1.1;
}

This is my /etc/default/isc-dhcp-server setup:

DHCPD_CONF=/etc/dhcp/dhcpd.conf
INTERFACES="wlan0"

Everything else in the above files is commented out (and not included in this post).

The problem I'm having involves using eth0 to connect to the internet. I plug in eth0 to update packages, pull git repositories, etc. This is important for keeping my Raspberry Pi maintained.

When I plug in an active Ethernet cable to eth0, I don't get any internet connection on the Raspberry Pi. The ad-hoc network still runs, and I can connect and ssh at 192.168.1.1, but the Pi has no internet access.

I've successfully gotten an internet connection using eth0 by disabling the ad-hoc network, but I need both working at the same time.

Any suggestions?

Greenonline
  • 2,740
  • 4
  • 23
  • 36
Bobothetwit
  • 11
  • 1
  • 2

3 Answers3

1

None of this is Pi-specific, but here is your answer:

The problem is that you've set eth0 to manual. Go back to having it on dhcp. That you are running a dhcp server on wlan0 does not change the fact that you need a dhcp client on eth0!

JayEye
  • 1,898
  • 11
  • 18
  • With eth0 set to dhcp, the pi does get internet, the wireless network does broadcast, but the DHCP server on wlan0 does not work. Any suggestions? Thanks for the help so far! – Bobothetwit Apr 28 '16 at 14:29
0

You have iface eth0 inet manual which will do NOTHING although if you use the standard networking setup dhcpcd will supply details.

Presumably you have disabled dhcpcd as you claim to be running a DHCP server.

I know you are trying to do something different but see the following for background. How do I set up networking/WiFi/Static IP

You also claim to have an ad-hoc network. AFAIK this is not possible on the Pi (many others have asked about this). Maybe you are running an access point.

If you want to use the Pi to provide internet access you need to create a bridge.

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • please check your statements for correctness before you offer them as advice. Whether adhoc mode is supported or not is a function of the wireless interface. For example, both the Realtek 8188 (very common in usb wifi adapters) and the BCM43438 on the Pi3 support ad hoc mode. – JayEye Apr 27 '16 at 07:02
  • @JayEye I offered this as opinion (from other posts I have read) not as a statement of fact. It is not that the WiFi modules do not allow ah-hoc but lack of software support on the Pi. Many users do not appreciate the difference between AP and ad-hoc mode. Indeed the user does not seem to be attempting to create an ad-hoc network. – Milliways Apr 27 '16 at 07:17
  • Thank you for explaining a little bit about the problem. I'll try changing eth0 from manual to dhcp (as another use actually suggested).

    For your reference, Raspberry Pi has no trouble creating and broadcasting an ad-hoc network with the right hardware. As I said in my original post, I got that part working fine.

    – Bobothetwit Apr 27 '16 at 13:30
0

Oh, I see the problems:

  • wlan0 and eth0 should be on different subnets. Judging from the lines address 192.168.1.1 and gateway 192.168.1.2 in your /etc/network/interfaces, eth0 is also on 192.168.1.0/24. Let eth0 take its address from dhcp. Also, you must not specify a gateway entry for wlan0; the default route for the pi will be set by dhcp.

  • The range line in dhcpd.conf specifies the range of addresses to allocate to your dhcp clients. That range must not include your own address.

To make everything work:

Choose some other subnet for wlan0, say, 192.168.4.0/24. The wlan0 stanza in interfaces should read something like

allow-hotplug wlan0
iface wlan0 inet static
  address 192.168.4.1
  netmask 255.255.255.0
  wireless-channel 3
  wireless-essid Test-Network
  wireless-mode ad-hoc

(no need for a gateway line)

Your dhcpd.conf should then include:

subnet 192.168.4.0 netmask 255.255.255.0 {
  option subnet-mask 255.255.255.0;
  option routers 192.168.4.1;
  option broadcast-address 192.168.1.1;
  # dynamically allocate addresses from .10 to .50
  pool {
    range 192.168.4.10 192.168.4.50;
  }
  # example of a statically-allocated address.
  # Note that it is outside the pool!
  host foo.example.com {
    hardware ethernet 08:00:2b:32:44:8a;
    fixed-address 192.168.4.77;
    option host-name "foo.example.com";
  }
}

(I decided to save you and others some time and included an example of a static address).

If you really want to route traffic between the wireless and wired segments, don't forget to add net.ipv4.conf.all.forwarding = 1 in your /etc/sysctl.conf (or some equivalent place).

JayEye
  • 1,898
  • 11
  • 18
  • Thank you @Jayeye! I'll test this all soon - but I already have a question. With ipv4 forwarding enabled, I understand that internet access from ethernet will be accessible via ad-hoc. What will happen when ethernet is unplugged? Will the ad-hoc network function as it does currently? (no internet) – Bobothetwit Apr 29 '16 at 21:57
  • No, with forwarding enabled, internet access will not be available via the ad-hoc network (your original question said "This connection does not need to provide internet access to the laptop.").

    There are several ways of doing this, and with a little bit of searching you can find them. It's definitely beyond the scope of a simple comment. It's also not a pi-specific issue, so you may want to search other fora as well.

    – JayEye Apr 29 '16 at 23:16