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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • 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 use “btrfs scrub” command to manage scrubbing on Btrfs file systems
  2. Beginner’s Guide to LVM (Logical Volume Management)
  3. How To Disable Weak Cipher And Insecure HMAC Algorithms in SSH services for CentOS/RHEL 6 and 7
  4. How to Create a New /boot Partition in CentOS / RHEL
  5. How to disable NetworkManager on CentOS / RHEL 7
  6. What are “segfault” messages in /var/log/messages file
  7. ‘docker images’ command error – “Permission Denied”
  8. How To Separate Each Of Syslog Client’s Messages Into Different File (CentOS/RHEL 6 and 7)
  9. How to disable ICMP redirects on CentOS/RHEL
  10. Repairing filesystem issues at Boot in CentOS/RHEL 7 and 8

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright