One IP address when wifi and ethernet connected

Thanks for the great work so far. I’m new to Linux and the Raspberry Pi 2. I’m using an Edimax EW-7811un wifi adapter which is working fine and easily connects to the router.

I would like to have an ethernet ready TV to connect to the internet wirelessly. My router is LTE so I can’t place it next to the TV (poor LTE signal).

I followed the following guide.

However, I have a problem. Whenever I connect the ethernet cable to the RP2 the wifi adapter shuts down. If I subsequently disconnect ethernet, wifi goes back on. It does seem to be an automated process.

I’ve looked around and people seem to point to three solutions all of which haven’t worked for me: a) stable power – I have a 2A adapter so not an issue; b) allow-hotplug eth0 – I had already included this command in /etc/network/interfaces; c) remove ifplugd – I didn’t have this command installed to begin with. I then installed it and purged it to see if it would make any difference. It didn’t.

Also, connecting the RP to my laptop uses an IP address different from the one I assigned manually. I had assigned a static address 192.168.2.1 for eth0 but when connected to the laptop the ethernet is assigned an IP of 169.254.42.120. It seems that all the changes made were not committed but I may not be fulling grasping the issue.

I’m running the latest alpha4 OSMC for a raspberry pi 2. As I’m new to the Pi I’m not sure which files I should look at for automated processes. Any ideas on how to keep the wifi connected when the ethernet cable is connected as well?

Thanks

In ConnMan we have specified this as a ‘SinglePreferredTechnology’. In /etc/connman.conf, removed the line.

Source: https://github.com/samnazarko/osmc/blob/master/package/network-osmc/files/etc/connman.conf

Thanks a ton! Changed the command in connman.conf and it worked fine. :smile:

EDIT: scratch that. When I reboot the RP2 only the ethernet connection is live. If I take the cable out and put it back on again then the wifi stays on. Strange behaviour.

I only seem to have only one live IP address at a time, depending on how I prioritise on /etc/connman.conf. The Pi doesn’t give two IP addresses at the same time. The ifconfig command confirms this, either wifi or ethernet are attributed an IP address but not both.

There must be another file which is limiting IP address setting when both ethernet and wifi are on. Any thoughts?

First of all the guide you follow is not enough to make this work this way. In order for your RPi to grant IP addresses to other devices you should install and configure DHCP server (eg. isc-dhcp-server). Otherwise you’ll have to configure address manually (on your laptop or TV).

About the connectivity, to proof that you configured everything correctly, try to make this work by manually assigning IP addresses. Something like:

ifconfig eth0 up
ifconfig eth0 192.168.2.1 netmask 255.255.255.0
ifconfig wlan0 up
ifconfig wlan0 192.168.0.10 netmask 255.255.255.0
route add default gw 192.168.0.1

Then connect your laptop using ethernet cable, configure network card ipv4 address to 192.168.2.2 with 255.255.255.0 netmask and 192.168.2.1 gateway. After that you should be able to ping your Rpi within your new “inside” network.
Also you should be able to access the rest of your network devices and the internet from at least your RPi, or even from your laptop/TV if you have SNAT and routing properly configured.

[EDIT: You have to change above addresses and/or interface names to match your network schema of course]

Thanks Mariusz. I’ll give it a try when I get home from work.

The tutorial actually includes a configuration for DHCP with isc-dhcp-server. However, the issue I was encountering was that I couldn’t get two IP addresses assigned at the same time. I’ll configure eth0 manually instead and see if it works.

Thanks for your help. Being a beginner I feel like I’m trying to discuss a Norwegian soap opera with a Korean…

Tried the instructions as suggested. The TV can connect to the Pi with the right IP address (192.168.2.2) but I can’t seem to get internet to work. Also, I have to attribute the IP address to eth0 manually as the instruction in interfaces does not make it work. An ifconfig eth0 shows the eth0 without any inet addr. So I have two problems: 1) get eth0 to automatically have the IP address as included in the /etc/network/interfaces file; and 2) route internet traffic to eth0.

I’ve been playing around with the files but seem stuck. Sorry, but I’m new to the Pi.

Thanks

My /etc/network/interfaces cat

auto lo
iface lo inet loopback

 iface eth0 inet static
  address 192.168.2.1
  network 192.168.2.0
  netmask 255.255.255.0
  broadcast 192.168.2.255
  gateway 192.168.2.1

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.15.6
netmask 255.255.255.0
broadcast 192.168.15.255
gateway 192.168.15.1
wpa-ssid "myrouter"
wpa-psk "mypassword"
wpa-group TKIP CCMP
wpa-key-mgmt WPA-PSK

