Friday, September 28, 2012

Static IP Address Configuration


To configure the Internet Protocol version 4 (IPv4) properties of a network connection with a static IP address for servers running Linux operating systems, you need to update and/or edit the network configuration files.

These configuration files are located on each Linux based system, as follow:
RHEL / Red hat / Fedora / CentOS Linux: /etc/sysconfig/network-scripts/
Debian / Ubuntu Linux: /etc/network/interfaces

Example Setup:

IP address: 192.168.1.10
Netmask: 255.255.255.0
Hostname: anneke.ceren.sys
Domain name: ceren.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. Edit /etc/sysconfig/network as follows:

# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=anneke.ceren.sys
GATEWAY=192.168.1.254

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

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

# Intel Corporation 82573E Gigabit Ethernet Controller (Copper)

DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:30:48:56:A6:2E
IPADDR=192.168.1.10
NETMASK=255.255.255.0
ONBOOT=yes

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

# vi /etc/resolv.conf
search ceren.sys
nameserver 192.168.1.254
nameserver 8.8.8.8
nameserver 202.54.2.5

Finally, you need to restart the networking service:
# /etc/init.d/network restart

No, we have to verify the new static ip configuration for eth0:
# ifconfig eth0
# route -n
# ping 192.168.1.254
# ping google.com

Debian / Ubuntu Linux Static IP Configuration:


Edit /etc/hostname:

# vi /etc/hostname

anneke.ceren.sys

Edit /etc/network/interfaces:

# vi /etc/network/interfaces

iface eth0 inet static
     address 192.168.1.10
     network 192.168.1.0
     netmask 255.255.255.0
     broadcast 192.168.1.255
     gateway 192.168.1.254

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

# vi /etc/resolv.conf 
search ceren.sys
nameserver 192.168.1.254
nameserver 8.8.8.8
nameserver 202.54.2.5

Finally, you need to restart the networking service:
# /etc/init.d/networking restart

Type the following commands to verify your new setup, enter:
# ifconfig eth0
# route -n
# ping google.com


Special Thanks to UnixCraft