1

I have Motion running on my Pi.

I want to be able to access the Motion interface/feed (hosted on <pi ip>:8081) to be accessible both via WiFi and via Ethernet with a static address and DHCP for both the interfaces. I would also prefer to keep them isolated from each other/not have them bridged.

Have configured wlan0 to act as a wireless access point (as give in this guide, but without the Routing/Masquerade).

This worked as expected.

After this I tried doing the same for Ethernet, so I also added a static address for eth0 to /etc/dhcpcd.conf and added entry to enable dnsmasq for eth0 (via a file in etc/dnsmasq.d/).

The static address for eth0 is different from wlan0 and so are the dhcp-range.

I can only access via one of the interfaces at a time. So if I boot up the Pi connected with the Ethernet, I can access Motion on the Pi (via Ethernet). However, access via WLAN fails. On the other hand, with Ethernet unplugged I can access Motion via WLAN.


How do I enable both the Eth and Wlan to work independently with DHCP and static IP on both of them to access Motion on the Pi?

Also, is it possible to have the same static IP address for both the interfaces?


Edit: Output of various commands as asked by @eftshift0:

$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:c3:d7:6b brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:96:82:3e brd ff:ff:ff:ff:ff:ff


$ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:c3:d7:6b brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.1/24 brd 192.168.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::f98e:1b2a:d923:6474/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:96:82:3e brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.2/24 brd 192.168.0.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::496:128:e7ec:f5b0/64 scope link 
       valid_lft forever preferred_lft forever


$ netstat -lntp | grep 8081
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:8081            0.0.0.0:*               LISTEN      -       
  • 1
    Do you want DHCP or static IP? I still don't understand WHY so many Pi users want static IP - other computer users get by without – Milliways Jul 30 '18 at 16:36
  • @Milliways, static IP is to make the Motion interface easily accessible - any user just has to point to a fixed IP without needing to figure out IP addresses. – Kanchu Jul 30 '18 at 16:45
  • What is the output of these commands when you have both interfaces up? ip link show ip addr show ip route show. Then what do you see when you run this? netstat -lntp | grep 8081. You can add the output to your question. – eftshift0 Jul 30 '18 at 17:17
  • 1
    Let me answer one of your questions, at least: Also, is it possible to have the same static IP address for both the interfaces?. The answer is no. Different interfaces need to be set up to different network segments (let alone, IP addresses), unless you know what you are doing. – eftshift0 Jul 30 '18 at 17:19
  • 1
    You want your RPI to act as DHCP server, one for eth0, one for wlan0, right? Is there another DHCP server on one of the subnets, maybe from an internet router? Is there anywhere a connection to the internet? You wrote "The static address for eth0 is different from wlan0 and so are the dhcp-range". Just now that isn't true as ip addr show. Both interfaces are on the same subnet 192.168.0.0/24. – Ingo Jul 30 '18 at 19:00
1

The problem that you are having is that Linux does not like having multiple interfaces on the same subnet. (Another question regarding this.) In its routing table, it will choose one of the interfaces as the "best" route to your local network, so all the other interfaces will end up not seeing any traffic. It is possible to get this configuration to work, but you'll need to set up ARP rules and policy-based routing tables.

I do have to wonder if you need this complicated of a setup though: without bridging, traffic from the two interfaces would never see each other anyways. If you're using the wireless interface as an AP that is completely separated from the wired network, it shouldn't be using the same network address (give it something like 192.168.1.1/24.) That would take care of the issue.

  • OK... Will try that... – Kanchu Jul 31 '18 at 9:07
  • Thank you.... As mentioned in the comments to the question and in your answer, having different range/subnet of IP address and dhcp-range worked! – Kanchu Jul 31 '18 at 16:03
0

If I understand you right your setup is simple to do with systemd-networkd. Nearly the most action is to switch to systemd-networkd. For reference I use Raspbian Stretch Lite 2018-06-27 updated with sudo apt update && sudo apt full-upgrade && sudo reboot. Here is the setup.

Step 1: Setup systemd-networkd

For detailed information look at (1). Here only in short. Execute these commands:

# enable journaling
rpi ~$ sudo -Es
rpi ~# mkdir -p /var/log/journal
rpi ~# systemd-tmpfiles --create --prefix /var/log/journal #ignore warnings (*)

# disable classic networking
rpi ~# systemctl mask networking.service
rpi ~# systemctl mask dhcpcd.service
rpi ~# sudo mv /etc/network/interfaces /etc/network/interfaces~
rpi ~# sed -i '1i resolvconf=NO' /etc/resolvconf.conf

# enable systemd-networkd
rpi ~# systemctl enable systemd-networkd.service
rpi ~# systemctl enable systemd-resolved.service
rpi ~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

(*) You will get one or two confusing warnings "...Cannot set file attribute..." This are not errors and doesn't matter in this case.

Step 2: Configure wpa_supplicant as access point

To configure wpa_supplicant as access point create this file with your settings for country=, ssid=, psk= and maybe frequency= You can just copy and paste this in one block to your command line beginning with cat and including EOF (delimiter EOF will not get part of the file):

rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf <<EOF
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

ap_scan=2
network={
    ssid="RPiNet"
    mode=2
    key_mgmt=WPA-PSK
    psk="password"
    frequency=2437
}
EOF

rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi ~# systemctl enable wpa_supplicant@wlan0.service

Step 3: Setting up network interfaces

Create the following two files to configure eth0 and wlan0.

rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
Address=192.168.0.1/24
DHCPServer=yes
EOF

rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
Address=192.168.1.1/24
DHCPServer=yes
EOF

Reboot.

That's it. Now devices with DHCP enabled get an ip address no matter if they use ethernet or wifi. Each device can connect to the RasPi on ethernet to static ip address 192.168.0.1 and on wifi to static ip address 192.168.1.1. There is no routing between ethernet and wifi, means devices on subnet 192.168.0.0/24 cannot connect to devices on subnet 192.168.1.0/24.


references:
[1] Howto migrate from networking to systemd-networkd with dynamic failover

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.