# Static IP witih DHCP assigned nameservers

## Element Dave

Networking experts,

I have a very simple setup using dhcpcd to obtain an address and nameservers from a local home router/NAT.  Is it possible to manually configure a static IP while retaining the behavior in which /etc/resolv.conf is populated by the dhcp client?  Manually setting the IP (in /etc/conf.d/net) is straightforward and clearly documented in the handbook; I'm just not certain whether the combination is supported and I'm unable to test it at the moment.  This condition is desirable because my internal IP will remain constant, but the nameservers I use may change from time to time.

Thanks in advance.

----------

## Jimini

Of course it is possible. 

First, emerge net-misc/dhcp.

1) Static IPs via DHCP

Open /etc/dhcp/dhcpd.conf and add lines like the following:

```
host Bla                { hardware ethernet 00:11:22:AA:BB:99; fixed-address Bla; }
```

Open /etc/hosts and add lines like the following:

```
10.0.0.100        Bla.in.your.domain           Bla             #Perhaps a little description
```

Now (re)start your dhcp-daemon via /etc/init.d/dhcpd restart

2) Serving the ip of the nameserver

Open /etc/dhcp/dhcpd.conf and add look for

```
subnet 10.0.0.0 netmask 255.255.255.0 {

        range 10.0.0.11 10.0.0.99;

        option subnet-mask 255.255.255.0;

        option broadcast-address 10.0.0.255;

        option routers 10.0.0.1;

        option domain-name-servers 10.0.0.1;

}
```

Edit the option named option domain-name-servers here and restart your dhcp-daemon. Now everything should work.

Best regards,

Jimini

Edit: in my case, my dhcp-server also works as my dns-server. Therefore, I use net-dns/dnsmasq. In /etc/resolv.conf, I have some nameserver-ips - all the other machines in my network use the ip-adress of my nameserver instead:

/etc/resolv.conf on my dns-server:

nameserver some.ip.adresses.here

/etc/init.d/dnsmasq start - that's it.

----------

## DONAHUE

Pretending your router is 192.168.0.1 and supports dns passthrough and your interface is eth0 (use your values if you try this):

try:

 *Quote:*   

> dns_servers_eth0="192.168.0.1 4.2.2.6"

 

in /etc/conf.d/net

4.2.2.6 is a public dns server, feel free to pick another, public server is good backup and may be faster than router/isp service.

----------

## kimmie

Jimini: I think he wanted to use the dhcp server on the router, not host one?

Element Dave: I've found that the best thing to do in this situation is to set up a fixed host on your router. Most routers support this. Then your computer stays fully DHCP, making it easier to move about, but it always gets assigned the same address from your router. The other easy option is what DONAHUE suggested.

----------

