19/12/2013

Linux Static IP Address Configuration

Tutorials BASH Shell Troubleshooting Nginx Networking MySQL Google Cloud Platform Amazon Cloud Computing Rackspace Cloud Computing Linux CentOS Debian / Ubuntu Ubuntu Linux Suse RedHat and Friends Slackware Linux UNIX AIX Mac OS X FreeBSD FreeBSD Jails (VPS) Openbsd Solaris See all tutorial topics Blog About Contact us Forum Linux Scripting Guide RSS/FEED

Linux FAQ / Howtos

Linux Static IP Address Configuration
by Nix Craft on April 23, 2011 · 15 comments· LAST UPDATED April 23, 2011 in Debian / Ubuntu, Linux, Networking How do I configure the Internet Protocol version 4 (IPv4) properties of a network connection with a static IP address for servers running Linux operating systems? How do I configure static IP address under Debian Linux or Redhat / RHEL / Fedora / Redhat Enterprise Linux server?
www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/ 1/11

19/12/2013

Linux Static IP Address Configuration

You need to update and/or edit the network configuration files. This tutorial provides procedures to configure a static IP address on a computer running the following operating systems: 1. RHEL / Red hat / Fedora / CentOS Linux eth0 config file - /etc/sysconfig/networkscripts/ifcfg-eth0 2. RHEL / Red hat / Fedora / CentOS Linux eth1 config file - /etc/sysconfig/networkscripts/ifcfg-eth1 3. Debian / Ubuntu Linux - /etc/network/interfaces

Sample Setup: Linux Static TCP/IP Settings
In this example you will use the following Internet Protocol Version 4 (TCP/IPv4) Properties including IP, default gateway, and preferred DNS servers: IP address: 192.168.1.10 Netmask: 255.255.255.0 Hostname: server1.cyberciti.biz Domain name: cyberciti.biz Gateway IP: 192.168.1.254 DNS Server IP # 1: 192.168.1.254 DNS Server IP # 2: 8.8.8.8 DNS Server IP # 3: 202.54.2.5

RHEL / Red hat / Fedora / CentOS Linux Static IP Configuration
For static IP configuration you need to edit the following files using a text editor such as vi. Edit /etc/sysconfig/network as follows, enter:
#c a t/ e t c / s y s c o n f i g / n e t w o r k

Sample static ip configuration:
N E T W O R K I N G = y e s H O S T N A M E = s e r v e r 1 . c y b e r c i t i . b i z G A T E W A Y = 1 9 2 . 1 6 8 . 1 . 2 5 4

Edit /etc/sysconfig/network-scripts/ifcfg-eth0, enter:
#c a t/ e t c / s y s c o n f i g / n e t w o r k s c r i p t s / i f c f g e t h 0

Sample static ip configuration:
#I n t e lC o r p o r a t i o n8 2 5 7 3 EG i g a b i tE t h e r n e tC o n t r o l l e r( C o p p e r ) D E V I C E = e t h 0 B O O T P R O T O = s t a t i c D H C P C L A S S = H W A D D R = 0 0 : 3 0 : 4 8 : 5 6 : A 6 : 2 E I P A D D R = 1 9 2 . 1 6 8 . 1 . 1 0 N E T M A S K = 2 5 5 . 2 5 5 . 2 5 5 . 0 O N B O O T = y e s

www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/

2/11

19/12/2013

Linux Static IP Address Configuration

Edit /etc/resolv.conf and setup DNS servers, enter:
#c a t/ e t c / r e s o l v . c o n f

Sample static IP configurations:
s e a r c hc y b e r c i t i . b i z n a m e s e r v e r1 9 2 . 1 6 8 . 1 . 2 5 4 n a m e s e r v e r8 . 8 . 8 . 8 n a m e s e r v e r2 0 2 . 5 4 . 2 . 5

Finally, you need to restart the networking service, enter:
#/ e t c / i n i t . d / n e t w o r kr e s t a r t

To verify new static ip configuration for eth0, enter:
#i f c o n f i ge t h 0 #r o u t en #p i n g1 9 2 . 1 6 8 . 1 . 2 5 4 #p i n gg o o g l e . c o m

Debian / Ubuntu Linux Static IP Configuration
Edit /etc/hostname, enter:
#c a t/ e t c / h o s t n a m e

Sample ip config:
s e r v e r 1 . c y b e r c i t i . b i z

Edit /etc/network/interfaces, enter:
#c a t/ e t c / n e t w o r k / i n t e r f a c e s

