coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

[Solved] Cannot SSH to zero w AP thru ip of hostapd

Sun Oct 15, 2017 6:38 pm

I have followed mostly this http://imti.co/post/145442415333/raspbe ... station-ap to built an Access Point + wireless client. It is working and I am going to add other servers to it as well. However.

My connection is: Internet - router - RPi - Android phone.
wlan0 of RPi get ip from the router.
uap0 of RPi has fixed ip 192.168.50.1, and assign ip to the phone(s).
tested the phone can get access to internet.

I can ssh to RPi's wlan0 ip thru router. However, I can't do it from the phone thru ip of uap0. I have tried JuiceSSH & Termius.
Okay, I can still use the ip of wlan0 to ssh in thru the AP connection. However, I may not always have the ip of wlan0 available when I am not with my router. I want to ssh pi@192.168.50.1.

the iptables rule in my setup is

Code: Select all

iptables -t nat -A POSTROUTING -s 192.168.50.0/24 ! -d 192.168.50.0/24 -j MASQUERADE
Have I totally missed something important? Or, I have to make some changed on sshd.conf? Or, the above iptables rule has to be modified? Or, ...

Please help

-------------- edited
Just add [Solved] to Subject
Last edited by coopi on Mon Oct 16, 2017 3:46 am, edited 2 times in total.

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Cannot SSH to zero w AP thru ip of hostapd

Sun Oct 15, 2017 9:53 pm

I just checked with my setup from the other thread, and I can ssh into the ap ip.
viewtopic.php?f=36&t=195216
I'm using a RPi3, but the same setup should apply to a Zero.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: Cannot SSH to zero w AP thru ip of hostapd

Mon Oct 16, 2017 3:41 am

SurferTim wrote:
Sun Oct 15, 2017 9:53 pm
I just checked with my setup from the other thread, and I can ssh into the ap ip.
viewtopic.php?f=36&t=195216
I'm using a RPi3, but the same setup should apply to a Zero.
Million thanks for your hints.

Just like declaring a variable w/o assigning any value to it when programming Arduino. I put into /etc/dhcpcd.conf a single line

Code: Select all

interface uap0
reboot, and it just works amazingly.

btw, systemctl status dhcpcd still reports a "failed", but it works for the part I need behind.

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Mon Oct 16, 2017 10:36 am

If you set up the AP as I posted in the other thread, the dhcpcd service would not fail.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Mon Oct 16, 2017 11:16 am

SurferTim wrote:
Mon Oct 16, 2017 10:36 am
If you set up the AP as I posted in the other thread, the dhcpcd service would not fail.
Mine is a zero w. To get AP and wireless client work together, I need them use the same channel. As channel# varies from hotspot ro hotspot, I have my hostapd.conf file be built (by script) during boot so as to capture the channel# used at that instance. I have also made some extra scripts (per "profile") for my easy personal usage. It will be quite some work if I follow your version line by line; and merely to get rid of a pseudo failed message is not a reason attractive enough. ;)

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Mon Oct 16, 2017 11:23 am

Mine doesn't have a problem with different channels on the client. Just tested it.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Tue Oct 17, 2017 3:08 am

SurferTim wrote:
Mon Oct 16, 2017 11:23 am
Mine doesn't have a problem with different channels on the client. Just tested it.
I wonder, so I test. It does not work.

I use a spare tf card, fresh install latest raspbian lite. I use my tomatousb router to monitor live connectivity of wlan0. Instead of reboot twice, I did much more times. I found wpa_supplicant.service is not enabled, I enabled it manually. Then, I found wlan0 get connected for awhile (on tomatousb screen) during boot process and dropped forever.

dhcpcd.service is now active, but still with a red line
uap0: IAID conflicts with one assigned to wlan0
I am further surprised because even I manually match the channel#, that setup still deliver the same failure symptom.
Lucky me I have not the desire to remove the pseudo failed message on dhcpcd of my current setup.

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Tue Oct 17, 2017 10:28 am

I tried a fresh install yesterday, and followed the instructions I posted. I tested it all day yesterday, and it worked flawlessly. I can imagine if there were several users connected, it wouldn't perform as well.

I'm using a RPi3, so maybe there is a difference. I'm planning on purchasing a Zero W soon. I'll test this setup on it.

Edit: Are you certain you followed this part?

Open /etc/wpa_supplicant/wpa_supplicant.conf with a text editor.
Save as /etc/wpa_supplicant/wpa_supplicant-wlan0.conf.
Add this to wpa_supplicant-wlan0.conf

Code: Select all

network={
   ssid="MySSID"
   psk="MyPassphrase"
}
There should be no network entries in wpa_supplicant.conf!

One thing I haven't checked. You are using a different ssid on the AP than the client, correct?

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Tue Oct 17, 2017 5:09 pm

@SurferTim

