Main Tutorials

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 Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Sanjeet
13 years ago

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

Jamieson Becker
15 years ago

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.)

Aleph
5 years ago

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

Browser Information
13 years ago

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