How to set static IP address on Unix

In Unix system like Debian, Ubuntu or Red Hat, It is possible to set a static IP address with ifconfig command.

My current Debian system IP address is

mkyong:~# ifconfig
eth0    Link encap:Ethernet  HWaddr 00:15:17:1D:CE:2F  
          inet addr:  Bcast:  Mask:

I want change it to, just issue following command to set a static IP address in unix

ifconfig eth0 netmask
mkyong:~# ifconfig eth0 netmask
mkyong:~# ifconfig
eth0    Link encap:Ethernet  HWaddr 00:15:17:1D:CE:2F  
          inet addr:  Bcast:  Mask:


P.S eth0 is your system network card.

Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


  • Browser Information

    I’m trying to learn more about DNS/computer networking and I loved your post. Keep up the great work.

  • Sanjeet

    I have connected 5 systems using switch and its not connected with internet cable.
    One of the system ipaddress is getting change even if dhclient is not running.I want static ipaddress. how can i continue, i dont want to configure ip addr using ifconfig again and again. how to avoid changing of ip address.


  • Jamieson Becker

    Excellent blog post! Here’s a few extra details on IP address configuration on Linux and UNIX.

    For UNIX, as well as Linux (which is not UNIX per se), ifconfig will only change the IP temporarily. You would have to run this ifconfig again after every bootup. The method for making such a change permanent is dependent on the system. In most systems, the “SEE ALSO” section of the ifconfig man page (i.e., “man ifconfig”) will refer you to the configuration files that are referenced on startup. Of course, just changing a config file will not force a change of the IP address until the next boot, so you may still want to use ifconfig as detailed above or force a restart of the network configuration.

    In Debian and derived distributions such as Ubuntu and SimplyMeppis, the network configuration is stored in the /etc/network/interfaces file.

    For Red Hat, Fedora, and derivatives such as Mandriva and CentOS, the file is /etc/sysconfig/network-scripts, such as ifcfg-eth0.

    Each of these files should be appropriately commented and/or have man pages associated with them.

    (And, of course, most systems have one or more GUI’s to edit these files, too, but these are highly system dependent. I recommend learning how to edit the text files when possible since GUI’s shouldn’t be installed on a server anyway, you can also easily write code to customize these files, and it’s generally much faster to edit a text file than it is to change something in a GUI.)