run "$ iw list" and check the last part of the long output. Zero W gives
valid interface combinations:
* #{ managed } <= 1, #{ P2P-device } <= 1, #{ P2P-client, P2P-GO } <= 1,
total <= 3, #channels <= 1
* #{ managed } <= 1, #{ AP } <= 1, #{ P2P-client } <= 1, #{ P2P-device } <= 1,
total <= 4, #channels <= 1
Some people refer to it but so far no one claims fully understand it. But from the last #channels<=1, it is commonly believed that you must use the same channel for this setup.

I learn from viewtopic.php?f=91&t=187166 to write my own script. You may need it after you purchase a zero w.

Not 100% sure if it is a hardware problem and whether improvement is made for later batch of zero w production. I do observe a #channel<=2 for a Jun-purchased zero w running on non-raspbian os.

Regarding your question about wpa-supplicant, I followed exactly those filename and content. After I post the previous reply, I thought I should not enable wpa-supplicant. Quite likely it will result in two wpa-supplicant processes which is fatal itself. So, to be fair, my NO is based on the result of my first test (before enable wpa-supplicant) only.

For my own test, especially for the channel switch, I have two connection flow
1. internet - router(ssid-A) - RPi - Android phone
2. internet - Android phone 1 (data plan, wifi tethering, ssid-B) - RPi - Android phone 2

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Tue Oct 17, 2017 7:52 pm

You do not need to use the same channel in hostapd as the wifi client. I use channel 7 in hostapd.conf, but that is just the initial (boot) frequency. My Mikrotik wireless router uses channel 4. Almost immediately after the RPi wlan0 interface connects to my Mikrotik router's ap on channel 4, the RPi uap0 ap changes to channel 4. Ive tested this.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Wed Oct 18, 2017 4:59 am

SurferTim wrote:
Tue Oct 17, 2017 7:52 pm
You do not need to use the same channel in hostapd as the wifi client. I use channel 7 in hostapd.conf, but that is just the initial (boot) frequency. My Mikrotik wireless router uses channel 4. Almost immediately after the RPi wlan0 interface connects to my Mikrotik router's ap on channel 4, the RPi uap0 ap changes to channel 4. Ive tested this.
Good luck on your zero w.

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Wed Oct 18, 2017 9:13 am

coopi wrote:
Wed Oct 18, 2017 4:59 am
Good luck on your zero w.
No luck required. It either will or it won't. I ordered it this morning.

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Sun Oct 22, 2017 11:35 am

@coopi: Are you using the full version or the Lite version of Stretch? I'm testing with a RPi3 in anticipation of the arrival of my Zero W tomorrow. I have no problem with the full version, but apparently there is a network difference between them. The full version, even booting to a CLI, works. The Lite version will not allow the wlan0 interface to connect, even on a RPi3.

I have a new thread posted in Troubleshooting to see what the difference is between the two versions.
viewtopic.php?f=28&t=195889

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Mon Oct 23, 2017 8:33 pm

I just got my Zero W, and it booted up fine. I'm using the full version booting to CLI. The ap (uap0) changes frequency to match the station (wlan0).

I'm still having problems with Stretch Lite. wlan0 will not associate with the ap.

Wired Life
Posts: 3
Joined: Thu Sep 12, 2013 12:41 am

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Tue Oct 24, 2017 12:24 pm

Same problem here with stretch lite on zero w.
Got "IAID conflicts with one assigned to wlan0" and then "wlan0: carrier lost"
Cant get working client and ap at the same time.
Channel is the same, when i remove iw entry from rc.local the client works again.
Please help

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Tue Oct 24, 2017 12:29 pm

It is the hostapd service that causes the fail with Lite. If I disable the hostapd service, wlan0 will associate with the ap. When I enable it again, wlan0 fails to associate with the ap.

dmesg shows
brcmfmac: brcmf_cfg80211_add_iface: iface validation failed: err=-16

It works fine with the Stretch 2017-09-07 full version.

I thought the only difference between the full version and lite was the GUI desktop, but it isn't. The network stuff is also different.

Wired Life
Posts: 3
Joined: Thu Sep 12, 2013 12:41 am

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Tue Oct 24, 2017 2:15 pm

Is the only way to switch to full stretch?
So bad...

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Tue Oct 24, 2017 2:22 pm

Wired Life wrote:
Tue Oct 24, 2017 2:15 pm
Is the only way to switch to full stretch?
So bad...
At this time, it appears that is the only solution for this setup. I tried many approaches with Lite, and failed every time. It didn't matter whether it was a RPi3 or Zero W.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Wed Oct 25, 2017 4:34 pm

SurferTim wrote:
Sun Oct 22, 2017 11:35 am
@coopi: Are you using the full version or the Lite version of Stretch? I'm testing with a RPi3 in anticipation of the arrival of my Zero W tomorrow. I have no problem with the full version, but apparently there is a network difference between them. The full version, even booting to a CLI, works. The Lite version will not allow the wlan0 interface to connect, even on a RPi3.

I have a new thread posted in Troubleshooting to see what the difference is between the two versions.
viewtopic.php?f=28&t=195889
Sorry for the late reply, I use 2017-09-07-raspbian-stretch-lite.img.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Wed Oct 25, 2017 4:53 pm

