You are on page 1of 13

Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration Pagina 1 di 13

Home About Forum Howtos & FAQs Shell Scripts Tutorials RSS Subscribe
Network Config tool Free Configuration Management tool for Routers Switches Firewalls etc

nixcraft - insight into linux admin work

Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration

by Vivek Gite My friend wanted to know how to change or convert DHCP network configuration to static configuration. After initial installation, he wanted to change network settings. Further, his system is w/o GUI system aka X Windows. Here is quick way to accomplish the same: Your main network configuration file is /etc/network/interfaces Desired new sample settings: => Host IP address => Netmask: => Network ID: => Broadcast IP: => Gateway/Router IP: => DNS Server: Open network configuration file
$ sudo vi /etc/network/interfacesOR$ sudo nano /etc/network/interfaces

Find and remove dhcp entry:

iface eth0 inet dhcp

Append new network settings:

iface eth0 inet static address netmask network broadcast gateway

Save and close the file. Restart the network:

$ sudo /etc/init.d/networking restart

Task: Define new DNS servers

Open /etc/resolv.conf file
$ sudo vi /etc/resolv.conf

You need to remove old DNS server assigned by DHCP server:

search nameserver


Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration Pagina 2 di 13

nameserver nameserver

Save and close the file.

Task: Test DNS server

$ host

Network command line cheat sheet

You can also use commands to change settings. Please note that these settings are temporary and not the permanent. Use above method to make network changes permanent or GUI tool as described below.

Task: Display network interface information

$ ifconfig

Task: Take down network interface eth0 / take a network interface down
$ sudo ifconfig eth0 downOR $ sudo ifdown eth0

Task: Bring a network interface eth0 up

$ sudo ifconfig eth0 upOR$ sudo ifup eth0

Task: Change IP address and netmask from command line

Activate network interface eth0 with a new IP ( / netmask:
$ sudo ifconfig eth0 netmask up

Task: Display the routing table

$ /sbin/route

OR$ /sbin/route -n

Kernel IP routing table Destination Gateway localnet * * * default Genmask Flags U U U UG Metric 0 0 0 0 Ref 0 0 0 0 Use 0 0 0 0 Iface ra0 eth0 eth1 ra0

Task: Add a new gateway

$ sudo route add default gw

Task: Display current active Internet connections (servers and established connection)
$ netstat -nat

Task: Display open ports

$ sudo netstat -tulpOR$ sudo netstat -tulpn

Task: Display network interfaces stats (RX/TX etc)

$ netstat -i

Task: Display output for active/established connections only


Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration Pagina 3 di 13

$ netstat -e $ netstat -te $ netstat -tue

Where, -t : TCP connections -u : UDP connections -e : Established

Task: Test network connectivity

Send ICMP ECHO_REQUEST to network hosts, routers, servers etc with ping command. This verifies connectivity exists between local host and remote network system:
$ ping router $ ping $ ping

See simple Linux system monitoring with ping command and scripts for more information.

Task: Use GUI (Graphical Configuration) network Tool

If you are new, use GUI configuration tool, type the following command at terminal:
$ network-admin &

Above command is Ubuntu's GUI for configuring network connections tool.

Final tip - Learn how find out more information about commands
A man page is your best friend when you wanted to learn more about particular command or syntax. For example, read detailed information about ifconfig and netstat command:
$ man ifconfig $ man netstat

Just get a short help with all command options by appending --help option to each command:
$ netstat --help

Find out what command is used for particular task by searching the short descriptions and manual page names for the keyword:
$ man -k 'delete directory' $ apropos -s 1 remove

Display short descriptions of a command:

$ whatis rm $ whatis netstat

Linux offers an excellent collection of utilities, which can be use to finding the files and executables, remember you cannot memorize all the commands and files ;) Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here! Subscribe

Email this to a friend Printable version Rss Feed Last Updated: Jul/27/2007

{ 3 trackbacks }


Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration Pagina 4 di 13

S. Beatty Consulting Blog Archive An Ubuntu Server 7.04 Installation in VMware 11.12.07 at 3:52 am Linux convert static IP configuration to DHCP network configuration Vunknowns Weblog 04.20.08 at 5:46 pm Not A Fan at 12.05.08 at 12:33 pm { 44 comments read them below or add one }

