# Static IP and DHCP with WLAN

## mikki-kun

Hi there,

I would like to assign my WLAN card a static IP if it's connected to my homenetwork (possibly in the future even more networks) and use DHCP when I am not on specified networks. As my router doesn't support setting that I have to do it clientside, but that isn't bothering me that much to be honest. At least I learn something new  :Smile: 

I am trying getting that done with /etc/conf.d/net and wpa_supplicant on my Atheros AR928X PCI-E card but somehow it overreads my settings for my static IP.

The relevant part of /etc/conf.d/net looks as the following:

```
/etc/conf.d/net

# Wireless options are held in /etc/wpa_supplicant.conf

# Consult the sample file /etc/wpa_supplicant.conf.example for instructions

# To choose wpa_supplicant over iwconfig

modules=( "wpa_supplicant" )

# To configure wpa_supplicant

wpa_supplicant_wlan0="-Dwext" # For generic wireless

#wpa_supplicant_wlan0="-Dmadwifi" # For Atheros based cards

# Consult wpa_supplicant for more drivers

# By default don't wait for wpa_suppliant to associate and authenticate.

# If you would like to, so can specify how long in seconds

#associate_timeout_eth0=60

# A value of 0 means wait forever.

# GENERIC WIRELESS OPTIONS

# PLEASE READ THE INSTRUCTIONS IN /etc/conf.d/wireless.example FOR

# HOW TO USE THIS ESSID VARIABLE

# You can also override any settings found here per ESSID - which is very

# handy if you use different networks a lot

#config_wlan0=( "dhcp" )

#dhcpcd_wlan0="-t 10"

# Setting name/domain server causes /etc/resolv.conf to be overwritten

# Note that if DHCP is used, and you want this to take precedence then

# set dhcp_ESSID="nodns"

#dns_servers_ESSID=( "192.168.0.1" "192.168.0.2" )

#dns_domain_ESSID="some.domain"

#dns_search_ESSID="search.this.domain search.that.domain"

# Please check the man page for resolv.conf for more information

# as domain and search are mutually exclusive.

# You can also override any settings found here per MAC address of the AP

# in case you use Access Points with the same ESSID but need different

# networking configs. Below is an example - of course you use the same

# method with other variables

#mac_config_001122334455=( "dhcp" )

#mac_dhcpcd_001122334455="-t 10"

#mac_dns_servers_001122334455=( "192.168.0.1" "192.168.0.2" )

mac_config_001150e8e8b6=( "192.168.2.3 brd 192.168.2.255 netmask 255.255.255.0" )

mac_routes_001150e8e8b6=( "default via 192.168.2.1" )

mac_dns_servers_001150e8e8b6=( "192.168.2.1" )

#If any of the above profiles fail use DHCP

fallback_wlan0=( "dhcp" )

dhcpcd_wlan0="-t 5"

```

I am clueless, why it "falls" back to DHCP even though the MAC specified is correct. The MAC is the BSSID of the router, right?

If anybody can lend me a hand here I'd gladly appreciate it.

Thanks.

mikki-kun

----------

## nanoczar

I had a buddy who did this by using a MAC address on his home network and then allowed DHCP to work outside his house. He seemed to like it. Would that be an option?

----------

## mikki-kun

If I understood you correctly your buddy used the same layout as I would wanna have. I would like to specifiy the defined networks by MAC and not by their SSID as SSIDs can change or be the same. MACs don't tend to have these "features".

So yeah, I would like to make MAC-based configurations but if none of the stated MACs are found I'd like it to fall back to DHCP and use that.

Hopefully you can lend me a hand there.

Thanks  :Smile: 

mikki-kun

----------

## jordanwb

I think NetworkManager (and probably wikd) can do what you want.

----------

## dmpogo

You set your computer to use DHCP always,  so no need for any configuration here,  but on  DHCP server  at home you set to assign a specific IP for a given MAC address. Even cheap routers can do that.

----------