Wired Life wrote:
Tue Oct 24, 2017 12:24 pm
Same problem here with stretch lite on zero w.
Got "IAID conflicts with one assigned to wlan0" and then "wlan0: carrier lost"
Cant get working client and ap at the same time.
Channel is the same, when i remove iw entry from rc.local the client works again.
Please help
Forget if I still get this error message to live with, I do remember the boot message* is NOT 100% clean.

The above link I mentioned that helps me to write the script that match the channel# did mention another tricks - i.e. before you run hostapd, you have to set wlan0 down first, and set it up again afterward. I have it done in the same script that run by /etc/rc.local.

Following is my script for your reference.

Code: Select all

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
iw dev wlan0 interface add uap0 type __ap
sysctl net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -s 192.168.50.0/24 ! -d 192.168.50.0/24 -j MASQUERADE
# write the first part of the conf file
echo -en 'interface=uap0\nssid=YOURSSID\ndriver=nl80211\nhw_mode=g\nieee80211n=1\nchannel=' > /etc/hostapd/hostapd.conf
iwlist channel 2> /dev/null | awk '/Current/ {print substr($5,1,length($5) - 1)}' >> /etc/hostapd/hostapd.conf
echo -e 'macaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\nwpa=2\nctrl_interface=/var/run/hostapd\nctrl_interface_group=0' >> /etc/hostapd/hostapd.conf
echo -e 'wpa_passphrase=YOURPASSWORD\nwpa_key_mgmt=WPA-PSK\nrsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
ifdown wlan0
ip link set dev uap0 up
ip addr add 192.168.50.1/24 broadcast 192.168.50.255 dev uap0
sleep 1
# start hostapd
hostapd -B -P /run/hostapd.pid /etc/hostapd/hostapd.conf &
sleep 1
service hostapd restart
ifup wlan0
service dnsmasq restart
I have wlan0 included in /etc/network/interfaces. Otherwise, ifup/down may not work, need ip link set dev ... as uap0.

* yes, boot message, not dmesg. I use serial cable instead of lan cable, and (gnu) screen command can capture it.

EDIT-----------------------
Sorry that I had my production script modified quite a bit already, and I have over cleaned the following 2 lines when I copy and paste them here. (Look strange, right after running a hostapd command, at once restart hostapd daemon, but it needs to be work this way.) I have inserted them back to the correct position in the above script.
sleep 1
service hostapd restart
Last edited by coopi on Fri Oct 27, 2017 5:56 am, edited 1 time in total.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Wed Oct 25, 2017 5:11 pm

SurferTim wrote:
Tue Oct 24, 2017 12:29 pm
It is the hostapd service that causes the fail with Lite. If I disable the hostapd service, wlan0 will associate with the ap. When I enable it again, wlan0 fails to associate with the ap.

dmesg shows
brcmfmac: brcmf_cfg80211_add_iface: iface validation failed: err=-16

It works fine with the Stretch 2017-09-07 full version.

I thought the only difference between the full version and lite was the GUI desktop, but it isn't. The network stuff is also different.
try set wlan0 down first
start hostapd
then set wlan0 up again
During my debug, I run command line-by-line to see if anything goes wrong. After everything works fine, I then put them into config & script. Just do more tests and I believe there will be a working one for everyone's environment.

SurferTim
Posts: 1006
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Thu Oct 26, 2017 11:46 am

coopi wrote:
Wed Oct 25, 2017 5:11 pm
try set wlan0 down first
start hostapd
then set wlan0 up again
During my debug, I run command line-by-line to see if anything goes wrong. After everything works fine, I then put them into config & script. Just do more tests and I believe there will be a working one for everyone's environment.
Did not work here. Post how you tested that.

When I start the hostapd service and bring up wlan0, it will not associate with the ap.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Fri Oct 27, 2017 5:57 am

SurferTim wrote:
Thu Oct 26, 2017 11:46 am
coopi wrote:
Wed Oct 25, 2017 5:11 pm
try set wlan0 down first
start hostapd
then set wlan0 up again
During my debug, I run command line-by-line to see if anything goes wrong. After everything works fine, I then put them into config & script. Just do more tests and I believe there will be a working one for everyone's environment.
Did not work here. Post how you tested that.

When I start the hostapd service and bring up wlan0, it will not associate with the ap.
Thank you for your feedback. I double checked and amend the above script.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: [Solved] Cannot SSH to zero w AP thru ip of hostapd

Fri Oct 27, 2017 11:50 am

SurferTim wrote:
Thu Oct 26, 2017 11:46 am
coopi wrote:
Wed Oct 25, 2017 5:11 pm
try set wlan0 down first
start hostapd
then set wlan0 up again
During my debug, I run command line-by-line to see if anything goes wrong. After everything works fine, I then put them into config & script. Just do more tests and I believe there will be a working one for everyone's environment.
Did not work here. Post how you tested that.

When I start the hostapd service and bring up wlan0, it will not associate with the ap.
You may also check viewtopic.php?f=36&t=196263 for a complete and concise execution.

Return to “Networking and servers”

Who is online

Users browsing this forum: amir_s_m, klricks and 23 guests