Configure IP address (Networking) in RHEL/CentOS 7
First thing that we do after installing an operating system is to configure the IP address i.e. networking on the machine. Whether we want to connect to internet or only to our local area network (LAN), we must provide information regarding our network to the machine. In this tutorial, we are going to discuss to configure an IP address in RHEL/CentOS 7 using three different methods,
(Recommended Read: IP Aliasing : Assigning multiple IP addresses to single NIC)
Method 1- By editing Network Interface file
This method works on all Linux distributions. To configure IP address, we need to open the network configuration file & pass our network information in the file. In RHEL/CentOS 7, location for all network interfaces is ‘/etc/sysconfig/network-scripts‘, in our case name of network interface is ‘ifcfg-en0s3’. We will now edit the file to configure a static IP address for our system. Open the network interface file,
To configure a static IP address, change the ‘BOOTPROTO‘ to ‘none‘ (it’s DHCP by default) & enter IP address, gateway & DNS information. Also change ‘ONBOOT‘ to ‘yes‘ so that we don’t have to start networking services everytime we restart our system.
After making all the changes, save the file & then restart the networking services to implement the changes.
Method 2 – Using graphical interface
If we are using RHEL/CentOS with GUI then we can easily configure IP address graphically. Open ‘Network’ either by clicking network icon & then selecting ‘Network Settings‘ on top-left corner of the screen or goto Applications-> System Tools-> Settings-> Network.
Next, click on the settings icon (on bottom right corner of the opened window) & select IPV4 then mention you network information on the opened window.
After the IP information has been edited, click on apply & exit from the menu. Lastly restart network services for implementing the changes.
Method 3- Using NMTUI command
This method can be used in GUI as well as in CLI. For using it in GUI mode, open a terminal and enter the command ‘nmtui’ & press enter or if using CLI , just enter the command ‘nmtui’ & press enter. This will open a new window with 3 options i.e. we can edit our network interface, activate a network interface or set a hostname for our system (read our tutorial on setting hostname HERE ).
To setup networking for the system, select ‘Edit a connection’, select your network interface & then select ‘Edit’ using the arrow keys. In the ‘IPv4 Configuration’ select ‘manual’ & then enter your network information.
After making changes, press ‘OK’ to save the file & on the next screen press ‘Quit’ to exit from the menu. Restart your network services for changes to take effect.
Apart from these three methods, you can also configure IP address when installing operating system & also there are two more methods through which we can configure our network on RHEL/CentOS 7 machines i.e. by using ‘nmcli command & ifconfig command. This wraps up our tutorial on how to configure IP address. For any queries/questions, please use comment box below.