1

I need to set the ip address of the device automatically to a few default values so that it could be accessed over a connected network easily. The device is meant to be used in any LAN it is connected to.

For example if the device is connected in a network with ip addresses of the format: 192.168.2.* The device should set it's IP automatically as 192.168.2.200.

And if the local network has ips of the format 10.1.1.*, it should set it's ip as 10.1.1.200.

How can this be achieved with a script?

Also how to access the device with a name?

  • WHy do you need to do that? Could you please explain, maybe there is a better solution to the problem that you have. – Piotr Kula Apr 24 '14 at 10:36
  • I just had the idea of using SNMP pop up in my head. If there was an SNMP agent running on the Pi, and you'd push an SNMP broadcast from the PC to the network, the Pi could answer and the PC would receive the Pi's current IP address with the answer. -- But I'm just fantasizing. Probably not a good idea, don't know. :-) – JimmyB May 26 '14 at 14:34
  • Or one might look into using Reverse ARP. – JimmyB May 26 '14 at 14:35
  • I assume the only reason you going to all this trouble so you can find the IP of the Pi on the network. That is why DHCP is useful, especially when a DNS server sits next to it, like all routers do now a days. Even with a server you must have DNS next to DHCP. I understand if networks are running serverless and everything is static, then maybe a script like auto detect might work if you scanned predefined subsets, but what if a network uses a non standard IP range. You can make the Pi be the DHCP/DNS server and always set it to be x.x.x.1 and get the rest to work with the Pi. – Piotr Kula May 28 '14 at 09:56

3 Answers3

1

Maybe the following is interesting for you: http://www.raspberrypi.org/forums/viewtopic.php?f=66&t=18207

If you install the avahi program you can access your raspberry with raspberry.local without an entry in your dns. This works from a windows, mac os, or linux pc.

S.Spieker
  • 545
  • 1
  • 6
  • 18
  • Yea avavi is a nice solution sine you can resolce IP by "DNS" ping. But really, the DHCP/DNS server, even in normal routers have settings like this, for receiving IP, and setting DNS names. +1 – Piotr Kula Apr 24 '14 at 10:36
0

Do you know if the networks you are connecting to have DHCP running? If so, and you have access to the DHCP server, you could always add a static MAC to IP mapping. If you don't have access then you could try to add something to the dhcp client configuration to force a certain IP. If you connect to a network that does not have DHCP running at all it is pretty difficult for it to detect the network it is on.

jkirchne
  • 11
  • 1
  • Not always. But the setups' going to be quite simple, it's going to connect to the wifi router or the local lan connection. The IP would automatically set as per their dhcp settings. – Santosh Achari Apr 22 '14 at 14:42
  • Do you have the ability to setup a MAC to IP address static mapping in the DHCP server? That is normally the method that is used to solve this. – jkirchne Apr 23 '14 at 09:10
  • No. I just want a simple method to call the device connected in a network. Say with the ip address ending with 200 of their series – Santosh Achari Apr 24 '14 at 09:18
0

I was able to fix this by using Samba, and Avahi.

Samba let's me connect to Raspberry Pi through my window devices.

$ sudo apt-get install samba samba-common-bin

By just calling "hostname" as in "raspberrypi"

Avahi lets me reach through mac. "hostname.local" as in "raspberrypi.local".

sudo apt-get install avahi-daemon

I didn't bother any more about setting the static ip automatically.

Installing Samba

Installing Avahi