Configuring Linux Network Settings from the Command Line

posted October 18, 2016, 12:23 PM by

Jim Hannan (@jim_m_hannan), Principal Architect

In this blog I will discuss how to manually configure Linux network settings from the command line. While it may sound counter-intuitive to some, it is in my opinion (as well as that of many of my co-workers) the faster way to configure network settings.

First, let’s start by disabling NetworkManager. This tool is designed to make network setup quicker, but oftentimes just gets in the way and causes issues with interfaces getting misconfigured. We typically see issues after cloning a virtual machine.

Figure 1 – Disable the NetworkManager Service

[root@oel66 ~] # chkconfig NetworkManager off
[root@oel66 ~] # service NetworkManager stop


Next, find the interfaces that you will be configuring. For this virtual machine, we have one interface – ifcfg-eth0. Often after a clone, the interfaces numbers will increment to eth4 or eth5, etc. This happens because the clone creates new MAC addresses. If you would like get the interfaces number back to eth0, or eth1, you can edit the udev rules located in /etc/udev/rules.d/70-persistent-net.rules.

Figure 2 – Finding Network Interface Configurations

[root@oel66 network-scripts]# pwd
[root@oel66 network-scripts]# ls -l ifcfg-*
-rw-r–r–. 1 root root 231 Apr 24 2015 ifcfg-eth0
-rw-r–r–. 1 root root 254 Jul 22 2014 ifcfg-lo


With your favorite editor open to the interface file, edit the interface configuration file (see example below in Figure 3). We recommend, at a minimum, the following lines be included or added to the file as noted also noted Figure 3 below. For a clone, you will typically be changing the HWADDR and IPADDR network lines.

Figure 3 – Network Interface Settings

#Intel Corporation 82573E Gigabit Ethernet Controller (Copper)


That completes the interface configuration. Next we will look at the hostname and default gateway, so open the file /etc/sysconfig/network.

Figure 4 – Hostname & Gateway

[root@oel66 network-scripts]# cat /etc/sysconfig/network


Setting up DNS is completed in the /etc/resolv.conf file. In a simple DNS setup, for the scan listener in a home lab, there is a cool little package called dnsmasq that will make you a local machine for the first DNS server to check. As usual, does an awesome job of walking you through the setup.

Figure 5 – DNS Servers

[root@oel66 network-scripts]# cat /etc/resolv.conf


Finally, we will configure the host file with our hostname and new IP address.

Figure 6 – Editing the Host File

[root@oel66 network-scripts]# cat /etc/hosts localhost localhost.localdomain oel66.home.lab oel66


Hopefully, this article serves as a good guide for quickly and cleanly configuring network settings from the command line.

Share with your networkTweet about this on TwitterShare on LinkedInShare on FacebookDigg thisEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *


Share with your networkTweet about this on TwitterShare on LinkedInShare on FacebookDigg thisEmail this to someone