Sample static ip config:
i f a c ee t h 0i n e ts t a t i c a d d r e s s1 9 2 . 1 6 8 . 1 . 1 0 n e t w o r k1 9 2 . 1 6 8 . 1 . 0 n e t m a s k2 5 5 . 2 5 5 . 2 5 5 . 0 b r o a d c a s t1 9 2 . 1 6 8 . 1 . 2 5 5 g a t e w a y1 9 2 . 1 6 8 . 1 . 2 5 4

Edit /etc/resolv.conf and setup DNS servers, enter:
#c a t/ e t c / r e s o l v . c o n f

Sample dns static IP configurations:
s e a r c hc y b e r c i t i . b i z n a m e s e r v e r1 9 2 . 1 6 8 . 1 . 2 5 4 n a m e s e r v e r8 . 8 . 8 . 8 n a m e s e r v e r2 0 2 . 5 4 . 2 . 5

Finally, you need to restart the networking service under Debian / Ubuntu Linux, enter:
www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/ 3/11

19/12/2013

Linux Static IP Address Configuration

#/ e t c / i n i t . d / n e t w o r k i n gr e s t a r t

Type the following commands to verify your new setup, enter:
#i f c o n f i ge t h 0 #r o u t en #p i n gg o o g l e . c o m

See also: RHEL / Redhat / CentOS / Fedora Linux network configuration tutorial using GUI and config files. Debian / Ubuntu Linux network configuration tutorial
Tw eet 3 Like 31 6

Featured Articles: 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X Top 30 Nmap Command Examples For Sys/Network Admins 25 PHP Security Best Practices For Sys Admins 20 Linux System Monitoring Tools Every SysAdmin Should Know 20 Linux Server Hardening Security Tips Linux: 20 Iptables Examples For New SysAdmins Top 20 OpenSSH Server Best Security Practices Top 20 Nginx WebServer Best Security Practices 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors 15 Greatest Open Source Terminal Applications Of 2012 My 10 UNIX Command Line Mistakes Top 10 Open Source Web-Based Project Management Software Top 5 Email Client For Linux, Mac OS X, and Windows Users The Novice Guide To Buying A Linux Laptop { 15 comments… read them below or add one } 1 tasuke December 5, 2011 at 2:49 pm Very helpful…thanks alot Reply 2 John December 9, 2011 at 5:02 am YAY, easy as pie, thanks.
www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/ 4/11

19/12/2013

Linux Static IP Address Configuration

Reply 3 Mingpeng March 1, 2012 at 3:33 am very clever Reply 4 Mohamed January 21, 2012 at 11:11 am i am facing problem her in Ubuntu server i made static IP and it worked as ping from it and to it . after 5 min i can not ping to ubuntu but i used ifconfig i found my ip as it is and ping from ubunto to any pc is fine, i made ifdown then ifup it works again but after about time stopped ping from outside…??? Reply 5 Ricky March 29, 2012 at 3:34 am Sounds like you have another machine useing the ip address, try doing ifdown and then ping from another machine to your ip address if you get reply, change your static ip to one that gets no respose do a ping first to check if the ip is in use, this way you can ensure you have a unique address, if using a dhcp make sure you add a reservation into it else it could happen again where the server is not getting a lease so the dhcp will assign on request to a machine, good idea is to set your dhcp range to something like xxx.xxx.xxx.100 – 200 and then you know you can freely use any ip up to xxx.xxx.xxx.99 and not have to add it in the reservations because the dhcp wont assign below 100 Reply 6 Shekhar Raut June 12, 2012 at 4:29 am But if I have two NIC cards and I have to give different hostnames for evry ip. Is this possible? example NIC 1 : 192.168.1.1 HOSTNAME : server1.abcd.com NIC 2 : 192.168.2.1 HOSTNAME : server2.xyzf.com So is this possible on one system?? In DNS server I have made this entry. How can I resolve this ip/hostname from the machine itself. I am new in this field. Please advise me. ( I guess I can do this entries in /etc/hosts. Is this right??) Reply 7 KR-Tech November 6, 2012 at 10:08 am
www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/ 5/11

19/12/2013

Linux Static IP Address Configuration

