🌐 🇵🇱 Polski · 🇬🇧 EN
Networking is a key element for information exchange between systems. In this chapter, we will cover network configuration, DHCP and static IP addresses, troubleshooting, and DNS settings. Networking is a vital component of communication and serves as a window to the world for our environment. This material is not a source of knowledge about networking itself, so concepts such as gateway operations and other basic networking fundamentals should be understood before starting this chapter.
NETWORK CONFIGURATION IN LINUX
Network management is quite straightforward in a RedHat environment. Most settings are contained within files, making editing and changing configurations easy. To start, let's learn three basic commands:
- ifconfig - Displays the IP address and other information regarding the network interface
- route - Allows viewing or changing routing configuration
- system-config-network-tui - A tool - a menu used for network configuration
When working on network interfaces, two files are edited:
/etc/sysconfig/network - This file contains information about the gateway and hostname
/etc/sysconfig/network-scripts - A directory containing configuration files for network interfaces in the system
Let's start with the hostname and network information:
# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=RHEL01
The content of the file is easy to understand. The first two lines tell the system whether the network exists and if IPv4 and IPv6 protocols are available. By default, both are usually enabled; however, if you are not using IPv6 capabilities, it is good practice to disable it (by changing the value to "no" or removing the line). The next option included in the file is the hostname. Another option not mentioned in this example is the gateway, which informs the system which address is the gateway address. This entry is not visible by default because this setting is currently handled by DHCP. If we configure the system with a static IP address, we specify the gateway address in this file.
Tip
After changing the hostname, there is no need to restart the machine, but if you don't, there are still a few places where changes must be made. If the system is not critical or if you have enough time during the RedHat exam, it is better to perform a machine restart and let the system perform the necessary changes for us.
Next, let's move to the /etc/sysconfig/network-scripts location, where we will find many very important files related to the network. All network interfaces in the system have a configuration file that we can easily recognize by its specific name: ifcfg-ethX, where X denotes the number of the given interface. For example, a basic interface configuration file:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=08:00:27:30:74:AA
ONBOOT=yes
DHCP_HOSTNAME=RHEL01
TYPE=Ethernet
There are two important elements here. The first is DEVICE, which is the name of the interface. In the next line, it is specified which protocol the interface should use, and in this case, it is DHCP, which means the IP address is to be obtained from a DHCP server on the network. You probably want to know how to change this setting to a static IP address? You can change this setting manually, which is the fastest method for basic configuration.
STATIC IP ADDRESS
A quick method for configuring network interfaces is the "system-config-network-tui" tool. After launching it, we have a graphical interface at our disposal that allows changing settings on the fly. Let's change the settings of the second interface so that it has a static IP address.
Step 1 - Launching the tool:
# system-config-network-tui
Step 2 - Select which interface you want to configure
Step 3 - Editing the selected interface
Step 4 - Save and exit if we have finished editing
Now we know how simple it is to configure a selected network interface with a static IP address. The above changes can also be performed by directly editing the network interface files. After applying the changes, the network service must be restarted for the changes to take effect. Instead of disabling all interfaces, we can disable and restart only the specific one that was modified. To do this, use the "ifdown" and "ifup" commands. These commands are essentially a shorthand version of the "ifconfig" command.
Step 1 - Disabling the selected interface
# ifdown eth1
Step 2 - Enabling the selected interface
# ifup eth1
If the interfaces were configured with static IP addresses, we will not see anything on the screen after executing the above commands. If they are set to DHCP, a message about obtaining information from DHCP will appear after these commands. To verify the changes made, we always use the "ifconfig" command.
Syntax of the ifconfig command: # ifconfig [options] interface
Options for the ifconfig command:
- netmask MASK - Setting the mask for the interface
- hw ADDRESS - Setting the MAC address for the interface
- up - Bringing the interface up (starting)
- down - Bringing the interface down (stopping)
Let's see what changes were made:
# ifconfig eth1
Eth1 Link encap:Ethernet HWaddr 08:00:27:DB:D0:F5
inet addr:172.168.1.1 Bcast:172.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fedb:d0f5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:202 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:21322 (20.8 KiB)
Interrupt:9 Base address:0xd240
We can also see what changes appeared in the interface configuration file:
# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth1
BOOTPROTO=none
HWADDR=00:0c:29:e8:c3:80
ONBOOT=yes
DHCP_HOSTNAME=RHEL01
IPADDR=172.168.1.1
NETMASK=255.255.255.0
TYPE=Ethernet
Remember that after any changes to network interfaces, they should be restarted, and ideally, the entire network service should be restarted.
# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done.
[ OK ]
Bringing up interface eth1: [ OK ]
In the presented output of the network service restart, it can be seen that the eth0 interface is configured for DHCP because it is obtaining information from a DHCP server.
You can also set a static IP address for an interface by executing the command:
# ifconfig eth0 172.168.1.1 netmask 255.255.255.0
This command will have the identical effect as the actions performed in the system-config-network-tui menu.
Also worth reading: Configuring network interfaces in Linux



Comments