Setting a Static IP and DNS in Debian/Ubuntu over the CLI
Some times you just need a static IP but have no GUI to easily set one up. Well it is not so hard to do in Debian-based distributions.
- Open
/etc/network/interfaces
in your favorite editor. I like nano. - Find the line that starts with
iface [interface]
. The interface you are looking for is most likely eth0 or something similar. - Change the line to read
iface [interface] inet static
. - After it add your IP information. I have included a common example but just replace my information with your own.
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1 - Open
/etc/resolv.conf
. - In it use the
nameserver
directive to specify your name server(s). Thenameserver
directive(s) will be searched in the order entered here. Here is an example:
nameserver 192.168.1.2
nameserver 192.168.1.3 - Restart networking with
sudo /etc/init.d/networking restart
.
[Edit] 2013.08.10
Thanks to Renat Zaripov for pointing out my mistake in typing /etc/resolve.conf
instead of /etc/resolv.conf
.
8 thoughts on “Setting a Static IP and DNS in Debian/Ubuntu over the CLI”
thx breh
Perfect !
Add 8.8.8.8 as DNS server work
One potential issue here is that this solution needs an Internet connection to work (not to mention the fact that someone else can not watch all your queries).
This is a great solution if you do not require your DNS to work offline. For example, on a truly private network.
/etc/resolv.conf instead /etc/resolve.conf
Oh, man. How did that go unseen for so long? Heh, thanks.
after server restart above changing will be rest on dhcp
I don’t have resolve.conf file in /etc on my debian server.
Inside my /etc I have resolvconf directory and inside this I have one more directory which is update-libc.d; inside this directory I have one one regular file called avahi-daemon.
How can I update my dns ?
Please help me.
Thankx
I have resolv.conf — there is no ‘e’!