In our today’s guide, we are about to learn how to configure a network interface on any Red Hat-based Linux Operating System like CentOS, RHEL, Scientific Linux and Oracle Linux are exactly same, because all of these operating system use Network Manager so you are good to follow the below guide and configure your first interface.
To configure the interface we are using Network Manager it is a dynamic network control and configuration manager. Network Manager is used on RHEL 7.0 based Operating System and above versions by running as a service. But still, we can use legacy network service on RHEL 7 based OS.
Managing Network Manager
We can manage Network Manager service using below commands, But keep in mind while running below commands it will affect all the interfaces in your system. So better use nmcli or ifup / ifdown to manage individual interfaces.
# systemctl start NetworkManager # systemctl restart NetworkManager # systemctl status NetworkManager
Easy way to learn and use nmcli
Firstly, Before starting with the below steps, install “bash-completion” package because it will help to complete the command with options and arguments using TAB key.
# yum install bash-completion -y
While running the nmcli command Type nmcli and press TAB twice to get the available options so that you can learn nmcli soon and make it more easier to understand.
Understanding Network Interface Configuration
If you understand what needs to be considered while configuring an interface it will be easier for you. While configuring an interface we should know below configuration lines.
For a better understanding, each line of below configuration is defined line by line.
[root@corcls3 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 DEVICE=ens33 NAME=ens33 TYPE=Ethernet BOOTPROTO=none ONBOOT=yes IPADDR=192.168.107.202 PREFIX=24 GATEWAY=192.168.107.2 DNS1=192.168.107.2 DOMAIN=linuxsysadmins.local IPV6INIT=no [root@corcls3 ~]#
Still, confused? have a look into below definition about above interface configuration.
- First, know the device name assigned by kernel etc. (eth0, ens32, enoxxx)
- Second, you can use any name for your connection profile.
- Type of the interface (Ethernet) we are about to configure.
- Which interface needs to be configured (ens32).
- Static IP Address method or DHCP to be configured.
- The interface needs to start persistently during reboot.
- If any static IP address
- Sub net you are about to use for your IP Address
- The gateway address of your subnet
- DNS server address
- DNS search domain(search linuxsysadmins.local)
- Whether IPv6 need to be created or not.
Print the available Physical Interfaces (NIC)
Let’s start to print and know the available physical interfaces.
# nmcli device
Or to print complete information about an interface. This is not required in common use because it will print all the information about an interface.
# nmcli device show
The output of other interfaces is removed and shown only for ens32. Very less information shown because we have not configured this interface yet.
[root@corcls3 ~]# nmcli device show GENERAL.DEVICE: ens32 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:D7:EF:CC GENERAL.MTU: 1500 GENERAL.STATE: 30 (disconnected) GENERAL.CONNECTION: -- GENERAL.CON-PATH: -- WIRED-PROPERTIES.CARRIER: on [root@corcls3 ~]#
We have two physical interfaces, One (ens33) is already configured and underuse. For demonstration purpose, we are about to use ens32 shown in RED colour.
- The first column shows the physical device name.
- Type of the device will be in the second column.
- State of the interface device in the third column.
- Finally, at last, the profile name or connection name.
The current status of connection has two dashes “–” which means the connection was not yet configured.
Once we know the interface let’s start to create connection profile without configuring an IP Address.
It is possible to create a connection name, assign the IP address, gateway, DNS, DNS search, IP assigning method, IPv6 etc in a single command.
However, to understand what we are doing, first, we will create only the profile name, Then modify the connection to assign an IP address, By following modify the connection and assign with DNS, DNS search, and much more.
Creating a Connection Profile
As soon as we confirmed with the physical interface, create the connection profile.
# nmcli connection add type ethernet ifname ens32 con-name prod
- nmcli – Command-line tool for controlling NetworkManager
- connection – To specify a connection profile to create.
- add – To add a new connection profile.
- type – To specify the type of Interface (Ethernet, Bridge, VLAN, Team, VLAN, WIFI etc).
- ethernet – We are creating an Ethernet type
- ifname – To specify the Interface
- ens33 – Our physical interface
- con-name – To create a connection profile name.
- prod – This is our connection profile name.
[root@corcls3 ~]# nmcli connection add type ethernet ifname ens32 con-name prod Connection 'prod' (93969447-cc11-4755-a858-6712cdd2a9cd) successfully added. [root@corcls3 ~]#
Configuring Static IP Address
Subsequently, modify the created connection and configure with a static IP Address and gateway
# nmcli connection modify prod ipv4.addresses 192.168.107.205/24 ipv4.gateway 192.168.107.2
After that modify the connection profile for other configurations.
Configure with DNS IP and Search Domain
Set the name server and search domain
# nmcli connection modify prod ipv4.dns 192.168.107.2,220.127.116.11 ipv4.dns-search linuxsysadmins.local
Multiple DNS IP Addresses can be used by placing a “,” one after another.
Make the Connection to Start Persistently
By following modify the connection profile to set the IP Address as static instead of DHCP and mark to start the interface persistently, this is exactly same as onboot=yes in Interface configuration file.
# nmcli connection modify prod ipv4.method manual ipv6.method ignore autoconnect yes
We are ignoring IPv6 in our demonstration, will cover it in a separate guide.
Verify the New Connection Profile
Print the created connection
# nmcli connection
We have our existing connection profile and the new one.
[root@corcls3 ~]# nmcli connection NAME UUID TYPE DEVICE ens33 d81c0666-39db-44d7-a8fd-f69e4fcc5af3 ethernet ens33 prod eb212e78-e078-4f73-8e83-08421d5c18f5 ethernet ens32 [root@corcls3 ~]#
To get more detailed information of your created connection profile.
# nmcli connection show prod
The output will be long and with detailed information.
[root@corcls3 ~]# nmcli connection show prod connection.id: prod connection.uuid: eb212e78-e078-4f73-8e83-08421d5c18f5 connection.stable-id: -- ----output truncated---- [root@corcls3 ~]#
At last, bring the interface offline and online to make the changes into effect, Then print the interface to verify.
# nmcli connection down prod # nmcli connection up prod
Print the configured interface
[root@corcls3 ~]# ifconfig ens32 ens32: flags=4163 mtu 1500 inet 192.168.107.205 netmask 255.255.255.0 broadcast 192.168.107.255 ether 00:0c:29:d7:ef:cc txqueuelen 1000 (Ethernet) RX packets 80398 bytes 4831594 (4.6 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 591 bytes 44777 (43.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@corcls3 ~]#
We can notice the IP Address and it only configured with IPv4 address.
By running above commands our configuration file will be populated and saved under the standard interface configuration location /etc/sysconfig/network-scripts/.
[root@corcls3 ~]# cat /etc/sysconfig/network-scripts/ifcfg-prod TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none IPADDR=192.168.107.205 PREFIX=24 GATEWAY=192.168.107.2 DNS1=192.168.107.2 DNS2=18.104.22.168 DOMAIN=linuxsysadmins.local DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no NAME=prod UUID=eb212e78-e078-4f73-8e83-08421d5c18f5 DEVICE=ens32 ONBOOT=yes [root@corcls3 ~]#
This is how network Interface configuration looks like after configuring it.
Configure Network Interface in a Single Go
As we said before, the all above steps can be run in a single go. However, you need to be familiar with using nmcli so you are good with creating interfaces.
Below single command will create a connection profile and Network Interface configurations.
- Assign a Static IP Address
- DNS Search domain
- OFF the DHCP
- Gateway address
- Marking interface to start persistently
- Ignore IPv6 configuration
# nmcli connection add type ethernet ifname ens32 con-name prod ipv4.addresses 192.168.107.205/24 ipv4.gateway 192.168.107.2 ipv4.dns 192.168.107.2,22.214.171.124 ipv4.dns-search linuxsysadmins.local ipv4.method manual ipv6.method ignore autoconnect yes
That’s it we have successfully configured a Network Interface by creating a profile and assign with a static IP address to it.
In Conclusion, Create a network interface on the Linux server using command-line tool nmcli. Will come up with more Linux networking articles in future. Subscribe to our newsletter and keep updated. Provide your feedback in below comment section.