mdsousa
Posts: 39
Joined: Wed Feb 12, 2014 4:29 pm
Location: New Hampshire
Contact: Website

Problem ssh'ing to PI directly connected to ubuntu laptop

Wed Apr 09, 2014 2:09 am

Hi

I am not able to ssh into my PI that is directly connected to the ethernet port of my ubuntu 12.04 laptop. The PI has 2014-01-07 wheezy installed.

The laptop is wirelessly (wifi) connected to the internet. I have set the Network->Wired->Options->IPv4(tab) to 'Shared to other computers'.

When the PI is connected, ifconfig shows inet addr:10.42.0.1 (there is not an inet addr in the eth0 section before the PI is connected).

With the PI connected, I can ping 10.42.0.1

Code: Select all

mike@mike-Aspire-7535:~$ ping 10.42.0.1
PING 10.42.0.1 (10.42.0.1) 56(84) bytes of data.
64 bytes from 10.42.0.1: icmp_req=1 ttl=64 time=0.281 ms
64 bytes from 10.42.0.1: icmp_req=2 ttl=64 time=0.148 ms
64 bytes from 10.42.0.1: icmp_req=3 ttl=64 time=0.060 ms
but when I try to ssh, I get the following:

Code: Select all

mike@mike-Aspire-7535:~$ ssh -X pi@10.42.0.1
ssh: connect to host 10.42.0.1 port 22: Connection refused
I have tried setting a static ip address (10.42.0.1) in the PI's etc/network/interfaces file, but that did not help.

I want to run the PI headless without a separate monitor/keyboard/mouse (I actually do not have these items). I wish to work on it through this headless configuration, connected to the the Ethernet port on my laptop.

Any suggestions would be much appreciated.

Thanks...

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Problem ssh'ing to PI directly connected to ubuntu lapto

Wed Apr 09, 2014 2:19 am

mdsousa wrote:... When the PI is connected, ifconfig shows inet addr:10.42.0.1 (there is not an inet addr in the eth0 section before the PI is connected)...
Is this from running ifconfig on your laptop or the Raspberry Pi itself? I suspect 10.42.0.1 is the IP address of your laptop. The Raspberry Pi will have a different 10.42.0.x IP address.

mdsousa
Posts: 39
Joined: Wed Feb 12, 2014 4:29 pm
Location: New Hampshire
Contact: Website

Re: Problem ssh'ing to PI directly connected to ubuntu lapto

Wed Apr 09, 2014 2:30 am

The laptop is given an ip address from the wireless router, ifconfig -a is executed on the laptop (I cannot ssh or telnet to the PI to run anything yet)
ifconfig -a on the laptop shows the laptop's address as:

Code: Select all

wlan0
inet addr:192.168.1.31
The eth0 is not set until the PI is attached by ethernet cable.
before PI is attached:

Code: Select all

eth0      Link encap:Ethernet  HWaddr 00:26:2d:5b:2c:4f  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:16 
after PI is attached:

Code: Select all

eth0      Link encap:Ethernet  HWaddr 00:26:2d:5b:2c:4f  
          inet addr:10.42.0.1  Bcast:10.42.0.255  Mask:255.255.255.0
          inet6 addr: fe80::226:2dff:fe5b:2c4f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:552 errors:0 dropped:0 overruns:0 frame:0
          TX packets:715 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:47190 (47.1 KB)  TX bytes:77374 (77.3 KB)
          Interrupt:16 
telnet fails also:

Code: Select all

mike@mike-Aspire-7535:~$ telnet pi@10.42.0.1
telnet: could not resolve pi@10.42.0.1/telnet: Name or service not known

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Problem ssh'ing to PI directly connected to ubuntu lapto

Wed Apr 09, 2014 2:56 am

mdsousa wrote:The laptop is given an ip address from the wireless router, ifconfig -a is executed on the laptop (I cannot ssh or telnet to the PI to run anything yet)...
Once you connect the Raspberry Pi to your laptop using an ethernet cable, the laptop has two IP addresses. The first, 192.168.1.31, is the IP address given by your wireless router. The second, 10.42.0.1, belongs to the network created between the Raspberry Pi and your laptop. However, this is the IP address of your laptop on this network, not he IP address of the Raspberry Pi. You need to find the IP address of the Raspberry Pi. The simplest way to do this would be to connect a monitor to the Raspberry Pi as it is displayed on the console. As you have said this isn't an option for you, you will need to find the IP address another way. First you could guess. My guess would be 10.42.0.2, I could be wrong. Alternatively you could try using the arp-scan command. You may need to install this on your laptop. Then use the command

