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:

  • RHEL / Red hat / Fedora / CentOS Linux eth0 config file – /etc/sysconfig/network-scripts/ifcfg-eth0
  • RHEL / Red hat / Fedora / CentOS Linux eth1 config file – /etc/sysconfig/network-scripts/ifcfg-eth1
  • 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: 10.1.1.10
  • Netmask: 255.255.255.0
  • Hostname: server1.domain.com
  • Domain: domain.com
  • Gateway IP: 10.1.1.16
  • DNS Server IP # 1: 10.1.1.100
  • DNS Server IP # 2: 10.1.1.99

Update following common files

Entries in /etc/hosts must be in the following format:
IPv4_address hostname alias alias …
where:
IPv4_address must be in the first position
hostname is a fully-qualified domain name and must be in the second position.
aliases are optional and follow the address and hostname entries

$ cat /etc/hosts
127.0.0.1       localhost
10.1.1.10       server1.domain.com  server1.domain.com  server1
 
# The following lines are desirable for IPv6 capable hosts
::1     server1.domain.com server1.domain.com server1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
$ cat /etc/hostname
server1.domain.com

and run

cat -F /etc/hostname

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
NETWORKING=yes
HOSTNAME=server1.domain.com
GATEWAY=10.1.1.16

Edit /etc/sysconfig/network-scripts/ifcfg-eth0, enter:

$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:30:48:56:A6:2E
IPADDR=10.1.1.10
NETMASK=255.255.255.0
ONBOOT=yes

Edit /etc/resolv.conf and setup DNS servers, enter

$ cat /etc/resolv.conf
#Sample static IP configurations:
search domain.com
nameserver 10.1.1.100
nameserver 10.1.1.99

Finally, you need to restart the networking service, enter:

$ /etc/init.d/network restart
$ ifconfig eth0
$ route -n
$ ping 10.1.1.16
$ ping google.com

Debian / Ubuntu Linux Static IP Configuration
Edit /etc/hostname, enter:

$ cat /etc/hostname
server1.domain.com

Edit /etc/resolv.conf and setup DNS servers, enter:

  1. When resolvconf is installed
    $ cat /etc/network/interfaces
    iface eth0 inet static
         address 10.1.1.10
         network 10.1.1.0
         netmask 255.255.255.0
         broadcast 10.1.2.255
         gateway 10.1.1.16
         dns-search domain.com
         dns-nameservers 10.1.1.100 10.1.1.99
         # To add routing uncomment following line
         #up route add -net 10.1.2.0 netmask 255.255.255.0 gw 10.1.1.16
  2. When resolvconf is not installed
    $ cat /etc/network/interfaces
    iface eth0 inet static
         address 10.1.1.10
         network 192.168.1.0
         netmask 255.255.255.0
         broadcast 192.168.1.255
         gateway 10.1.1.16
         # To add routing uncomment following line
         #up route add -net 10.1.2.0 netmask 255.255.255.0 gw 10.1.1.16
    
    $ cat /etc/resolv.conf
    search domain.com
    nameserver 10.1.1.100
    nameserver 10.1.1.99

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 10.1.1.16
$ ping google.com
Advertisements