April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

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

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

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>