ssh to RPi with hostname via wifi

Got problems while trying to ssh to your RPi with hostname via wireless network? Yes, me too.

I am a lazy guy to connect keyboard and display to RPi every time I develop and test my project on RPi. Also, I don't like too many wires so I use a wifi dongle. After setting up the wireless network environment and hostname of my RPi, I still cannot connect my RPi from my laptop with hostname. I connect the display and keyboard to RPi again to check the wifi settings. Guess what? The settings are fine. I could connect to internet from RPi. Then I try to connect to RPi with IP address instead of hostname and it works. So the problem is there is no mapping from RPi's hostname to RPi's IP address.

Finally, I find "libnss-mdns" could solve my issue. Here I summarize all setting steps to ssh to RPi with hostname via wifi.

1. Set hostname in /etc/hosts
2. Set hostname in /etc/hostname
3. Install libnss-mdns by sudo apt-get install libnss-mdns

Now I could connect my RPi from my laptop with hostname. But there is a little trick: the suffix ".local" must be added to the hostname.

ssh pi@myrpi.local
ssh pi@myrpi

There is one more thing annoying me on my Edimax wifi adapter. It is going to sleep very quickly and frequently. So I add one more step to prevent the dongle from suspending.

4. Edit /etc/modprobe.d/8192cu.conf by adding
options 8192cu rtw_power_mgnt=0
to disable power management
Post a Comment