Code: Select all

sudo arp-scan --interface=eth0 -localnet
to find the IP address of the Raspberry Pi.

mdsousa
Posts: 39
Joined: Wed Feb 12, 2014 4:29 pm
Location: New Hampshire
Contact: Website

Re: Problem ssh'ing to PI directly connected to ubuntu lapto

Wed Apr 09, 2014 3:02 am

Thanks for the inputs AndyD. I've installed and ran arp-scan

Code: Select all

mike@mike-Aspire-7535:~$ sudo arp-scan --interface=eth0 -localnet
Interface: eth0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.8.1 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)

0 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.8.1: 256 hosts scanned in 1.360 seconds (188.24 hosts/sec). 0 responded
mike@mike-Aspire-7535:~$
doesn't look like much is going on...

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Problem ssh'ing to PI directly connected to ubuntu lapto

Wed Apr 09, 2014 3:18 am

mdsousa wrote:...doesn't look like much is going on...
Agreed! I have not tried this type of connection myself, so I am unsure of the next step. It appears that your laptop at least is sensing a network on ETH0 and assigning an IP address for the adapter. It would also appear that the Raspberry Pi has not been assigned an IP address. I would be tempted to power cycle the Raspberry Pi while leaving the Raspberry Pi connected to your laptop. Give it a minute or two to boot up and then try the arp-scan again.

User avatar
rpdom
Posts: 17976
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Problem ssh'ing to PI directly connected to ubuntu lapto

Wed Apr 09, 2014 6:05 am

As a guess, I would assume that your Pi is given an address of 10.42.0.2 as the next one up from the laptop's 10.42.0.1.

Try ping -c 4 10.42.0.2 and if that works, ssh pi@10.42.0.2

There is possibly a log file for the Ubuntu Connection Sharing that will show IP addresses being allocated, which would be under /var/log/ somewhere, but I don't know which. If the ICS uses dnsmasq for DNS/DHCP (which is likely), it should show in daemon.log.

mdsousa
Posts: 39
Joined: Wed Feb 12, 2014 4:29 pm
Location: New Hampshire
Contact: Website

Re: Problem ssh'ing to PI directly connected to ubuntu lapto

Wed Apr 09, 2014 4:42 pm

Ping to 10.42.0.2 didn't work:
mike@mike-Aspire-7535:~$ ping 10.42.0.2

Code: Select all

PING 10.42.0.2 (10.42.0.2) 56(84) bytes of data.
From 10.42.0.1 icmp_seq=1 Destination Host Unreachable
From 10.42.0.1 icmp_seq=5 Destination Host Unreachable

I disconnected the PI and reconnected while tailing syslog. This is the output (sorry for the volume of sutff) from syslog as soon as the PI was connected:

Code: Select all

