Earlier we have discussed how we can configure network connections using three different methods i.e. by editing network interface file, by using GUI & by using nmtui command (READ ARTICLE HERE). In this tutorial, we are going to use two other methods to configure network connections on our RHEL/CentOS machines. We are going to discuss 'nmcli' command & 'ifconfig' command in Linux.
First utility that we will be using is ‘nmcli’ command & we can configure network on almost any Linux distribution using this method.
(Recommended read :- Assigning multiple IP addresses to a single NIC)
Also Read: How to manage network in Ubuntu 18.04 – Netplan Command
Using NMCLI command in Linux
NetworkManager is used as default networking service on RHEL/CentOS 7 versions. It is a very powerful & useful utility for configuring and maintaining network connections. & to control the NetworkManager daemon we can use ‘nmcli’.
Syntax for using nmcli is,
$ nmcli [ OPTIONS ] OBJECT { COMMAND | help }
Viewing current network settings
To display the status of NetworkManager, run
# nmcli general status
to display only the active connections,
# nmcli connection show -a
to display all active and inactive connections, run
# nmcli connection show
to display a list of devices recognized by NetworkManager and their current status, run
# nmcli device status
Assigning IP address to an interface
To assign IP address & default gateway to a network interface, syntax for command is as follows,
# nmcli connection add type ethernet con-name CONNECTION_name ifname INTERFACE_name ip4 IP_address gw4 GATEWAY_address
Change the fields as per you network information, an example would be
# nmcli connection add type ethernet con-name office ifname enOs3 ip4 192.168.1.100 gw4 192.168.1.1
Unlike ifconfig command , we can set up a DNS address using nmcli command. To assign a DNS server to an interface, run
# nmcli connection modify office ipv4.dns "8.8.8.8"
Lastly, we will bring up the newly added connection,
# nmcli connection up office ifname enOs3
Enabling or disabling a network interface
For enabling an interface using nnmcli, run
# nmcli device connect enOs3
To disable an interface, run
# nmcli device disconnect enOs3
Using Ifconfig command in Linux
View current network settings
To view network settings for all the active network interfaces, run,
# ifconfig
To view network settings all active, inactive interfaces, run
# ifconfig -a
Or to view network settings for a particular interface, run
#ifconfig enos3
Assigning IP address to an interface
To assign network information on an interface i.e. IP address, netmask & broadcast address, syntax is
# ifconfig enOs3 IP_ADDRESS netmask SUBNET broadcast BROADCAST_ADDRESS
here, we need to pass information as per our network configurations. An example would be
# ifconfig enOs3 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
This will assign IP 192.168.1.100 on our network interface enOs3. We can also just modify IP or subnet or broadcast address by running the above command with only that parameter like,
# ifconfig enOs3 192.168.1.100
# ifconfig enOs3 netmask 255.255.255.0
# ifconfig enOs3 broadcast 192.168.1.255
Enabling or disabling a network interface
To enable a network interface, run
$ ifconfig enOs3 up
To disable a network interface, run
# ifconfig enOs3 down
Note:- When using ifconfig , entries for the gateway address are to be made in /etc/network file or use the following ‘route’ command to add a default gateway,
# route add default gw 192.168.1.1 enOs3
For adding DNS, make an entry in /etc/resolv.conf.
That’s it guys. There are many other uses for nmcli & ifconfig command in linux but examples mentioned here should just get you started. If having any issues/queries, please mention them in the comment box down below.
We are giving you exclusive deals to try Linux Servers for free with 100$ credit, check these links to claim your 100$,
DigitalOcean - 100$ free credit & Linode - 100$ free credit
Check some Exclusive Deals, HERE.
Also, check out DevOps Book You should read section.
The ifconfig and all related tools (route, arp, etc) are obsolete since very long time ago. Use “ip” from iproute2 instead.