How to set static IP address on Unix
Written on September 22, 2008 at 8:01 am by
mkyong
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.0mkyong:~# 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.
This article was posted in Unix / Linux category.
Oracle Magazine - Free Magazine
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for Java's developers and DBAs, and more.
Securing & Optimizing Linux: The Hacking Solution - Free Guide
A comprehensive collection of Linux security products and explanations in the most simple and structured manner on how to safely and easily configure and run many popular Linux-based applications and services.
The Windows 7 Guide: From Newbies to Pros - Free Guide
In this 46 page guide you will be introduced to Windows 7 and what it has to offer. This guide will go over the software compatible issues, you will learn about the new taskbar, how to use and customize Windows Aero, what Windows 7 Libraries are all about, what software is included in Windows 7, and how easy networking is with Windows 7 along with other topics.
All Java Tutorials
- Java Core Technology - Java RegEx, Java XML, Java I/O, Java Misc
- J2EE Frameworks - Hibernate, Spring 2.5, Spring MVC, Struts 1.x, Struts 2.x
- Build Tools - Maven, Archiva
- Unit Test - jUnit, TestNG
- Client Scripts - jQuery
I’m trying to learn more about DNS/computer networking and I loved your post. Keep up the great work.
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
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.)