1 George 12.17.06 at 12:17 pm Thank you nixcraft! You are not only teaching excellent networking specifics, but, most importantly, also making me understand how to do this on my own. Not too many guys out there are able to do this as you have done.

2 Rafael 07.30.07 at 5:44 am Thank you, this made it work for me. I had the problem of needing to use static ip address, for various other lan requirements. Although, one minor glitch creeped up .. after I had edited the /etc/network file. My gateway is set to, rather than 1.254, and so that is what I had set in the network file. After editing this file I still had no internet connection, but I could ping the gateway. But I was able to connect after modifying the setting in the gui: System>Admin>Network>eth0>gateway address. It had a default setting of, changing it to my actual gateway fixed it.

3 Grady Lambert 08.17.07 at 1:32 am A very good tutorial. Thank you. I have been struggling with networking for sometime. You have helped to clear up a lot of confusion.

4 Shelly 09.10.07 at 8:31 am Hi and thanks for this article. Why do you change the 255 to 254 please? Do I need to do that if setting a server box up within a network with other multiple OSs?

5 steppa 10.12.07 at 5:31 pm NetworkManager is fine for varying wlan configurations. This guide gives a sleek way to configure a static network. Afterwards you can apt-get purge remove network-manager knetworkmanager network-manager-gnome dhcdbd to get rid of unnecessarily runnig daemons.

6 Anonymous 12.08.07 at 4:07 am


Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration Pagina 5 di 13

auto eth0 should precede anything added to interfaces and be on its own line.

7 Grayheart 01.30.08 at 7:43 pm one small problem if you edit /etc/resolv.conf directly, the next time you ifdown or ifup an interface or reboot for that matter your settings are lost. In Ubuntu the resolv.conf is generated each time you up/down an interface. So unless you removed the resolvconf package which is generally installed by default, you need to add proper dns- entries to the /etc/network/interfaces file to make changes permanent. eg: iface eth0 inet static address netmask network broadcast gateway # dns-* options are implemented by the resolvconf package, if installed dns-nameservers dns-search

8 G7 02.01.08 at 7:39 am About dns-nameservers: if you have >1 dns servers they must be in 1 line separated by spaces. But not in 2-3 lines (it will hangup network startup script at all) !!!