Apr  9 12:28:35 mike-Aspire-7535 kernel: [773411.723791] tg3 0000:03:00.0: eth0: Link is up at 100 Mbps, full duplex
Apr  9 12:28:35 mike-Aspire-7535 kernel: [773411.723810] tg3 0000:03:00.0: eth0: Flow control is on for TX and on for RX
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> (eth0): carrier now ON (device state 20)
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> (eth0): device state change: unavailable -> disconnected (reason 'carrier-changed') [20 30 40]
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Auto-activating connection 'Connection Sharing'.
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) starting connection 'Connection Sharing'
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> (eth0): device state change: disconnected -> prepare (reason 'none') [30 40 0]
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 1 of 5 (Device Prepare) scheduled...
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 1 of 5 (Device Prepare) started...
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 2 of 5 (Device Configure) scheduled...
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 1 of 5 (Device Prepare) complete.
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 2 of 5 (Device Configure) starting...
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> (eth0): device state change: prepare -> config (reason 'none') [40 50 0]
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 2 of 5 (Device Configure) successful.
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 3 of 5 (IP Configure Start) scheduled.
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 2 of 5 (Device Configure) complete.
Apr  9 12:28:35 mike-Aspire-7535 kernel: [773411.726282] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 3 of 5 (IP Configure Start) started...
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> (eth0): device state change: config -> ip-config (reason 'none') [50 70 0]
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 5 of 5 (IPv4 Configure Commit) scheduled...
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 3 of 5 (IP Configure Start) complete.
Apr  9 12:28:35 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 5 of 5 (IPv4 Commit) started...
Apr  9 12:28:35 mike-Aspire-7535 avahi-daemon[876]: Joining mDNS multicast group on interface eth0.IPv4 with address 10.42.0.1.
Apr  9 12:28:35 mike-Aspire-7535 avahi-daemon[876]: New relevant interface eth0.IPv4 for mDNS.
Apr  9 12:28:35 mike-Aspire-7535 avahi-daemon[876]: Registering new address record for 10.42.0.1 on eth0.IPv4.
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> (eth0): writing resolv.conf to /sbin/resolvconf
Apr  9 12:28:36 mike-Aspire-7535 dnsmasq[1159]: setting upstream servers from DBus
Apr  9 12:28:36 mike-Aspire-7535 dnsmasq[1159]: using nameserver 192.168.1.1#53
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Policy set '12FX05004871' (wlan0) as default for IPv4 routing and DNS.
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Executing: /sbin/iptables --table filter --insert INPUT --in-interface eth0 --protocol tcp --destination-port 53 --jump ACCEPT
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Executing: /sbin/iptables --table filter --insert INPUT --in-interface eth0 --protocol udp --destination-port 53 --jump ACCEPT
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Executing: /sbin/iptables --table filter --insert INPUT --in-interface eth0 --protocol tcp --destination-port 67 --jump ACCEPT
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Executing: /sbin/iptables --table filter --insert INPUT --in-interface eth0 --protocol udp --destination-port 67 --jump ACCEPT
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Executing: /sbin/iptables --table filter --insert FORWARD --in-interface eth0 --jump REJECT
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Executing: /sbin/iptables --table filter --insert FORWARD --out-interface eth0 --jump REJECT
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Executing: /sbin/iptables --table filter --insert FORWARD --in-interface eth0 --out-interface eth0 --jump ACCEPT
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Executing: /sbin/iptables --table filter --insert FORWARD --source 10.42.0.0/255.255.255.0 --in-interface eth0 --jump ACCEPT
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Executing: /sbin/iptables --table filter --insert FORWARD --destination 10.42.0.0/255.255.255.0 --out-interface eth0 --match state --state ESTABLISHED,RELATED --jump ACCEPT
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Executing: /sbin/iptables --table nat --insert POSTROUTING --source 10.42.0.0/255.255.255.0 ! --destination 10.42.0.0/255.255.255.0 --jump MASQUERADE
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> Starting dnsmasq...
Apr  9 12:28:36 mike-Aspire-7535 NetworkManager[970]: <info> (eth0): device state change: ip-config -> activated (reason 'none') [70 100 0]
Apr  9 12:28:36 mike-Aspire-7535 dnsmasq[26644]: started, version 2.59 cachesize 150
Apr  9 12:28:36 mike-Aspire-7535 dnsmasq[26644]: compile time options: IPv6 GNU-getopt DBus i18n DHCP TFTP conntrack IDN
Apr  9 12:28:36 mike-Aspire-7535 dnsmasq-dhcp[26644]: DHCP, IP range 10.42.0.10 -- 10.42.0.100, lease time 1h
Apr  9 12:28:36 mike-Aspire-7535 dnsmasq[26644]: reading /etc/resolv.conf
Apr  9 12:28:36 mike-Aspire-7535 dnsmasq[26644]: using nameserver 127.0.0.1#53
Apr  9 12:28:36 mike-Aspire-7535 dnsmasq[26644]: cleared cache
Apr  9 12:28:37 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) successful, device activated.
Apr  9 12:28:37 mike-Aspire-7535 NetworkManager[970]: <info> Activation (eth0) Stage 5 of 5 (IPv4 Commit) complete.
Apr  9 12:28:37 mike-Aspire-7535 dbus[788]: [system] Activating service name='org.freedesktop.nm_dispatcher' (using servicehelper)
Apr  9 12:28:37 mike-Aspire-7535 dbus[788]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr  9 12:28:37 mike-Aspire-7535 avahi-daemon[876]: Joining mDNS multicast group on interface eth0.IPv6 with address fe80::226:2dff:fe5b:2c4f.
Apr  9 12:28:37 mike-Aspire-7535 avahi-daemon[876]: New relevant interface eth0.IPv6 for mDNS.
Apr  9 12:28:37 mike-Aspire-7535 avahi-daemon[876]: Registering new address record for fe80::226:2dff:fe5b:2c4f on eth0.*.
Apr  9 12:28:45 mike-Aspire-7535 ntpdate[26677]: adjust time server 91.189.89.199 offset 0.209462 sec
Apr  9 12:28:46 mike-Aspire-7535 kernel: [773422.328033] eth0: no IPv6 routers present
Apr  9 12:28:49 mike-Aspire-7535 kernel: [773425.021392] tg3 0000:03:00.0: eth0: Link is down
Apr  9 12:28:49 mike-Aspire-7535 NetworkManager[970]: <info> (eth0): carrier now OFF (device state 100, deferring action for 4 seconds)
Apr  9 12:28:50 mike-Aspire-7535 kernel: [773426.656972] tg3 0000:03:00.0: eth0: Link is up at 100 Mbps, full duplex
Apr  9 12:28:50 mike-Aspire-7535 kernel: [773426.656991] tg3 0000:03:00.0: eth0: Flow control is on for TX and on for RX
Apr  9 12:28:50 mike-Aspire-7535 NetworkManager[970]: <info> (eth0): carrier now ON (device state 100)
Make any sense of this?

