Linux Static IP Address Configuration

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?

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/network-scripts/ifcfg-eth0
  2. RHEL / Red hat / Fedora / CentOS Linux eth1 config file – /etc/sysconfig/network-scripts/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:
  • Netmask:
  • Hostname:
  • Domain name:
  • Gateway IP:
  • DNS Server IP # 1:
  • DNS Server IP # 2:
  • DNS Server IP # 3:

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:
# cat /etc/sysconfig/network
Sample static ip configuration:


Edit /etc/sysconfig/network-scripts/ifcfg-eth0, enter:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
Sample static ip configuration:

# Intel Corporation 82573E Gigabit Ethernet Controller (Copper)

Edit /etc/resolv.conf and setup DNS servers, enter:
# cat /etc/resolv.conf
Sample static IP configurations:


Finally, you need to restart the networking service, enter:
# /etc/init.d/network restart
To verify new static ip configuration for eth0, enter:
# ifconfig eth0
# route -n
# ping
# ping

Debian / Ubuntu Linux Static IP Configuration

Edit /etc/hostname, enter:
# cat /etc/hostname
Sample ip config:

Edit /etc/network/interfaces, enter:
# cat /etc/network/interfaces
Sample static ip config:

iface eth0 inet static

Edit /etc/resolv.conf and setup DNS servers, enter:
# cat /etc/resolv.conf
Sample dns static IP configurations:


Finally, you need to restart the networking service under Debian / Ubuntu Linux, enter:
# /etc/init.d/networking restart
Type the following commands to verify your new setup, enter:
# ifconfig eth0
# route -n
# ping

See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 23 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
23 comments… add one
  • tasuke Dec 5, 2011 @ 14:49

    Very helpful…thanks alot

  • John Dec 9, 2011 @ 5:02

    YAY, easy as pie, thanks.

    • Mingpeng Mar 1, 2012 @ 3:33

      very clever

  • Mohamed Jan 21, 2012 @ 11:11

    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…???

    • Ricky Mar 29, 2012 @ 3:34

      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 – 200 and then you know you can freely use any ip up to and not have to add it in the reservations because the dhcp wont assign below 100

  • Shekhar Raut Jun 12, 2012 @ 4:29

    But if I have two NIC cards and I have to give different hostnames for evry ip.
    Is this possible?

    NIC 1 :
    NIC 2 :

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

    • Betro Hakala Mar 30, 2015 @ 22:13

      in /etc/hosts server1 server2

  • KR-Tech Nov 6, 2012 @ 10:08

    Awesome, helped me out using Raspberry Pi Debian.

  • A J Nov 19, 2012 @ 17:45

    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?

  • Yogesh Dec 19, 2012 @ 8:42

    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!

  • Vimal Jan 8, 2013 @ 14:41

    Cyberciti, whenever I come here, I am done with my solution. Thank you so much.
    Keep it up :)

  • Ace Apr 29, 2013 @ 22:19

    on HREL/CentOS it didn’t work.

    After restarting it connected, (pinged google ok) but pinging the IP I set returned unknown host


  • null May 9, 2013 @ 2:04

    dont forget “auto eth0”

  • shufil Jun 5, 2013 @ 11:07

    For set Centos Static IP Address Configuration need this configuration

    vi /etc/sysconfig/network-scripts/ifcfg-eth0


  • Johny Jun 10, 2013 @ 16:23

    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

  • akram Feb 17, 2014 @ 15:03

    thanks a lot it’s perfect explain
    I was suffering from IP problem between VMware and local computer there isn’t connection when I was using Putty to do connect to linux on VMware.

    once again thanks million *_^

  • Mustafa Mar 3, 2014 @ 1:59

    Good useful information. It was very helpful

  • Mohan Apr 30, 2014 @ 7:10

    thanks a lot dear please keep sharing this kind to knowledge to our all linux users.

  • derek May 9, 2014 @ 21:56

    Doesn’t look like it’ll work when you need something like this.

    ip a a dev lo
    ip a a dev lo

    • sammer Nov 27, 2014 @ 6:09

      thanks its very help full site for user but one request for you Add search box in web page for finding more details which i want.

  • m.ghodsi Jun 19, 2015 @ 6:22

    Helped a lot, thx

  • Hitter Ken Jan 29, 2016 @ 12:01

    Than you dude. Worked like a charm

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum