# Switch from dhcp to static ip

## cmay4

I'd like to switch from DHCP to a static IP.  I'm not sure how to go about this.  I am using a NAT router, and here are the stats...

```
root # route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth0

root # ifconfig -a

eth0      Link encap:Ethernet  HWaddr 00:40:05:A2:CD:B7

          inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0

          UP BROADCAST NOTRAILERS RUNNING  MTU:1500  Metric:1

          RX packets:2984 errors:1 dropped:0 overruns:0 frame:0

          TX packets:2152 errors:8 dropped:0 overruns:0 carrier:8

          collisions:0 txqueuelen:100

          RX bytes:253092 (247.1 Kb)  TX bytes:189450 (185.0 Kb)

          Interrupt:10 Base address:0xe800

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:2 errors:0 dropped:0 overruns:0 frame:0

          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:100 (100.0 b)  TX bytes:100 (100.0 b)

root # cat /etc/resolv.conf

nameserver 192.168.0.1

search howard01.md.comcast.net

```

I assume I need to edit my resolv.conf, but I'm not sure how.  Also, how do I find out the IP addresses of my nameservers, since dhcp has always handled it. Any help would be appreciated.  Thanks.

Chuck

----------

## klieber

Just follow the steps in the install guide.  It shows how to set up a static as well as a DHCP connection, so switching between them should be straightforward.  (you basically just have to edit /etc/conf.d/net, but check the doc for more info)

--kurt

----------

## cmay4

 *klieber wrote:*   

> Just follow the steps in the install guide.  It shows how to set up a static as well as a DHCP connection, so switching between them should be straightforward.  (you basically just have to edit /etc/conf.d/net, but check the doc for more info)
> 
> --kurt

 

I looked at it, but I'm still unclear.

```
# /sbin/ifconfig $IFACE $IPNUM broadcast $BCAST netmask $NMASK

# /sbin/route add -net default gw $GTWAY netmask 0.0.0.0 metric 1
```

Makes sense to me.  However,

```
domain mydomain.com

nameserver 10.0.0.1

nameserver 10.0.0.2
```

I don't know what my DNS servers are, since I am using DHCP.  Also, is there a way to have a static ip, but use DHCP to get the DNS servers?

Chuck

----------

## klieber

 *cmay4 wrote:*   

> I don't know what my DNS servers are, since I am using DHCP. 

 

A quick Google search should turn up wonders.  :Smile:   Also, dhcpcd should place the nameservers it gets from the DHCP server in /etc/resolv.conf -- the fact that it's not doing so is somewhat perplexing.

 *cmay4 wrote:*   

> Also, is there a way to have a static ip, but use DHCP to get the DNS servers?

 

I don't think so, but more importantly, why would you want to?  name servers change so infrequently that once you drop a couple in your /etc/resolv.conf file, you rarely ever have to worry about it again.

--kurt

----------

## cmay4

 *Quote:*   

> Also, dhcpcd should place the nameservers it gets from the DHCP server in /etc/resolv.conf -- the fact that it's not doing so is somewhat perplexing.

 

I assume it's using the Netgear router as the nameserver.  I used the router's web interface to see if I could find the name servers there, but no luck.  Quite strange.

Chuck

----------

