Friday, November 8, 2013

Assign static local domain to Raspberry Pi

In my previous examples about ssh, vnc, I always have to check the IP address (192.168.xxx.xxx) of my Raspberry Pi locally with ifconfig, or login my router to look-up the connected IPs; because it will change dynamically. By assigning a static local domain to Raspberry Pi with avahi-daemon, I can use a local domain such as raspberrypi.local consistently.



Steps:

If you have computers running Apple’s OS X on your network, it already support it.
If you run on Windows, you have to install Bonjour Print Services for Windows.

In Raspberry Pi side, enter the command:
sudo apt-get install avahi-daemon
sudo insserv avahi-daemon

Create a configfile for Avahi at /etc/avahi/services/multiple.service, with the command:
sudo pico /etc/avahi/services/multiple.service

with content of:
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
        <name replace-wildcards="yes">%h</name>
        <service>
                <type>_device-info._tcp</type>
                <port>0</port>
                <txt-record>model=local</txt-record>
        </service>
        <service>
                <type>_ssh._tcp</type>
                <port>22</port>
        </service>
</service-group>

then run the command:
sudo /etc/init.d/avahi-daemon restart

The local domain name of your Raspberry Pi will be <Raspberry Pi host name>.local, such as:
raspberrypi.local

After a moment, you can access Raspberry Pi with its new static domain.

Video demo:

reference:
http://elinux.org/RPi_Advanced_Setup

No comments: