Arduino Yun: permanently set static ip address

Hi! First of all, sorry but I'm not super confident with linux and openwrt network configuration.

I'd like to have an aruino yun as a server that accepts requests in my home network. Due to the fact that it has to be a server I think the best option is to configure it with a static ip address. To do that I've configured my router to start the dhcp from 192.168.3.100 and higher. Lower then 100 are static ip address.

Even if I read some posts already in this forum I'm not sure I'm doing it in the right way because sometimes when I reset the board or the router (switching off and on the power) the openwrt machine in the yun loses the network configuration I have done.

It's not very clear if the problem is caused by the reset of the yun, the reset of the router, or both the things in some weird combination.

I'd like my yun to be always with the same ip address, even if the router is down for a while, even if I restart the yun and the wifi net is up, event if I restart the yun and the wifi net is down.

I've tried some different things from various post (*) but I think the best is from http://forum.arduino.cc/index.php/topic,217733.0.html

root@Arduino:~# cat /etc/config/network

config interface 'loopback'
    option ifname 'lo'
    option proto 'static'
    option ipaddr '127.0.0.1'
    option netmask '255.0.0.0'

config interface 'lan'
#   option proto 'dhcp'
    option 'proto' 'static'
        option 'ipaddr' '192.168.3.42'      # the status ip address I want
        option 'netmask' '255.255.255.0'
        option 'gateway' '192.168.0.1'
        option 'dns'     '192.168.0.1'

config interface 'wan'
    option ifname 'eth1'
    option proto 'dhcp'
    option metric '10'

Sometimes it loses the net configuration: if I restart the yun It has a dhcp address (like 192.168.3.104) OR it open the access point setting (I haven't understand what causes what). Once it also happened that the white led that notify me the openwrt is ok (I have the new openwrt image) was not on (and this scared me a little).

Due to the fact that sometimes it loses the net configuration I have commented out the line

wifi-live-or-reset

in the file /etc/rc.local

So that:

root@Arduino:~# cat /etc/rc.local
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

#wifi-live-or-reset
boot-complete-notify

# Log down the server output
now=$(date +"%Y.%m.%d.%S")
logfilename="server.$now.log"
cd /root/node; node server.js > $logfilename 2>&1

exit 0

But I'm not sure it is enough to stay permanently with a static ip address and wait for the wifi net go up again. Please post anything that could help me, some other posts, or man pages, because it is really annoying to set configuration every time! Hope not to be too openwrt illiterate : )


(*) http://forum.arduino.cc/index.php?topic=227693.msg1650457#msg1650457 http://www.remoteaccesscontrol.it/index.php/overview1/2-non-categorizzato/13-arduinoyun http://forum.arduino.cc/index.php?topic=239095.0

config interface 'loopback'
    option ifname 'lo'
    option proto 'static'
    option ipaddr '127.0.0.1'
    option netmask '255.0.0.0'

config interface 'lan'
#   option proto 'dhcp'
    option 'proto' 'static'
        option 'ipaddr' '192.168.0.42'      # the status ip address I want
        option 'netmask' '255.255.255.0'
        option 'gateway' '192.168.0.1'
        option 'dns'     '192.168.0.1'

config interface 'wan'
    option ifname 'eth1'
    option proto 'dhcp'
    option metric '10'
config interface 'loopback'
    option ifname 'lo'
    option proto 'static'
    option ipaddr '127.0.0.1'
    option netmask '255.0.0.0'

config interface 'lan'
#   option proto 'dhcp'
    option 'proto' 'static'
        option 'ipaddr' '192.168.0.42'      # the status ip address I want
        option 'netmask' '255.255.255.0'
        option 'gateway' '192.168.0.1'
        option 'dns'     '192.168.0.1'

config interface 'wan'
    option ifname 'eth1'
    #option proto 'dhcp'
        option 'proto' 'static'
        option 'ipaddr' '192.168.0.43'      # the status ip address I want
        option 'netmask' '255.255.255.0'
        option 'gateway' '192.168.0.1'
        option 'dns'     '192.168.0.1'
    option metric '10'
/etc/init.d/network reload

sorry?

nano /etc/config/network

change:

config interface 'wan'
    option ifname 'eth1'
    option proto 'dhcp'
    option metric '10'

to:

config interface 'wan'
    option ifname 'eth1'
    #option proto 'dhcp'
        option 'proto' 'static'
        option 'ipaddr' '192.168.0.43'      # the status ip address I want
        option 'netmask' '255.255.255.0'
        option 'gateway' '192.168.0.1'
        option 'dns'     '192.168.0.1'
    option metric '10'

mantissa00 there's a subtle issue here: in order to set a static ip address to a wifi interface it has to be connected to a wifi (or must have created one). I think you cannot just set the IP: wifi has to up and running, then you can tell the interface it does not have to obtain an IP via dhcp as it has to use the one you set (at least that what I understand, please correct me if I'm wrong)