9 Raj 02.01.08 at 1:54 pm I think only dhclient updates resolv.conf, look like ubuntu has some additional scripting at /etc/rc.d/*. On a side note, you can write protect resolv.conf
sudo chattr +i /etc/resolv.conf man chattr

10 pankaj 03.08.08 at 8:39 am How can i encrypted the file from VI. And how can i connect the internet in my home and I want also connect the localarea network. And what is joe editor explane.

11 pankaj 03.08.08 at 8:42 am How can i configer the server connection on my one more system If i would like the 1st system is an Administrator..

12 polarizer 04.01.08 at 12:45 pm This was very useful to me cause i wasnt able to find a way to accomplish that via dpkg-reconfigure or debconf. thx for sharing the polarizer


Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration Pagina 6 di 13

13 danny0085 04.08.08 at 7:29 pm a litle tutorial to how to configure DHCP dhcp

14 Tauxz 06.04.08 at 6:28 am how to i restart network i used: sudo /etc/init.d/networking restart /etc/init.d/networking restart bu still nothing happening, pls can you help me.

15 Tinapa Faletiute 06.16.08 at 8:18 am How to save after changing something in the terminal window for ubuntu 7.04?

16 Rim 06.25.08 at 4:03 pm This was incredibly helpful. I am a very experienced Windows admin but I still feel like a newbie when it comes to Linux. Not only did I complete the task I needed with your help, you also made me realize the difference between editing config files and just using ifconfig. Bookmarking your site.

17 Ray Malone 07.04.08 at 6:35 pm I have just started with Linux with ubuntu server 8.94. Never used Linux before. Just wanted to say thank you. Wanted to use Fixed Ip for the server and found your site and great instructions easily. Just wanted to say thanks.

18 dido 07.05.08 at 9:11 am Excellent. Thanks.

19 Randy 07.18.08 at 2:06 am Oh wow. Thank you so much for this tip!


Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration Pagina 7 di 13

20 ernest 07.28.08 at 3:10 am thanks for the tip. i think its working with my server :). when you have time, can you explain what these do (in resolv.conf): search nameserver thanks!!

21 Jason 07.30.08 at 11:43 am Thank you. Linux newbie here but slowly & surely getting there your guide did exactly what I needed. Thanks. Only odd thing for me was the instance of Ubuntu (JeOS 8.04.1 on VMWare ESX Server) only saw eth1 and not eth0 however the process still worked. Cheers.

22 David 08.11.08 at 1:27 pm This wont work, Wlan0 does not show up in this file. Where can I edit for Wlan0?

23 George 08.25.08 at 9:17 am This has helped me set-up the ethernet interface for my new ubuntu installation

24 Beyboo 11.09.08 at 6:46 am This is really excellent stuff. No wise guy talk, plain guru speak. I have saved this page as a PDF and am gonna use it for my future references. I am a Ubuntu Gnome user and am trying out Kubuntu Ibex (and KDE) for the first time. Its really a pain to set it up :(

25 dave beall 11.18.08 at 6:35 am thank you for your time and this helped me get this project going its people like you that are willing to help us newbies that makes the internet an invaluable tool.

26 David 11.18.08 at 4:32 pm and still my question goes unanswered, wlan0 does not exist in this file. Apparently wanting to help newbies is not the goal here =\


Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration Pagina 8 di 13

27 Richard 12.09.08 at 3:30 pm Excellent Info. Thanks for all your help.

28 Jackal 01.03.09 at 1:00 pm I am total new to ubuntu server 8.04 we are runnining a wireless network cross country and sharing one router to exit to the internet. Our lan use an ip range of to 192.168.255 . Now our present intranet works fine in windows but we are considdering changing to ubuntu . we presently use pppeoe to access the server ip address i need to setup to . our internet router is presently set to submask .Default gateway ubuntu server is now a barebone serveris there a step by step method tutorial of how to make my server work as a local intranet and international internet multiple web, email, and hosting server Please email me

29 anuu 02.17.09 at 11:54 am hmn its good tutorial, can u add litle bit explanations to: i setup lan and Internet sharing to my sisters pc and my laptop and thats all, but Im actually dont know much about correct netmasking, ip, i mean how to choose correct those: i mean ip: starting with 172 or 192 or 10 what differences ? i mean netmask or or.. ? thank you

30 ian 02.20.09 at 7:19 am Hi, I am new to networking. Can someone help me? I have a situation where I have two NIC cards in my Blade server. I have an Ethernet cable that comes from the router plugged into one of the NIC cards (that works and provides internet access for the blade server running Ubuntu 8.04). What I want to do since my second Ethernet cable is very short, is connect one end of the short cable to the second NIC card on the Blade server, and connect the other end of the short cable to the NIC card on my Windows Server 2003 so I can access the internet from the Windows machine. How do I go about getting the Windows server to access the internet? What configurations do I need to do on the Blade server and Windows server to make everything work? Your help is greatly appreciated. Thx!

31 anuu 02.20.09 at 8:18 pm ian setup ip_forward to on echo 1 > /proc/sys/net/ipv4/ip_forward and setup POSTROUTING, MASQUERADE to CARD2 that will share net to win /sbin/iptables -t nat -A POSTROUTING -o eth0 -s CARD2IPHERE -j MASQUERADE hm i think thats all


Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration Pagina 9 di 13

32 Ravi 02.23.09 at 5:25 pm Nice tutorial. Thanks and Keep it up.

33 Ali Raza 03.17.09 at 4:21 am thanx

34 Philip 04.02.09 at 10:23 pm Thank you for this website. I come from Window and this is my first time doing static IP on my LAN on a Linux. I am pretty familiar on setting it in Window. I just have these question. Host IP address (This would be my static IP that I want on this machine) => Netmask: => Network ID: (What is this?) => Broadcast IP: (What is this? Never seen in Window) => Gateway/Router IP: (This would my router IP) => DNS Server: (I do not use DNS. Can I put my ISP DNS?) On PC there is a alternate DNS server also. How do I include it here? Thanks for helping!

35 Cliff 04.05.09 at 2:31 pm Thanks for the tutorial. This is excellent reference material.

36 P.C.S.V.PRASAD 04.20.09 at 8:35 am IN WinXP i configured my network as follows IP : Sunbet : Gateway : Prf DNS : Alt DNS : But sugest me how to configure in UBUNTU Linux GUI I am not able to understand how it was taking Broad cast as Thaks

37 Gagan 04.22.09 at 7:43 am Thanks.. quick fix!


Howto: Ubuntu Linux convert DHCP network configuration to static IP configura... Pagina 10 di 13

38 arasu 05.20.09 at 7:40 pm excellent but i cannot save the terminal after changes. anyone can help me

39 Matey 05.28.09 at 12:06 pm Hello All: How do I change my MAC (HW) Address in Ubuntu? (for eth0) I know I can use ifconfig but the help files is full of these [[[ <>>]]] and m ore brackets and its too confusing, why couldnt they show the real command instead of all these brackets? Any way my connection is OK but I get refused!? (so wots new) lol ;-) I cant get on the i think my MAC address has been put on the black list of some sort.!? Thank You!

40 tutu 06.18.09 at 3:54 pm theres no etc/network on my RedHat 7.0 Linux. Where should I go from here? I was able to change the IP with the ifconfig but I would like to make it permanent. Thanks.

41 Vivek Gite 06.18.09 at 4:33 pm This tutorial is about Debian / Ubuntu Linux. For redhat update file /etc/sysconfig/network-scripts/ifcfgeth0. See our RedHat specific tutorial here.

42 tutu 06.18.09 at 8:01 pm Thank you, I got it.

43 Mehdy Mahmood 07.04.09 at 8:03 pm I have pppoe connection , i need to connect my pc to my local lan , so i have set up ip to my lan card . but we ever i set up the ip to my lan ,, my pppoe goes down , but lan works . so my lan and my pppoe works dont work together. please help me out . i need to work them together.

44 Amit Patel 07.11.09 at 6:12 am above blog was extremely helpful for me. thanking you a lot !! Leave a Comment Name *


Howto: Ubuntu Linux convert DHCP network configuration to static IP configura... Pagina 11 di 13

E-mail * Website

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> Notify me of followup comments via e-mail.

Tagged as: add gateway, change ip address, dhcp, host command, Linux, list open port, netstat command, network, Networking, sudo command, ubuntu Previous post: What you should (and shouldnt) expect from 64-bit Linux? Next post: QD#5: Linux Networx Pipes in $37M, Firefox Extending the Search Bar, Web dev in Linux tips, 8Core Mac Pro, College rags, SSH Tips, TCP/IP Guide Sign up for our daily email newsletter: Sign up

WISP-Router Inc Provides

MikroTik equipment and Solutions For your WISP/ISP network.

Fax Over IP
Send faxes through FOIP with GFI FAXmaker. New version 14 out now!

Wireless AutoSwitch
Automatically disable your wireless card when you connect by wire (LAN)

Tutta l'assistenza per navigare con Alice Adsl senza problemi.



Howto: Ubuntu Linux convert DHCP network configuration to static IP configura... Pagina 12 di 13

Fax Over IP Send faxes through FOIP with GFI FAXmaker. New version 14 out now!

Router Risolvi i problemi di connessione con l'assistenza online di Alice

Linux Free how-to slideshow. Install ubuntu in 7 easy steps. View now!

Remote Desktop Control Funziona dietro tutti i firewall. Prova gratuita senza registrazioni.

Related Posts
Best Linux / UNIX Posts of 2007: Part ~ I Easy Linux or UNIX Network Load Testing Configure static routes in Debian or Red Hat Linux systems

Free White Papers

Madness, Mergers, Acquisitions, and Divestitures. This paper presents the steps to swiftly and precisely execute a migration path... Removing the complexity from information protection; how encryption can add... With data breaches widespread, no organization can afford to be complacent, as... Achieving Rapid Data Recovery for IBM AIX Environments Planning for recovery is a requirement in businesses of all sizes. In...

More White Papers

Ubuntu Linux See all topics...

Sponsored Links
Kindle: Amazon's 6" Wireless Reading Device - The best e-reading system on the market. Fully functional design, better graphics and longer battery life. Gorgeous and sleeker than the original. Cricket is not just a game it is a religion for many of us! Daily Indian and World Cricket news, live score, links and much more! See your text ad here

2004-2009 nixCraft. All rights reserved | Privacy Policy | Terms of Service


Howto: Ubuntu Linux convert DHCP network configuration to static IP configura... Pagina 13 di 13

Advertise | Questions or Comments | Sitemap