# Setting static IP address to UDHCP client

## ENzero

I am using udhcp client for an embedded device. I am trying to add a feature to set a static IP, Netmask, DNS, and gateway address.

I am trying to set it through the "-r" argument (request):

```
/sbin/udhcpc -A 3 -f -s /tmp/udhcpc_wlan0_sh -i wlan0 -r 172.16.0.2
```

It does not seem to work. I try to connect my device to an access point and it still used the dhcp deamon provide address.

I was wondering if there are any additional things that I need to do to enable static address.

----------

## NeddySeagoon

ENzero,

Welcome to Gentoo.

-r 172.16.0.2 only requests an address. The DHCP server is not compelled to grant it.

Fix the MAC address in your embedded device, if it isn't already.

Then tell your DHCP server to fix the IP address that is assigned to that MAC address.

You can also configure /etc/conf.d/net to assign a static address.

If you do that, be sure that it is outside the range that your DHCP server can assign.

----------

## bunder

in /etc/conf.d/net you can set some of these, but i don't remember where you set the wifi password off hand. (edit: unless your intention is to run hostapd, it goes in there)

```
modules_wlan0="!iwconfig !wpa_supplicant" #you probably need to adjust this one

config_wlan0="192.168.2.1 broadcast 192.168.2.255 netmask 255.255.255.0"

channel_wlan0="44"

essid_wlan0="mywifinetwork"

```

----------

## ENzero

Thanks @NeddySeagoon and @bunder for responding!

I see ... so I don't really tweak anything in for udhcpc.

 *Quote:*   

> You can also configure /etc/conf.d/net to assign a static address.
> 
> If you do that, be sure that it is outside the range that your DHCP server can assign.

 

I using just random access points like phones/routers. I am aiming to be able to set static ip inside or outside the dhcp server range if it's possible.

I could not find  /etc/conf.d/net since I am working on a horrible proprietary stuff(structure is a bit differnt). Is there a way through terminal to set static address?

----------

## NeddySeagoon

ENzero,

/etc/conf.d/net does not exist until you create it.

When its missing, dhcpcd or whatever you have installed does its dynamic thing.

I have in /etc/conf.d/net 

```
config_eth0="192.168.100.20/24 brd 192.168.100.255"

# VM router

routes_eth0="default via 192.168.100.253"
```

I need a static IP address to be able to fix things when when my dhcp breaks.

However my dhcp server will only assign 192.168.100.220 to 192.168.100.240 so my static 192.168.100.20 will not cause IP address collisions.

-- edit --

ifconfig <interface> <IP> sets a static IP.

You will also need a default route if you want to connect beyond your local subnet

route add default gw <IP_of_Router>

----------

## Jaglover

 *Quote:*   

> I am working on a horrible proprietary stuff(structure is a bit differnt).

 

Is it somehow Gentoo based?

----------

## UberLord

 *ENzero wrote:*   

> Is there a way through terminal to set static address?

 

ip addr add 192.168.0.1/24 dev eth0

----------