My route -n output

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.15.1    0.0.0.0         UG    0      0        0 wlan0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.15.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
192.168.15.1    0.0.0.0         255.255.255.255 UH    0      0        0 wlan0

My iptables cat

# Generated by iptables-save v1.4.21 on Thu Feb 19 18:52:26 2015
*mangle
:PREROUTING ACCEPT [225:24969]
:INPUT ACCEPT [224:24812]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [109:15668]
:POSTROUTING ACCEPT [109:15668]
COMMIT
# Completed on Thu Feb 19 18:52:26 2015
# Generated by iptables-save v1.4.21 on Thu Feb 19 18:52:26 2015
*nat
:PREROUTING ACCEPT [2:225]
:INPUT ACCEPT [1:68]
:OUTPUT ACCEPT [3:228]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o wlan0 -j SNAT --to-source 192.168.15.6
COMMIT
# Completed on Thu Feb 19 18:52:26 2015
# Generated by iptables-save v1.4.21 on Thu Feb 19 18:52:26 2015
*filter
:INPUT ACCEPT [59:6724]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [30:5664]
-A FORWARD -i eth0 -o wlan0 -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
COMMIT
# Completed on Thu Feb 19 18:52:26 2015

My iptables -t nat -L output

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
SNAT       all  --  anywhere             anywhere             to:192.168.15.6

My dhcpd.conf cat

# Configuration file for ISC dhcpd for Debian
#
#
ddns-update-style none;
option domain-name "osmc.local";
option domain-name-servers 192.168.15.1;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
#let the server know about network 192.168.15.0 but offer no service here
subnet 192.168.15.0 netmask 255.255.255.0{
}
#configure service for network 192.168.2.0 (the ethernet port)
subnet 192.168.2.0 netmask 255.255.255.0 { 
 range 192.168.2.10 192.168.2.50;
 option routers 192.168.2.1;
}

Add

auto eth0

before iface eth0

you can remove lines with “network” and “broadcast” They are irrelevant.

You can’t have 2 gateways. Leave only the upstream one: 192.168.15.1, remove the line with the other.

This suggest that you have configured eth0 to search for address from DHCP - you should unconfigure it.
try command:

ip addr

If you don’t have it try to install package with that tool. It will show you exactly what ip addresses are set on which interface. It is much more verbose and exact then ifconfig.

About iptables:
If you are accepting packets by default (“FORWARD ACCEPT”), you don’t have to explicitly add any “-A FORWARD” accept rules.

The NAT rules seem fine, but it should be:

-A POSTROUTING -s eth0 -o wlan0 -j SNAT --to-source 192.168.15.6

About DHCP, you should try on some DHCP related sites and also see what it is logged to /var/log/messages or syslog when you start dhcpd deamon and then when you connect PC/TV. You may have to add some debbugging options to server configuration to see more verbose logs.

[Edit: AFAIK OSMC uses some network manager and for the /etc/interfaces to work as expected you may have to turn that network manager OFF. I don’t know how to do it though - I am new to OSMC]

{Edit 2: Also make sure you enabled routing. See here and try to set it accordingly on your system. I don’t have access to osmc right now so I cannot check the exact commands]

Thanks. I’ve added auto eth0 to interfaces. I’ve also removed the 2nd gateway, don’t know how it got there in the first place as it wasn’t there before… I’ve also revised the iptables as suggested, removing “-A FORWARD” accept rules and changing -A POSTROUTING as above.

My ip addr outputs:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    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,DYNAMIC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:06:58:2c brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.1/24 brd 192.168.2.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::ba27:ebff:fe06:582c/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 74:da:38:00:77:1a brd ff:ff:ff:ff:ff:ff
    inet 192.168.15.6/24 brd 192.168.15.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::76da:38ff:fe00:771a/64 scope link 
       valid_lft forever preferred_lft forever

Seems to be OK, I guess. The TV is configured to a manual IP 192.168.2.2. I’ve also had enabled the IP forwarding as suggested in your 2nd edit. Still no luck, the TV connects to the Pi ethernet but no connection to the internet. Somewhere down the line the packets don’t seem to be flowing from eth0 to wlan0. I’ve checked the files above again and they seem in line with tutorial on NAT and iptables but somewhere down the line there’s a failure. I don’t have any messages file in the /var/log, don’t know where else to look at to inspect for NAT between eth0 wlan0.

