• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 7 : Configuring static IP adress using network interface configuration files

By admin

There are various ways you can configure an IP address in RHEL 7. The posts discusses the use of network interface configuration files to configure the IP address. Each physical network device has an associated network interface configuration file. Network interface configuration files are located in the /etc/sysconfig/network-scripts directory.

1. Use the ip addr command to display your available network interfaces.

# ip addr
1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.104/24 brd 192.168.43.255 scope global dynamic eth0
       valid_lft 2792sec preferred_lft 2792sec
    inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe23:2fbc/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff

Note that you have 3 Ethernet interfaces (eth0, eth1) and the loopback interface (lo). If you interface names are somthing like eno16777736, refere this post to change the interface naming to eth0 and eth1.

2. cd into the /etc/sysconfig/network-scripts directory which holds the network interface configuration files.

# cd /etc/sysconfig/network-scripts

Here you would find the network configuration file for the eth1 interface i.e. ifcfg-eth1. If not already present you can copy the interface configuration file of interface eth0.

3. We want to assign IP address 192.168.1.30 to the interface eth1. Edit the configuration file for the interface and change the highlighted parameters as show below :

# vi ifcfg-eth1
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="no"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
NAME="eno16777736"
UUID="7fe712d2-5e3a-4f68-b34b-4b3f6c787a56"
ONBOOT="yes"
IPADDR0="192.168.1.30"
PREFIX0="24"
HWADDR="00:0C:29:D5:6E:9C"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"

4. Edit the /etc/hosts file to add the entry for the new IP address :

# cat /etc/hosts
127.0.0.1   	localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         	localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.30	geeklab

5. Restart the network services :

# systemctl restart network
# ip addr
1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.104/24 brd 192.168.43.255 scope global dynamic eth0
       valid_lft 2538sec preferred_lft 2538sec
    inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe23:2fbc/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.30/24 brd 192.168.1.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed5:6ea6/64 scope link
       valid_lft forever preferred_lft forever

Using network interface control scripts to stop/start a specific network interface

The network interface control scripts i.e. ifup and ifdown. Use the ifdown command to stop the interface and eno16777736. Verify the status of the interface using “if addr” command (the ip address should have disappeared):

# ifdown eth1
# ip a
1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.104/24 brd 192.168.43.255 scope global dynamic eth0
       valid_lft 2751sec preferred_lft 2751sec
    inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe23:2fbc/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff

Use the ifup command to start the interface again :

# ifup eth1
# ip addr
1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.104/24 brd 192.168.43.255 scope global dynamic eth0
       valid_lft 2720sec preferred_lft 2720sec
    inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe23:2fbc/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.30/24 brd 192.168.1.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed5:6ea6/64 scope link
       valid_lft forever preferred_lft forever

Filed Under: CentOS/RHEL 7

Some more articles you might also be interested in …

  1. How to create partitions and file systems on DM-Multipath devices
  2. How to add words to the dictionary cracklib uses for validating passwords against known dictionary words
  3. CentOS / RHEL 7 : How to disable all tty consoles and enable only 1
  4. How To Setup mutt in CentOS/RHEL
  5. How to Create a New /boot Partition in CentOS / RHEL
  6. How to set nproc (Hard and Soft) Values in CentOS / RHEL 5,6,7
  7. how to add a custom script to the systemd in CentOS/RHEL 7
  8. Beginners Guide to Udev in Linux
  9. ‘docker images’ command error – “Permission Denied”
  10. How to Mirror Swap, Boot and Root Partions in CentOS/RHEL 7 Using mdadm Utility

You May Also Like

Primary Sidebar

Recent Posts

  • How to Configure Automatic Package Updates on the Server in CentOS/RHEL 8
  • FATAL: Error inserting rds_rdma
  • Failed to start LSB: Bring up/down networking – On restarting network service CentOS/RHEL (DHCP client)
  • How To Add Timestamps To dmesg Kernel Boot Log in CentOS/RHEL
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary