Switching from a dynamic to a static IP address


When I make a Debian Linux box, I start with it as a DHCP client and let it get the network settings automatically. This tip is to help me remember where to change them when I want to switch to a static IP.

This is for the Debian Linux (Woody and Sarge).



There will be some stuff about lo (the loopback interface), which should be left alone.

Then there is an ethn section for each network card (i.e. eth0, eth1 and so on). The examples all use eth0.

DHCP network cards will have a line like:

iface eth0 inet dynamic

Statically configured network cards will have a section like:

iface eth0 inet static
	address local address
	netmask subnet mask
	network network address, usually the lowest address on your subnet
	gateway gateway's IP address, usually the one greater than lowest address on your subnet
	broadcast network broadcast address, usually the highest address on your subnet
	dns-nameservers server1 server2
	dns-search defaultdomain

Note that the indent is a single tab, not spaces.

Here is an example:

iface eth0 inet static
	dns-search example.net

After making the change, run ifdown eth0 and then ifup eth0.

To check the current configuration, run ifconfig.


Note that in Ubuntu 12.04, this is configured with the dns-nameservers and dns-search lines above. Changes to resolv.conf will be overwritten when you restart.

Statically configured:

search default domain name
nameserver DNS server ip address

The default domain is used when you only type in one word (i.e. when you try to resolve mail and want it to go to mail.example.com, you should use example.com as the default domain.

You can have multiple nameserver lines if you have backup name servers. Only one will be used though, it does not search all of them.

Here is an example (using OpenDNS):

search example.com