How To Set Static IP Address on CentOS Stream 10
Setting up a static IP address is a crucial task for server administrators working with CentOS Stream 10. Unlike dynamic IP addresses that can change after reboots, static IPs ensure your server maintains the same address consistently, making it reliable for hosting services like web servers, databases, or DNS. This comprehensive guide walks you through multiple methods to configure static IP addresses on CentOS Stream 10, providing detailed instructions for different approaches and best practices.
Introduction
CentOS Stream 10 represents the latest evolution in the CentOS ecosystem, bringing modern networking capabilities and management tools. For servers and network infrastructure, static IP configuration is essential for maintaining consistent connectivity and enabling reliable service delivery. Whether you’re setting up a web server, database server, mail server, or any critical network component, proper IP configuration forms the foundation of your system’s networking.
Static IP addresses offer numerous advantages over dynamic addressing, particularly in server environments. They provide consistent access points for services, simplify firewall rule management, allow for more straightforward DNS configuration, and eliminate the dependency on DHCP servers. On CentOS Stream 10, the process of configuring static IPs has evolved significantly from earlier versions, with NetworkManager now taking center stage as the preferred network configuration tool.
This guide provides detailed, step-by-step instructions for configuring static IP addresses on CentOS Stream 10 using various methods, from the recommended command-line utilities to direct configuration file editing. We’ll also cover verification, troubleshooting, and best practices to ensure your network configuration is robust and reliable.
Prerequisites and Preparation
Before diving into the configuration process, ensure you have the following prerequisites in place:
System Requirements
To follow this guide effectively, you need:
- A functioning CentOS Stream 10 installation
- Administrative (root) access to the system
- Basic understanding of networking concepts
- Terminal access (either direct or via SSH)
Required Privileges
All commands in this guide require root privileges. You can either log in as the root user or use the sudo
command before each operation. For consistency, we’ll include sudo
where appropriate.
Essential Networking Information
Before configuring a static IP, gather the following information:
- The desired static IP address for your server
- Subnet mask (or CIDR prefix)
- Default gateway IP address
- DNS server addresses (primary and secondary)
- Your network interface name
To identify your network interfaces, run:
nmcli device status
This command displays available network devices and their connection status. The output will show device names like enp1s0
or similar. Note that interface names in modern Linux distributions follow predictable naming conventions and may not be the traditional eth0
that experienced administrators might expect.
You can also view detailed information about existing connections:
nmcli connection show
This provides information about configured network connections, including their UUIDs and types.
Understanding CentOS Stream 10 Network Management
NetworkManager vs. Legacy Methods
CentOS Stream 10, following the path set by RHEL 8 and later, has fully embraced NetworkManager as the standard network configuration tool. The legacy network-scripts method is deprecated, though it may still function for backward compatibility.
This shift represents a significant change in how network configurations are managed. Key differences include:
- NetworkManager operates as a daemon that actively manages network connections
- Configuration changes can be applied without full network service restarts
- Better support for modern networking features
- Improved integration with other system components
While longtime CentOS administrators might be tempted to use the familiar network-scripts method, embracing NetworkManager is recommended for forward compatibility and access to newer features.
Network Configuration Architecture
In CentOS Stream 10, network configurations are primarily stored in:
/etc/NetworkManager/system-connections/
– Contains connection profiles/etc/NetworkManager/NetworkManager.conf
– Main configuration file/etc/NetworkManager/conf.d/
– Additional configuration files
Each connection profile is stored as an individual file with a .nmconnection
extension, containing all parameters for that specific network connection. These files use an INI-style format with sections for different aspects of the connection, including general properties, IPv4/IPv6 settings, and device-specific configurations.
Method 1: Using nmcli Command Line Tool
The NetworkManager Command-Line Interface (nmcli) is the recommended tool for configuring networks on CentOS Stream 10. It provides a straightforward and scriptable way to manage network connections.
Identifying Network Interfaces
First, identify your network interfaces:
nmcli device
This displays output similar to:
DEVICE TYPE STATE CONNECTION
enp1s0 ethernet connected enp1s0
lo loopback connected lo
Make note of the device name (in this example, enp1s0
) as you’ll need it throughout the configuration process.
Configuring Static IP with nmcli
To configure a static IP address using nmcli, follow these steps:
1. Set the IP addressing method to manual (static):
sudo nmcli connection modify enp1s0 ipv4.method manual
2. Assign the static IP address with subnet prefix:
sudo nmcli connection modify enp1s0 ipv4.addresses 10.0.0.30/24
3. Configure the default gateway:
sudo nmcli connection modify enp1s0 ipv4.gateway 10.0.0.1
4. Set DNS servers:
sudo nmcli connection modify enp1s0 ipv4.dns 10.0.0.10
5. Ensure the connection starts automatically on boot:
sudo nmcli connection modify enp1s0 connection.autoconnect yes
Replace enp1s0
with your actual interface name, and use appropriate IP addresses, gateway, and DNS servers for your network.
For multiple DNS servers, specify them with spaces:
sudo nmcli connection modify enp1s0 ipv4.dns "8.8.8.8 8.8.4.4"
You can also set DNS search domains (your domain name):
sudo nmcli connection modify enp1s0 ipv4.dns-search "example.com"
Applying and Verifying Configuration
After configuring the static IP, apply the changes by restarting the connection:
sudo nmcli connection up enp1s0
Verify that your changes have been applied correctly:
ip addr show enp1s0
This displays the IP address configuration for the specified interface. Check that the IP address, netmask, and other settings match what you configured.
You can also verify the connection details using:
nmcli connection show enp1s0
To test connectivity, try pinging your default gateway and an external domain:
ping -c 4 10.0.0.1
ping -c 4 google.com
If both tests succeed, your static IP configuration is working correctly.
Creating a New Connection
Instead of modifying an existing connection, you can create a new one:
sudo nmcli connection add type ethernet con-name "static-ip" ifname enp0s3 ipv4.addresses 192.168.2.150/24 gw4 192.168.2.1 ipv4.method manual ipv4.dns "8.8.8.8 8.8.4.4" connection.autoconnect yes
This creates a new connection named “static-ip” for the interface enp0s3
with the specified static IP configuration.
Method 2: Direct Configuration File Editing
While nmcli is the recommended approach, sometimes direct editing of configuration files provides more control or is necessary for complex configurations.
Locating Configuration Files
NetworkManager stores connection profiles in the /etc/NetworkManager/system-connections/
directory. Each connection has its own file with a .nmconnection
extension.
To find your connection’s configuration file:
ls /etc/NetworkManager/system-connections/
Configuration File Structure
Open the configuration file with a text editor:
sudo nano /etc/NetworkManager/system-connections/enp1s0.nmconnection
The file should have an INI-style structure. To configure a static IP address, modify it to look similar to this:
[connection]
id=enp1s0
uuid=d5f41bf4-de0a-43b3-b633-7e2ec6212e58
type=ethernet
interface-name=enp1s0
autoconnect=yes
[ethernet]
mac-address=your-mac-address
[ipv4]
method=manual
addresses=192.168.122.66/24
gateway=192.168.122.1
dns=192.168.122.1
[ipv6]
method=auto
Key parameters to modify include:
method=manual
in the[ipv4]
section for static IP configurationaddresses=
to specify your static IP address with CIDR notationgateway=
to set your default gatewaydns=
to specify DNS servers
Applying Configuration Changes
After editing the file, save it and set the correct permissions:
sudo chmod 600 /etc/NetworkManager/system-connections/enp1s0.nmconnection
Then, reload NetworkManager to apply the changes:
sudo systemctl restart NetworkManager
Alternatively, apply changes to just the specific connection:
sudo nmcli connection up enp1s0
Verify that your changes have been applied correctly using the verification commands mentioned earlier.
Legacy Method: network-scripts
While NetworkManager is the recommended approach for CentOS Stream 10, some administrators might still prefer the legacy network-scripts method for backward compatibility.
Why This Method is Deprecated
The network-scripts method has been deprecated in RHEL 8 and later (including CentOS Stream 10) for several reasons:
- Limited flexibility compared to NetworkManager
- Lack of integration with modern Linux subsystems
- No active development or new features
Red Hat recommends migrating to NetworkManager for all new configurations.
Brief Overview of Legacy Configuration
If you need to use the legacy method, configuration files are located in /etc/sysconfig/network-scripts/
with names like ifcfg-<interface>
(e.g., ifcfg-eth0
).
Here’s an example of a static IP configuration using this method:
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
After editing the file, restart the network service:
sudo systemctl restart network
Be aware that this method might not be fully supported in future versions of CentOS Stream.
Verification and Testing
After configuring your static IP address, thorough verification and testing are essential.
Network Configuration Verification
Check the IP address assignment:
ip addr show
Verify the routing table to ensure the default gateway is set correctly:
ip route show
Check DNS resolution:
cat /etc/resolv.conf
nslookup google.com
dig google.com
These commands should return the IP addresses for google.com if DNS is configured correctly.
Connectivity Testing
Test basic connectivity to your default gateway:
ping -c 4 10.0.0.1
If this succeeds, try pinging an external IP address to verify internet connectivity:
ping -c 4 8.8.8.8
Then test DNS resolution:
ping -c 4 google.com
For more comprehensive testing, use tools like traceroute
to verify the network path:
traceroute google.com
Troubleshooting Common Issues
Even with careful configuration, network issues can arise. Here are some common problems and their solutions.
Configuration Not Applying
If your configuration changes don’t seem to take effect:
1. Check Service Status: Ensure NetworkManager is running:
sudo systemctl status NetworkManager
2. Restart NetworkManager: Try restarting the service:
sudo systemctl restart NetworkManager
3. Check Configuration File Permissions: For directly edited files, ensure they have the correct permissions:
sudo chmod 600 /etc/NetworkManager/system-connections/*.nmconnection
4. Check for Syntax Errors: Look for syntax errors in configuration files:
sudo nmcli connection reload
Network Connectivity Problems
If you can’t connect to the network after configuring a static IP:
1. IP Address Conflicts: Ensure no other device on the network is using the same IP address:
arping -D -I enp1s0 10.0.0.30
2. Incorrect Gateway or DNS Settings: Double-check your gateway and DNS settings:
nmcli connection show enp1s0 | grep 'ipv4'
3. Firewall Issues: Check if the firewall is blocking connectivity:
sudo systemctl status firewalld
sudo firewall-cmd --list-all
Advanced Troubleshooting
For more complex issues, try these advanced troubleshooting techniques:
1. Check NetworkManager Logs:
journalctl -u NetworkManager
2. Test with Temporary Configuration:
sudo ip addr add 10.0.0.100/24 dev enp1s0
sudo ip route add default via 10.0.0.1
If this works, the issue might be with NetworkManager rather than the network itself.
Best Practices and Security Considerations
Implementing best practices ensures your network configuration is robust, secure, and maintainable.
IP Address Planning
Proper IP address planning is crucial for network stability:
- Document Your IP Allocations: Maintain documentation of all static IP assignments to prevent conflicts.
- Use Reserved Ranges: Allocate static IPs outside of DHCP ranges to prevent address conflicts.
- Implement Logical Addressing Schemes: Group similar services in contiguous IP ranges for easier management.
- Plan for Growth: Reserve IP ranges for future expansion to avoid major renumbering later.
Security Best Practices
Network configuration is a critical aspect of system security:
1. Implement Firewall Rules: Configure firewalld to restrict access to only necessary services:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
2. Use Secure DNS Servers: Consider using DNS servers that provide security features like filtering or DNSSEC.
3. Monitor Network Activity: Implement monitoring solutions to detect unusual network activity.
4. Regularly Update Network Components: Keep NetworkManager and related packages updated:
sudo dnf update NetworkManager
Maintenance and Updates
Regular maintenance keeps your network configuration reliable:
1. Backup Network Configurations: Regularly back up your NetworkManager connection profiles:
sudo cp -r /etc/NetworkManager/system-connections/ /backup/network-configs/
2. Test Changes in Non-Production First: Always test significant network changes in a test environment before applying to production systems.
3. Document Changes: Maintain a changelog of network configuration modifications with dates and reasons.
Congratulations! You have successfully set up a static IP address. Thanks for using this tutorial to set a static IP address on CentOS Stream 10 Linux system. For additional help or useful information, we recommend you check the official CentOS Stream website.