Network Configuration On Centos 7

admin13 April 2024Last Update :

Understanding Network Configuration in CentOS 7

CentOS 7, a popular Linux distribution for servers and professionals, uses a set of tools and files to manage network configurations. Understanding the basics of these tools and configuration files is essential for any system administrator or technical user looking to maintain a robust networking environment.

Network Management Tools

nmcli: The command-line tool for NetworkManager, which provides a high-level interface for configuring networking.
nmtui: A text-based user interface for NetworkManager.
ifcfg files: Located in /etc/sysconfig/network-scripts/, these files are used to configure network interfaces.
ip command: Part of the iproute2 package, it’s used for displaying and manipulating routing, devices, policy routing, and tunnels.
netstat: A command-line tool that displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

Static IP Address Configuration

Configuring a static IP address involves editing the ifcfg files associated with the network interface. Here’s an example of how to configure a static IP on an Ethernet interface named eth0.

# /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=your-uuid-here
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4

After editing the file, restart the network service to apply changes:

sudo systemctl restart network

Dynamic IP Address Configuration (DHCP)

For DHCP configuration, ensure the BOOTPROTO directive is set to dhcp.

# /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=dhcp
...

Again, restart the network service to apply the changes.

Network Interface Management

Managing network interfaces can be done using the ip command. For instance, to bring up an interface:

sudo ip link set dev eth0 up

To bring down an interface:

sudo ip link set dev eth0 down

Routing Configuration

Setting up routes is crucial for directing traffic to the correct destination. Routes can be added via the ip route command.

sudo ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0

DNS Configuration

DNS settings are specified in the resolv.conf file located at /etc/resolv.conf. To use Google DNS, you would add:

nameserver 8.8.8.8
nameserver 8.8.4.4

Firewall Configuration

CentOS 7 typically uses firewalld as its default firewall management tool. Opening a port can be done with the following command:

sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload

Network Troubleshooting Tools

Tools like ping, traceroute, and mtr are invaluable for troubleshooting network issues.

Advanced Network Configuration Techniques

Bonding Interfaces

Bonding multiple network interfaces can provide redundancy and increased throughput. This requires creating a bond interface configuration file and modifying the slave interfaces’ configuration files.

Team Driver

Similar to bonding but more flexible, the team driver allows for grouping interfaces together using a small daemon called teamd.

VLAN Tagging

Virtual LANs (VLANs) can be configured by creating a VLAN interface with an appropriate ID.

Bridge Networking

Bridges can be used to connect virtual machines to the physical network. This involves setting up a bridge interface and attaching physical or virtual interfaces to it.

Automation and Scripting

Ansible for Network Automation

Ansible is a powerful automation tool that can manage network configurations across multiple systems. It uses YAML for its playbook language.

Shell Scripting

Simple bash scripts can automate repetitive tasks such as restarting services or applying new configurations.

Frequently Asked Questions

How do I restart the network service in CentOS 7?

Use the command sudo systemctl restart network.

What is the difference between nmcli and nmtui?

nmcli is a command-line tool, while nmtui provides a text-based user interface. Both are used to interact with NetworkManager.

Can I use both NetworkManager and traditional ifcfg files?

Yes, NetworkManager utilizes ifcfg files for network configurations when not managed directly through its own interfaces.

How do I set a static IP address in CentOS 7?

Edit the corresponding ifcfg file for your network interface, setting BOOTPROTO to none and specifying IPADDR, PREFIX, and GATEWAY.

Where are network interface configurations stored in CentOS 7?

Interface configurations are stored in /etc/sysconfig/network-scripts/ directory.

References

Leave a Comment

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


Comments Rules :

Breaking News