On the contrary, you can do what you're describing with the ethernet interface: you can set an ip even if it has no connected cable

That's why sonnyyu is suggesting to set an IP to the interface called "wan" in the config file

ps: I would do these kind of experimentation using the "advanced configuration panel": it's easier and it's guided. You can find the link in the header of the arduino webpanel

Hi! Ok, sorry I'm really not experienced in the network stuffs and a little bit confused..

Federico, do you mean that in the wifi networks there is no possibility to have a static ip address? Do you mean, in all wifi networks? Or only with the arduino yun hardware?

So, to understand a little bit better the config file from sonnyyu: loopback interface: for localhost, 127.0.0.1, i don't touch it lan interface: ip 192.168.0.42 for ethernet cable, let's say that if I don't use the ethernet cable is not used wan interface: ip 192.168.0.43 for the WiFi module built on board? why the option ifname 'eth1'?

Sorry but I'm still trying to understand what all those configurations mean and http://wiki.openwrt.org/doc/uci/network is not so clear to me..

mantissa00: Federico, do you mean that in the wifi networks there is no possibility to have a static ip address? Do you mean, in all wifi networks? Or only with the arduino yun hardware?

I'm saying it depends, on the state of your wifi interface. It has to be up&running. When it's in access point mode, its ip address is statically set in the config files. From what you say, you want a static IP address when running in client mode. This again is possible, but wifi interface still needs to be up&running: if your wifi is out of range or something, yun's wifi interface will NOT be up and therefore will NOT have an ip address. Everything IMHO because I'm repeating what I remember, not what I've just tested. I can make mistakes: my apologies if this is the case :) Best is if you give it a try and report back

mantissa00: ... So, to understand a little bit better the config file from sonnyyu: loopback interface: for localhost, 127.0.0.1, i don't touch it lan interface: ip 192.168.0.42 for ethernet cable, let's say that if I don't use the ethernet cable is not used wan interface: ip 192.168.0.43 for the WiFi module built on board? why the option ifname 'eth1'?

Sorry but I'm still trying to understand what all those configurations mean and http://wiki.openwrt.org/doc/uci/network is not so clear to me..

lan interface: ip 192.168.0.42 for wireless. wan interface: ip 192.168.0.43 for the eth1, ethernet cable. metric '10' means wireless gateway where a lower metric/cost is preferred

uci API;-

uci set network.lan=interface
uci set network.lan.proto=static
uci set network.lan.ipaddr=192.168.0.44
uci set network.lan.netmask=255.255.255.0
uci set network.lan.gateway=192.168.0.1
uci set network.lan.dns=192.168.0.1
uci set network.wan=interface
uci set network.wan.ifname=eth1
uci set network.wan.proto=static
uci set network.wan.ipaddr=192.168.0.45
uci set network.wan.netmask=255.255.255.0
uci set network.wan.gateway=192.168.0.1
uci set network.wan.dns=192.168.0.1
uci set network.wan.metric=10
uci commit
/etc/init.d/network reload

I've just been through this,

I was getting confused between the lan and wan settings, the wifi is controlled by the lan settings. so if my network is 192.168.1.1 and I want to static allocate 192.168.1.17 as the arduino Yun I would go to

root/etc/config/nano network

and make these changes.

config interface 'lan'
option ifname 'wlan0'
option proto 'static'
option ipaddr '192.168.1.17'
option netmask '255.255.255.0'
option gateway '192.168.1.1'
option dns '192.168.1.1'
option metric '10'

config interface 'wan'
option ifname 'eth1'
option proto 'dhcp'

then go to

root/etc/init.d/

and run

./network reload

use the yunSerialTerminal sketch to get a console and run

ifconfig

your wifi IP should now be statically allocated to 192.168.1.17

Obviously the network data will vary depending on your home / available wifi networks.

Hi everybody! I am trying to do this and I have a problem. I've tried several methods and I can assign the static IP succesfully (SSH, web panel) but the moment I do it I stop getting external connection to the Internet (cannot ping). I wan t to set this because I am using a Python application with websockets and want the Arduino to be always at the same IP.

Any help? Thank you very much.

EDIT: I forgot an evident solution for desktop clients...using arduino.local (equivalent) name. Sadly, it does not solve my problem since clients will be smartphones.