1

I have been struggling to configure static IP addresses for my wired and wireless connections on my Raspberry Pi (Raspbian).

If I add these lines to /etc/dhcpcd.conf then after rebooting I can connect via a wired connection:

interface eth0
static ip_address=192.168.1.2/16
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

If I replace that with the following and reboot I can connect via wifi:

interface wlan0
static ip_address=192.168.1.3/16
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

The problems comes when I add both pieces of code together:

interface eth0
static ip_address=192.168.1.2/16
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface wlan0
static ip_address=192.168.1.3/16
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

When I reboot the Raspberry Pi hangs and I cannot ssh in (I am running headless). If I unplug the network cable and then immediately plug it back in then I can ssh in.

Why can I only reboot when the network cable is unplugged?

  • 1
    Your problem is that you have two interfaces in the same network, 192.168.0.0/16, and each sets a default route. – RalfFriedl Jul 4 at 16:57
  • @RalfFriedl How do I go about fixing that? I do not know much about networking. What I wanted was to give the wired connection one IP address and the wifi another. I could then choose to connect via ssh to either the wired or wifi connection. Sorry if this sounds mad but I am at the extreme end of my network knowledge! – user1464409 Jul 4 at 17:11
  • What is the source of the SSH connection? – RalfFriedl Jul 4 at 17:14
  • @RalfFriedl I'm not sure what you mean by the source. My main computer runs Linux Mint if that is what you mean. Sorry again for not understanding. – user1464409 Jul 4 at 17:32
2

You cannot simply merge single working networks.

In general, if you want to give your interfaces ip addresses, no matter if static or by DHCP, both interfaces must be on different subnets and routing must be enabled. For example eth0 has ip address 192.168.1.2/24 on subnet 192.168.1.0/24 with 255 ip addresses. Then wlan0 cannot be on the same subnet. You must configure a different subnet, e.g. ip address 192.168.2.2/24 on subnet 192.168.2.0/24 also with 255 ip addresses but different from subnet 192.168.1.0/24. The subnet is given by the bit mask /24. Look at Wikipedia how subnetting works.

You have selected the whole private subnet 192.168.0.0/16 with 65536 ip addresses by bitmask /16 so your both ip addresses are on the same subnet. This cannot work, except you use a bridge. But when using a bridge, slave interfaces eth0 and wlan0 cannot have an ip address. Also Raspberry Pi does not support bridging a client wifi connection. Bridging an access point works.

There is another issue with your router. You should only use one router entry, because it simplifies routing setup. The RasPi can take only one route to the internet at a time.

You told nothing about your local network. Do you need that all devices on wifi and on the wired network are have ip addresses from the same subnet? That's a so called broadcast domain and you need a bridge configuration for it. Or is it possible that wifi devices and wired connected devices have ip addresses from different subnets? Then you can setup routing.

This could be a configuration for routing but I haven't tested it. It is only to show the general idea. In dhcpcd.conf:

interface eth0
static ip_address=192.168.1.2/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface wlan0
static ip_address=192.168.2.2/24
static domain_name_servers=192.168.1.1

or the other way around, depending on your local network and where your router is available.

Enable routing in /etc/sysctl.conf:

# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1

and reboot.

To get an idea about the bridging thing you can look at Setting up a Raspberry Pi as an access point in a standalone network (NAT).

  • Thank-you for your very detailed answer. There is a lot to take in there and I will take a while to do that. What I don't understand is why unplugging my network cable and then plugging it back in "fixes" the problem? – user1464409 Jul 4 at 18:19
  • @user1464409 There cannot be said much without knowing something about your network and without any configuration output, e.g. ip addr and ip route and others. I suggest to use your DHCP server on the network to get ip addresses. This will simplify things. – Ingo Jul 4 at 18:59

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.