Network Settings on CentOS 6

Network Settings on CentOS 6

After the installation of the CentOS 6 distribution, the Internet connection settings are set automatically, so you can immediately get to work in a browser or download packages from "Terminal".. However, sometimes the user has to change the settings of the current connection, create a new one, or switch to another existing network. In this case it is necessary to manually adjust the corresponding parameters using one of the available methods. We are going to talk about this below.

Network Settings on CentOS 6

All network settings, like most other settings, are stored in certain configuration files and are read by standard applications and services. The content of these files is what makes your Internet connection work. There are two different methods of correcting the required values: with the help of an additional utility or by modifying the content of the configuration documents. Below we will describe these two methods in detail and leave you the choice of the most suitable one.

Quick connection to the network

Before we start to discuss the full methods, we would like to mention the built-in ability to quickly connect to the network using the standard utility ifconfig. This option will be useful for those users who want to configure the IP address and subnet mask on their own. It is literally a matter of a few steps:

  1. Launch the standard console, for example via the application menu or by pressing the key combination Ctrl + Alt + T. In it he writes and activates ifconfigand then look at your existing interfaces to see which one to configure.
  2. Enter the command ifconfig eth0 netmask all the values, including the names of the interfaces, are replaced by the desired ones.
  3. If you ever need to disable an established connection, use sudo ifconfig eth0 down.
  4. This action is done on behalf of the superuser, so a password must be entered to grant root access.
  5. In case you need to get automatic connection parameters, you will need to replace the above commands with dhclient eth0.

Of course, this option allows you to literally establish a new connection in a couple of minutes, but it is not always possible to configure it to suit your users' needs, so we suggest checking the next two methods.

Method 1: TUI NetworkManager

The TUI NetworkManager application has a graphical interface appearance implemented through "Terminal".. This tool allows you to quickly manage existing networks and create new ones. However, this utility must first be installed on the system before you can edit the parameters.

  1. Download the latest version of the software through the official repository by entering sudo yum install NetworkManager-tui.
  2. Confirm your superuser account and wait for the download to complete.
  3. Start the TUI NetworkManager by executing the command nmtui.
  4. The main menu offers three actions to choose from - "Change connection.", Connect. и "Rename the node".. Let's start with the first point.
  5. In the list, find the appropriate connection type and proceed to edit it.
  6. At the top there are two fields in which you enter the name of the profile and the MAC address of the device used to organize the network.
  7. Details are revealed below "Ethernet". and individual protocol settings. Each field is filled in exclusively at the user's discretion. MAC address cloning, domain auto-discovery, and DNS servers are available here. Additionally, other routing parameters are configured.
  8. When a new connection is created, its type is selected first, which is necessary to generate the initial configuration.
  9. In the following, the procedure to manually create a network does not differ from the configuration of an existing network, except that the automatic connection and the access level are additionally set.
  10. In the list of networks, the active one is always marked, and to change it, use the arrows to scroll to the desired item and press the key. I went into.
  11. After the configuration is complete, restart the network service to update the configuration service network restart.

The considered method is more suitable for novice users who have not yet faced work on configuration files. However, it does have its downsides, such as limited functionality. No tool will provide a complete list of settings that you can change yourself in the settings.

Method 2: Edit the configuration file

All configuration files on Linux kernel-based operating systems are modified through various text editors. There are many such solutions, so the user usually chooses the best option himself. However, the choice of the program to open the configuration is not as important as the configuration process itself.

  1. Go to the console and navigate to the network configuration storage path by typing cd /etc/sysconfig/network-scripts/.
  2. We suggest passing the document through the editor dwarfintroducing sudo nano ifcfg-enp0s3where enp0s3 - name of the interface to modify. If the system does not already have this editor, pre-install it with sudo yum install nano.
  3. In the file you will see the parameters and their values, below we will talk about each element in detail. Now is the time to change everything you need.
  4. When you're done, apply your changes by clicking Ctrl + O and close the editor. Ctrl + X.
  5. Restart the network service service network restartto update the settings.

Now we are going to deal with the present parameters and consider two types of configuration - the static connection and obtaining the dynamic configuration via DHCP. In the file of the first type, the elements must have these values:

DEVICE=eth0 #Номер интерфейса, присвоенный системой
HWADDR=08:00:27:6c:e1:fc #MAC-адрес сетевого устройства. Не изменяется без надобности
TYPE=Ethernet #Тип соединения
UUID=e2f7b74a-ec49-4672-81cf-ff9c30d8ebdd #Идентификатор подключения
ONBOOT=yes #Автоматический запуск сети после загрузки операционной системы
NM_CONTROLLED=no #Включить или выключить контроль NetworkManager
BOOTPROTO=none #Не использовать DHCP
IPADDR= #IP-адрес
NETMASK= #Маска подсети
DNS1= #DNS-сервер
IPV6INIT=no #Отключение протокола IPv6
USERCTL=no #Запрет пользователю без привилегий управлять сетевым интерфейсом

We have placed descriptions of each line behind the #which is a comment in the config file. So you can copy it, changing the values ​​and leaving the line descriptions, so you remember what each line does in the future. This content is the standard for a static connection, but for a dynamic connection via DHCP the view changes a bit:

DEVICE=eth0 #Номер интерфейса, присвоенный системой
HWADDR=08:00:27:6c:e1:fc #MAC-адрес
TYPE=Ethernet #Тип интерфейса
UUID=e2f7b74a-ec49-4672-81cf-ff9c30d8ebdd #ИД интерфейса
ONBOOT=yes #Включать интерфейс при загрузке
NM_CONTROLLED=no #Контролируется ли интерфейс службой NetworkManager
BOOTPROTO=dhcp #Использовать DHCP
IPV6INIT=no #Отключение протокола IPv6
USERCTL=no #Запрет пользователям на управление этим интерфейсом

As you can see, in the second case, the IP address and the subnet mask are obtained automatically, because here the DHCP technology intervenes, the main thing is to specify it in the configuration file, so that all actions are successful. After making all the changes to the document, be sure to save it and restart the network service for all the updates to take effect.

Firewall configuration in CentOS

Another important component of any network connection is a firewall, also known as a firewall. Thanks to it, traffic is filtered and provides security for data transmission. The action of this same firewall depends on the installed rules, which are activated by default or are configured by each user individually. By default, CentOS uses FirewallD, the standard firewall management tool, which you can find a detailed guide on how to configure in our other article at the link below.

Read more: Firewall Configuration in CentOS

Sometimes users prefer a different tool - iptables. Basically, this utility is almost analogous to FirewallD, but with some features. Therefore, the user has to choose which firewall management solution to choose. We recommend that you also study the topic of editing iptables, and then choose the utility that suits you best.

Read more: Configuration of iptables in CentOS

Now you are familiar with all the steps of network configuration in CentOS 6 distribution. It only remains to choose one of the two presented methods and follow the given instructions. I would like to point out that editing the configuration file should always be done with the greatest possible care to avoid errors when entering parameters and values. A single mistake can lead to failure on the Internet.

We are glad that we were able to help you with your problem.

Describe what has not worked for you.
Our specialists will try to respond as quickly as possible.

Has this article helped you?

Creative stop
a how to do
Heroes Zone