Tag Archives: Static IP

Linux system administrators need to configure networking on their systems. On desktop machines, you can use dynamic IP addresses but on server infrastructure, you will need to set up a static IP address for a stable connection.

IP addresses on Linux systems are mostly assigned automatically by Dynamic Host Configuration Protocol (DHCP) servers. These are referred to as “dynamic addresses” and can change any time the system is rebooted. When a system is on a server or will be remotely administered, it is more convenient for these systems to have static addresses, offering stable and consistent connections with users and applications.

Fortunately, the steps required to setup a Linux system’s IP address from dynamic to static are fairly easy, though they will be a little different for the various distribution you are using. In this post, we’ll look at how this task is managed on RHEL/CentOS/Fedora and Debian/Ubuntu systems.

IP address: 192.168.0.100 Netmask: 255.255.255.0 Hostname: node01.linux-documentation.com Domain name: linux-documentation.com Gateway: 192.168.0.1 DNS Server1: 8.8.8.8 DNS Server2: 4.4.4.4

Configure Static IP Address in RHEL/CentOS/Fedora:

To configure the static IP address in RHEL / CentOS / Fedora, you will need to edit these files:

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

Where in the above "ifcfg-eth0" answers to your network interface namedeth0. If your interface is named “eth1" then the file that you have to edit is "ifcfg-eth1".

Let’s start editing the first file:

# vi /etc/sysconfig/network

Open that file and set the following:

NETWORKING=yes HOSTNAME=node01.linux-documentation.com GATEWAY=192.168.0.1 NETWORKING_IPV6=no IPV6INIT=no 

Now open next file as shown below:

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

Note: Make sure that you have opened the file corresponding to your network interface. You can get your network interface name using command ifconfig -a.

In that file you have to make the following changes:

DEVICE="eth0" BOOTPROTO="static" DNS1="8.8.8.8" DNS2="4.4.4.4" GATEWAY="192.168.0.1" HOSTNAME="node01.linux-documentation.com" HWADDR="00:19:99:A4:46:AB" IPADDR="192.68.0.100" NETMASK="255.255.255.0" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="8105c095-799b-4f5a-a445-c6d7c3681f07"

You will only need to edit the settings for i.e enter their respective values and save the file:

  1. DNS1 and DNS2
  2. GATEWAY
  3. HOSTNAME
  4. NETMASK
  5. IPADDR

Other settings should have already been predefined.

Next edit resolve.conf file by opening it with a text editor like nano or vi:

# vi /etc/resolv.conf
  
nameserver 8.8.8.8 # Replace with your nameserver ip
nameserver 4.4.4.4 # Replace with your nameserver ip

Once you have made your changes restart the networking with the following commands:

# /etc/init.d/network restart  [On SysVinit] 
# systemctl restart network [On SystemD]

Set Static IP Address in Debian / Ubuntu

To setup static IP address in DebianUbuntu, you have to open the following file:

# nano /etc/network/interfaces

You will see a line looking like this:

auto eth0
iface eth0 inet dhcp

Change it so it looks like this:

auto eth0
iface eth0 inet static 
  address 192.168.0.100
  netmask 255.255.255.0
  gateway 192.168.0.1
  dns-nameservers 4.4.4.4
  dns-nameservers 8.8.8.8

Save the file and then edit /etc/resolv.conf as follows:

# nano /etc/resolv.conf
nameserver 8.8.8.8 # Replace with your nameserver ip 
nameserver 4.4.4.4 # Replace with your nameserver ip

Restart the networking on your system with the following commands:

# /etc/init.d/network restart  [On SysVinit]
# systemctl restart network [On SystemD]

Your static IP address has been successfully configured.

Now, you know how to configure a static IP address on a Linux distro.