1

My setup is that I have two raspberry Pis connected directly via ethernet (enxb827eb9c0ecf), let's call them Pi 1 and Pi 2. Pi 1 is also connected wirelessly to my home router. I would like to be able to send a file from Pi 2 to Pi 1 over ethernet and then upload that file online using the WiFi on Pi 1.

I am trying to connect to the internet over wlan0 on Pi 1, but Pi 1 seems to prioritize attempting to connect to the internet via ethernet (where I am not connected to the web but to Pi 2). I am running Raspbian Stretch (so all the tutorials saying to edit /etc/network/interfaces are outdated according to this guide).

I have deleted /etc/ifplugd/action.d/action_wpa so that WiFi on Pi 1 connects fine but it seems to prioritize using the eth0 connection when reaching out to the web. (I can ping both Pis back and forth totally fine)

Note that all the following configurations and details are for Pi 1

/etc/dhcpcd.conf

interface wlan0                                                                                            

static ip_address=192.168.2.143/24                                                                         
static routers=192.168.2.1                                                                                 
static domain_name_servers=192.168.2.1                                                                     

interface enxb827eb9c0ecf                                                                                  

static ip_address=192.168.3.142/24                                                                         

/etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev                                                    
update_config=1                                                                                            
country=CA                                                                                                 

network={                                                                                                  
        ssid="********"                                                                                    
        psk="********"                                                                                     
        key_mgmt=WPA-PSK                                                                                   
}                                                                                                          

ifconfig

     enxb827eb9c0ecf: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500                                 
             inet 192.168.2.142  netmask 255.255.255.0  broadcast 192.168.2.255                            
             inet6 fe80::96ca:62e8:edea:e3e3  prefixlen 64  scopeid 0x20<link>                             
             ether b8:27:eb:9c:0e:cf  txqueuelen 1000  (Ethernet)                                          
             RX packets 594  bytes 37223 (36.3 KiB)                                                        
             RX errors 0  dropped 0  overruns 0  frame 0                                                   
             TX packets 590  bytes 27674 (27.0 KiB)                                                        
             TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                    

     lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536                                                          
             inet 127.0.0.1  netmask 255.0.0.0                                                             
             inet6 ::1  prefixlen 128  scopeid 0x10<host>                                                  
             loop  txqueuelen 1000  (Local Loopback)                                                       
             RX packets 385  bytes 36222 (35.3 KiB)                                                        
             RX errors 0  dropped 0  overruns 0  frame 0                                                   
             TX packets 385  bytes 36222 (35.3 KiB)                                                        
             TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                    

     wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500                                           
             inet 192.168.2.143  netmask 255.255.255.0  broadcast 192.168.2.255                            
             inet6 fe80::df3f:baa8:e17c:aef4  prefixlen 64  scopeid 0x20<link>                             
             ether b8:27:eb:c9:5b:9a  txqueuelen 1000  (Ethernet)                                          
             RX packets 1147  bytes 118792 (116.0 KiB)                                                     
             RX errors 0  dropped 0  overruns 0  frame 0                                                   
             TX packets 667  bytes 102957 (100.5 KiB)                                                      
             TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                    

iwconfig

 lo        no wireless extensions.                                                                         

 wlan0     IEEE 802.11  ESSID:"******"                                                                     
           Mode:Managed  Frequency:2.437 GHz  Access Point: 40:C7:29:4E:4D:FE                              
           Bit Rate=72.2 Mb/s   Tx-Power=31 dBm                                                            
           Retry short limit:7   RTS thr:off   Fragment thr:off                                            
           Power Management:on                                                                             
           Link Quality=70/70  Signal level=-28 dBm                                                        
           Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0                                        
           Tx excessive retries:0  Invalid misc:0   Missed beacon:0                                        

 enxb827eb9c0ecf  no wireless extensions.                                                                  

cat /etc/resolv.conf

 # Generated by resolvconf                                                                                 
 nameserver 192.168.2.1                                                                                    

cat /etc/network/interfaces

 # 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                

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: enxb827eb9c0ecf: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc                                      
 pfifo_fast state UP mode DEFAULT group default qlen 1000                                                  
     link/ether b8:27:eb:9c:0e:cf brd ff:ff:ff:ff:ff:ff                                                    
 3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP                            
 mode DORMANT group default qlen 1000                                                                      
     link/ether b8:27:eb:c9:5b:9a 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: enxb827eb9c0ecf: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP                  
 group default qlen 1000                                                                                   
     link/ether b8:27:eb:9c:0e:cf brd ff:ff:ff:ff:ff:ff                                                    
     inet 192.168.3.142/24 brd 192.168.3.255 scope global enxb827eb9c0ecf                                  
        valid_lft forever preferred_lft forever                                                            
     inet6 fe80::96ca:62e8:edea:e3e3/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:c9:5b:9a brd ff:ff:ff:ff:ff:ff                                                    
     inet 192.168.2.143/24 brd 192.168.2.255 scope global wlan0                                            
        valid_lft forever preferred_lft forever                                                            
     inet6 fe80::df3f:baa8:e17c:aef4/64 scope link                                                         
        valid_lft forever preferred_lft forever                                                            

