OpenWrt Forum Archive

Topic: Access Point running DHCP client with static IP address as fallback

The content of this topic has been archived on 1 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have configured my Nanostation2 as an AP including a DHCP client, receiving an IP address from the modem it is connected to. That all works fine.

However, what I need is a fallback static IP address assignment, if the router is not connected to a DHCP server, but say, to a standard PC (which typically has no DHCP server running).

Why is this useful? Devices like the Nanostation2 or the earlier Foneras only have one ethernet socket. That socket has to serve either as wan or lan port, depending on the configuration settings in /etc/config/network. If the router is set up with a WAN port and a DHCP client for normal operations the router performs fine as long as the router is connected to the DHCP server. But since the one port is used as WAN port, you cannot simultaneously login via ssh or webif to perform configuration tasks. To do that you need to connect your PC to the router, however when the same Nanostation2 or Fonera is then connected to a PC without DHCP server, you cannot connect to it via ethernet, because it is waiting as a dhcp client for an IP address assignment that will never come.

My attempts so far have been frustrated. I have added an IP address in /etc/config/networks like so:

root@OpenWrt:/# 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 wan
        option ifname   eth0
        option proto    dhcp
        option ipaddr   192.168.12.1
        option netmask  255.255.255.0

However, when the AP receives an IP address from an external dhcp server the IP address is overwritten by the IP address assigned by the dhcp server.

So question is: How can a router running OpenWRT set up as a dhcp client on the wan interface with a static IP address as a fallback (for the case no external IP address is being assigned)?

Any input is welcome.

Mean network alias?

uci add network alias
uci set network.@alias[-1].interface=wan
uci set network.@alias[-1].proto=static
uci set network.@alias[-1].ipaddr=192.168.12.1
uci set network.@alias[-1].netmask=255.255.255.0
uci commit network

Result:

config 'alias'
        option 'interface' 'wan'
        option 'proto' 'static'
        option 'ipaddr' '192.168.12.1'
        option 'netmask' '255.255.255.0'

(Last edited by Nilfred on 13 Sep 2009, 13:12)

The discussion might have continued from here.