Thanks for your help so far, I wouldn’t have gotten this far without it. I’ll have a look again tomorrow, this is driving me nuts…

I think maybe deleting the line was not working because SinglePreferredTechnology may default to true. Try keeping the line and setting it to false

S

Make sure:

sysctl net.ipv4.ip_forward

returns:

net.ipv4.ip_forward = 1

Then from the RPi try:

ping 192.168.2.2
ping 192.168.15.1

Both should work

Make sure you have configured on TV:
IP 192.168.2.2/255.255.255.0
Default Gateway: 192.168.2.1

on RPi:

netstat -rn
iptables -v -L
iptables -t nat -v -L

paste outputs

If unsuccessful - connect a PC instead of TV just to make sure and repeat the ping tests

It is really basic networking 1.0.1. If you have network connectivity to both networks linux should automatically act as router. All you need is sysctl command. And with SNAT it should do what you want.
Of course keeping those settings after reboot is another thing.

If it still doesn’t work do the following:
if no tcpdump, install it:

sudo apt-get -y install tcpdump

On RPi:

sudo tcpdump -i eth0 icmp

On PC (windows) acting as TV:

ping 192.168.2.1

if on linux do:

ping -c 4 192.168.2.1

Paste results of the tcpdump. Stop it (Ctrl+c).

Now on RPi:

sudo tcpdump -i wlan0 icmp

and from the PC:

ping 8.8.8.8

again paste the outputs.

OK. To make sure my files weren’t fudged somehow I’ve reinstalled OSMC alpha 4 on the Pi 2.

I was surprised to discover that under /etc/network there wasn’t any interfaces file. I have the router to manually allocate an ip address to the pi wifi (EW-7811n) so perhaps that’s why I can get ssh via wifi with ease. Also, ir raises questions as to whether the interfaces file in /etc/network actually does anything. Allocating a static IP for eth0 doesn’t work, I have to do it manually all the time.

I also notices that iptables command wasn’t installed, had to install it manually. Does the pre-up iptables command also requires some sort of installation?

The ip addr command also had to be manually installed. So it seems that there are a few commands that need manually installation. I may be missing some to get it all to work or perhaps /etc/network/interfaces file doesn’t do anything.

Regarding your outputs, sysctl returns net.ipv4.ip_forward = 1. From the pi, ping 192.168.2.2 and ping 192.168.15.1 both work fine there’s no packet loss. TV has a manual IP set for ethernet so in theory it should work.

netstat -rn output

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.15.1    0.0.0.0         UG        0 0          0 wlan0
192.168.2.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
192.168.15.0    0.0.0.0         255.255.255.0   U         0 0          0 wlan0
192.168.15.1    0.0.0.0         255.255.255.255 UH        0 0          0 wlan0

iptables -v -L output

Chain INPUT (policy ACCEPT 366 packets, 36259 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  eth0   wlan0   anywhere             anywhere            
    0     0 ACCEPT     all  --  wlan0  eth0    anywhere             anywhere             state RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT 220 packets, 25304 bytes)
 pkts bytes target     prot opt in     out     source               destination 

iptables -t nat -v -L output

Chain PREROUTING (policy ACCEPT 9 packets, 2048 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 9 packets, 2048 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 50 packets, 4245 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 9 packets, 524 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  110  9004 SNAT       all  --  any    wlan0   anywhere             anywhere             to:192.168.15.6
    0     0 SNAT       all  --  any    wlan0   anywhere             anywhere             to:192.168.15.6

The eth0 tcpdump on the pi and ping from laptop returns

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel

However, other times it returned

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
^C20:15:58.071481 IP Brunos-MacBook-Pro.local > osmc.local: ICMP host 192.168.2.11 unreachable, length 36

1 packet captured
2 packets received by filter
1 packet dropped by kernel

The wlan0 tcpdump returns

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan0, link-type EN10MB (Ethernet), capture size 262144 bytes
^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel
1 packet dropped by interface

On all occasions I have to halt the tcpdump on the pi with ctrl+C.

So, overall perhaps interfaces file doesn’t do anything. I have to setup eth0 IP address and iptables manually after rebooting. Somehow the routing is perhaps controlled by another file/command which I’m not sure about or maybe I’m missing some commands which are not included in the default OSMC installation.

We use ConnMan, so no /etc/network…

I am not sure of the question anymore as we seem to have deviated. This seems a different issue so please start a new thread.

Thanks Sam, I’ll start a new one.