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 10.70.0.61


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

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


ifconfig eth0 10.70.0.66 netmask 255.255.252.0

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

Done.

P.S eth0 is your system network card.

About the Author

author image
mkyong
Founder of Mkyong.com, 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.

Comments

Leave a Reply

avatar
newest oldest most voted
Jamieson Becker
Guest
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… Read more »
Browser Information
Guest
Browser Information

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

Sanjeet
Guest
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.

thankss

Aleph
Guest
Aleph

Is that possible using IPv6 and how to handle the submask there?