Thanks...

User avatar
rpdom
Posts: 17976
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Problem ssh'ing to PI directly connected to ubuntu lapto

Wed Apr 09, 2014 4:56 pm

From that log I can see that Ubuntu is definitely using Dnsmasq to handle the local DNS and DHCP.

The next step is to see what IP address it has assigned to your Pi. The easiest way to do this is to connect a screen and keyboard to the Pi and run /sbin/ifconfig eth0 on it. This will show the address. If you can't do that on the Pi, then try looking at /var/log/daemon.log on your laptop after connecting the Pi and see if dnsmasq has written anything useful in there. You should see something about DHCPREQUEST(eth0), DHCPOFFER(eth0) and DHCPACK(eth0) (assuming the logging is enabled).

suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Re: Problem ssh'ing to PI directly connected to ubuntu lapto

Wed Apr 09, 2014 6:44 pm

Primitive I know, but if you run this on the laptop it will send one ping with a quick timeout to each IP in the same range - the one that comes back is the Pi?

Code: Select all

for i in `seq 2 255` ; do ping -w 1 -c 1 10.42.0.$i ; done

mdsousa
Posts: 39
Joined: Wed Feb 12, 2014 4:29 pm
Location: New Hampshire
Contact: Website

Re: Problem ssh'ing to PI directly connected to ubuntu lapto

Wed Apr 09, 2014 7:24 pm

rpdom

Sounds like this is what you're asking for:

Code: Select all

Apr  9 15:13:56 mike-Aspire-7535 dnsmasq-dhcp[27258]: DHCPDISCOVER(eth0) 10.42.0.19 b8:27:eb:e2:52:db 
Apr  9 15:13:56 mike-Aspire-7535 dnsmasq-dhcp[27258]: DHCPOFFER(eth0) 10.42.0.19 b8:27:eb:e2:52:db 
Apr  9 15:13:56 mike-Aspire-7535 dnsmasq-dhcp[27258]: DHCPREQUEST(eth0) 10.42.0.19 b8:27:eb:e2:52:db 
Apr  9 15:13:56 mike-Aspire-7535 dnsmasq-dhcp[27258]: DHCPACK(eth0) 10.42.0.19 b8:27:eb:e2:52:db raspberrypi
I tried the 10.42.0.19 and it worked ... whew...:)

Kudos and thanks...

User avatar
hanzelpeter
Posts: 75
Joined: Mon Jul 09, 2012 11:56 am

Re: Problem ssh'ing to PI directly connected to ubuntu laptop

Sat Aug 29, 2020 8:08 am

Hello.

If someone else is trying this steps.
I have LUbuntu 18.04 host and was unable to connect to RPI.
After 1 hour of googling and trying I found in journactl that dnsmasq binary is missing.

So simple apt-get install dnsmasq fixed the problem.
That I was able to connect to RPI

Return to “Beginners”