Configuring Linux Network Settings from the Command Line
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
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
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
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
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, oracle-base.com does an awesome job of walking you through the setup.
Figure 5 – DNS Servers
Finally, we will configure the host file with our hostname and new IP address.
Figure 6 – Editing the Host File
Hopefully, this article serves as a good guide for quickly and cleanly configuring network settings from the command line.