ip route show

 default via 192.168.2.1 dev wlan0 src 192.168.2.143 metric 303                                            
 192.168.2.0/24 dev wlan0 proto kernel scope link src 192.168.2.143 metric 303                             
 192.168.3.0/24 dev enxb827eb9c0ecf proto kernel scope link src 192.168.3.142 metric 202                   
goldilocks
  • 56,430
  • 17
  • 109
  • 217
Matt
  • 416
  • 2
  • 6
  • 16

1 Answers1

1

You should not have two interfaces connected to the same network... unless you know what you are doing (there are some scenarios where it might be useful or necessary, but you have to mean it for it to make sense and then you have to face problems like this if both interfaces are up at the same time).

Anyway, what happens is that when you try to reach your rpi from some other host (say, ping), traffic will reach the rpi by the interface you intended (by the IP) but, when replying back, the "routing decision engine" might decide to send the response through the other interface. When traffic reaches the originating host the "expected response" is coming from one IP that the originating host didn't expect traffic to come from and so the connection breaks.

eftshift0
  • 660
  • 1
  • 7
  • 10
  • I don't have two interfaces connected to the Internet. My ethernet is connected into the ethernet port of another pi and my wifi is connected to the Internet. I want to be able to send a file from Pi 2 to Pi 1 over ethernet then upload it to the Internet using the wifi on Pi 1 – Matt Jul 04 '18 at 22:02
  • Man.... you are connected to the same network. Both interfaces are on the 192.168.2/24 network. Now.... if you didn't _mean_ for it to be that way(as in, you actually want them to be two separate networks.... one for the rpis to see each other and the other one to connect to another network with a router that will allow you to reach internet) then you should set two different network segments. One 192.168.2/24 and the other 192.168.3/24 (or something like that... you are allowed to go artistic here). That way the rpi won't be confused and will know through which interface to reach your router. – eftshift0 Jul 04 '18 at 22:16
  • Point taken. I had misread your initial comment. I thought since I didn't specify a default gateway for the Eth0 port that it wouldn't try to connect to the router – Matt Jul 04 '18 at 22:20
  • You are actually "correct" in the sense that you are not physically connected to the same network. But, to the rpi, both interfaces are connected to the same network segment and that's where the problem is. It's probably deciding to reach your router (192.168.2.1) through the eth0 interface instead of the wifi and the root cause is that you are setting up overlapping network segments for two different network. – eftshift0 Jul 04 '18 at 22:30
  • If I have 2 networks running from one RPI how do I control which network I am pinging from (I.e. How does it know to use wifi to ping google.com and ethernet to ping the local pi connected via ethernet)? – Matt Jul 04 '18 at 22:31
  • The things is that once you set up two different network segments _and_ specifying what the default gateway is (192.168.2.1 in 192.168.2.0/24 segment) then it will know that every single time it has to reach a computer that is outside of the two network segments that you set it up to use, then it will send that traffic to the default gateway for it to take care of said traffic... and given that your route actually knows how to reach whatever IP you want to reach on internet, then the connections will be established correctly. – eftshift0 Jul 04 '18 at 22:38
  • Ok so I hope I've interpreted what you are saying correctly... – Matt Jul 04 '18 at 22:46
  • I reconfigured /etc/dhcpcd.conf on Pi 1 to say the following: `interface wlan0 static ip_address=192.168.2.143/24 static routers=192.168.2.1 static domain_name_servers=192.168.2.1 interface enxb827eb9c0ecf static ip_address=192.168.3.142/24` and on Pi 2 /etc/dhcpcd.conf says the following: `interface eth0 static ip_address=192.168.3.151/24` I rebooted both Pis and still can't connect to the internet on Pi 1 – Matt Jul 04 '18 at 22:48
  • Ok..... environment has changed quite a bit then. I think you should update your question with the current configuration _and_ add the output of these commands: `ip link show` `ip addr show` `ip route show` – eftshift0 Jul 04 '18 at 22:50
  • Is standard practice to edit this question or fully repost it as a new question? Sorry I'm a total noob at this – Matt Jul 04 '18 at 22:52
  • Hmm.... its a fair question. I don't think the problem has changed, actually. Maybe add the updates _after_ the original question so that people can follow through (explaining what happened before the specifics of the updated configuration?). – eftshift0 Jul 04 '18 at 22:59
  • Ok clarified the question a lot and updated everything as you suggested. – Matt Jul 04 '18 at 23:12
  • Ok.... so, took a look at the updated information. So... on the rpi you now have 2 different network segments, have the default gateway set up on the wifi network. So.... can you ping the default gateway? Can you ping the other rpi? – eftshift0 Jul 04 '18 at 23:18
  • Uhh so I just tried it again and it's totally working fine now. I'm honestly not sure why it suddenly started working - but thanks so much for taking the time to help man, really appreciate your patience. It's possible I typo'd the default gateway when I pinged it after following your initial suggestion. – Matt Jul 04 '18 at 23:25
  • Welcome! But you better start upvoting stuff! :-D – eftshift0 Jul 04 '18 at 23:26
  • I did but it won't display since I don't have enough reputation to upvote yet :P – Matt Jul 04 '18 at 23:35