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,969
  • 5
  • 27
  • 38
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,908
  • 12
  • 19
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
  • 62,573
  • 32
  • 113
  • 225
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,908
  • 12
  • 19