Awesome, helped me out using Raspberry Pi Debian. Reply 8 A J November 19, 2012 at 5:45 pm Thanks, I was able to resolve my ip addressing problem…now it’s not resolving dns and yes I added the dns ip’s to resolv.conf. What a nose bleed! Is it just me or or is just beyond stupid Centos has problems connecting to the net out of the box??!? Reallllly? Reply 9 Yogesh December 19, 2012 at 8:42 am I don’t want DHCP to push DNS info in my resolv.conf. How do I achieve that? What I tried and didn’t help:1.Disable dns in /etc/nsswitch.conf 2.Disable dns in /etc/resolv.conf 3.Service network restart (obtain IP from DHCP) 4.Check resolv.conf to discover that dns ip is written in resolv.conf again! Reply 10 Yogesh December 19, 2012 at 8:47 am Dear Vivek Please delete my comment :-) I found the solution here: http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-dhcp-configuring-client.html PEERDNS=, where is one of the following: yes — Modify /etc/resolv.conf with information from the server. If using DHCP, then yes is the default. no — Do not modify /etc/resolv.conf. Reply 11 Vimal January 8, 2013 at 2:41 pm Cyberciti, whenever I come here, I am done with my solution. Thank you so much. Keep it up :) -Vimal Reply 12 Ace April 29, 2013 at 10:19 pm on HREL/CentOS it didn’t work.

www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/

6/11

19/12/2013

Linux Static IP Address Configuration

After restarting it connected, (pinged google ok) but pinging the IP I set returned unknown host :( Reply 13 null May 9, 2013 at 2:04 am dont forget “auto eth0″ Reply 14 shufil June 5, 2013 at 11:07 am For set Centos Static IP Address Configuration need this configuration vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=none HWADDR=e0:66:90:03:98:5b IPADDR=192.168.2.3 NETMASK=255.255.255.0 ONBOOT=yes GATEWAY=192.168.2.1 TYPE=Ethernet USERCTL=no IPV6INIT=no PEERDNS=yes Reply 15 Johny June 10, 2013 at 4:23 pm Hi i have this strange problem that on centOS running inside VirtualBox i set the IP Address and after sometime the configurations are lost and the interface has no IP Address. I have no clue why this is happeneing? Can someone please help. Its like i setup everything restart, fine i have ip there but after like a min or 40+ seconds configurations are lost. i set again with ifconfig, they stay for sometime and then reset again, what should i do? Please help Reply Leave a Comment Name * E-mail *

www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/

7/11

19/12/2013

Linux Static IP Address Configuration

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title=""> Notify me of followup comments via e-mail
Submit

Tagged as: /etc/HOSTNAME, /etc/init.d/network restart, /etc/init.d/networking restart, /etc/network/interfaces, /etc/resolv.conf, /etc/sysconfig/network, /etc/sysconfig/network-scripts/ifcfg-eth0, /etc/sysconfig/network-scripts/ifcfgeth1, default gateway, dns servers, enterprise linux, gateway ip, internet protocol version, internet protocol version 4, network configuration, network interfaces, network scripts, networking service, setup linux, static ip address, static ip configuration, tcp ip settings Previous Faq: Ubuntu Linux Stop a Process Next Faq: Linux Install an RPM File

GET FREE LINUX TIPS
Sign up for our newsletter to get howto & news
you@example.com Sign Up

Twitter - Google plus - Video Tutorials and Demos

Loading

www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/

8/11

19/12/2013

Linux Static IP Address Configuration

nix Craft
Replace user and try again. Follow 511 followers

www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/

9/11

19/12/2013

Linux Static IP Address Configuration

Related Faqs

Redhat Linux Network Interface Configuration (NIC) File Location

CentOS / Redhat: KVM Bridged Network Configuration

Linux Display Ethernet Bridge Name and Information

Ubuntu Static IP

Ubuntu Linux Configure Gateway / Default Routing IP Address

Linux command to remove virtual interfaces or network aliases
www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/ 10/11

19/12/2013

Linux Static IP Address Configuration

Red Hat / CentOS: Swap / Change Ethernet Aliases

Ubuntu Restart Network

HowTo Red Hat Enterprise Linux 5 Configure The Network Card

HowTo: Linux Restart Network Interface

Latest posts from our blog
Download Of The Day: Fedora Linux 20 (Heisenbug) CD / DVD ISO Valve SteamOS: A Linux-based Gaming Operating System Announced Download of the day: Half-Life 2 For Steam on Linux Download of The Day: Debian Linux 7 ( Wheezy ) Apache / Nginx: Visualize Web Server Access Log In Real Time ©2006-2013 nixCraft. All rights reserved. Cannot be reproduced without written permission. Privacy Policy | Terms of Service | Questions or Comments | Sitemap

www.cyberciti.biz/faq/linux-configure-a-static-ip-address-tutorial/

11/11

Sign up to vote on this title
UsefulNot useful