Setting the IP address on CentOS¶
In this article
Centos 7¶
Network interfaces in CentOS 7 are stored and configured through the configuration file /etc/sysconfig/network-scripts/ifcfg-eno1
, where eno1
- is the name of the active network card. The names of network card available in the OS, link availability and the current address can be found out by running the command:
How to configure DHCP¶
Attention
Active DHCP services on external Ethernet interfaces are forbidden by the Terms and Conditions of services and the use of the site.
Delete the IPADDR
, NETMASK
, GATEWAY
variables, and specify the value dhcp
in BOOTPROTO
:
How to set up a static IP address¶
The example of configuring a static IP address for an interface named eno1:
```bash
NAME="eno1"
ONBOOT=yes
BOOTPROTO=static
HWADDR="ac:1f:6b:f6:3b:7e"
IPADDR="82.148.21.50"
NETMASK="255.255.255.0"
GATEWAY="82.148.21.1"
TYPE=Ethernet
```
Applying a configuration¶
After changing the configuration file, you need to reload the interface:
Attention
After the reload, the changes will come into force. If you do not reload the network, then the changes will be applied only after the server is restarted.
You can check the network settings using the command:
NetworkManager¶
Information
An alternative method for configuring IP is the NetworkManager utility.
Adding an Interface¶
sudo nmcli con add con-name "static-ens224" ifname ens224 type ethernet ip4 192.168.1.76/24 gw4 192.168.1.1
Set up DHCP on the interface:¶
Attention
Active DHCP services on external Ethernet interfaces are forbidden by the Terms and Conditions of services and the use of the site.
Set up a static IP address:¶
After adding routes, you must restart the NetworkManager service.
Centos 8¶
NetworkManager¶
Note
By default, NetworkManager is the recommended way to set up a network in CentOS 8. All other methods are outdated.
Adding an Interface¶
$ sudo nmcli con add con-name "static-ens224" ifname ens224 type ethernet ip4 192.168.1.76/24 gw4 192.168.1.1
Set up DHCP on the interface¶
Attention
Active DHCP services on external Ethernet interfaces are forbidden by the Terms and Conditions of services and the use of the site.
Set up a static IP address:¶
nmcli con add con-name eth2 type ethernet ifname eth2 ipv4.method manual ipv4.address 192.168.0.15/24 ipv4.gateway 192.168.0.1
After adding routes, you must restart the NetworkManager service.
Note
Network interfaces in CentOS 8 are also stored and configured through the configuration file /etc/sysconfig/network-scripts/ifcfg-eno1
.
How to configure DHCP¶
Attention
Active DHCP services on external Ethernet interfaces are forbidden by the Terms and Conditions of services and the use of the site.
Delete the IPADDR
, NETMASK
, GATEWAY
variables, and specify the value dhcp
in BOOTPROTO
:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="enp1s0"
UUID="d5f41bf4-de0a-43b3-b633-7e2ec6212e58"
DEVICE="enp1s0"
ONBOOT="yes"
How to set up a static IP address¶
The example of configuring a static IP address:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="enp1s0"
UUID="d5f41bf4-de0a-43b3-b633-7e2ec6212e58"
DEVICE="enp1s0"
ONBOOT="yes"
IPADDR=192.168.122.66
PREFIX=24
GATEWAY=192.168.122.1
DNS1=192.168.122.1
Applying a configuration¶
After changing the configuration file, you need to reload the interface:
Attention
After the reload, the changes will come into force. If you do not reload the network, then the changes will be applied only after the server is restarted.
You can check the network settings using the command:
CentOS 9-10 Stream¶
When configuring your network, it's crucial to understand the difference between an active network interface and a connection profile in NetworkManager:
-
Active Network Interface (visible through the
ip addr show
command) - this is the current working connection, which can be automatically configured via DHCP during system startup. -
NetworkManager Connection Profile (managed through
nmcli connection
) - this is a persistent configuration that is saved in the system and applied on each boot.
Attention
An interface can be active and functioning even without a profile in NetworkManager. This can lead to confusion when nmcli connection modify
commands don't work due to the absence of a profile, although the interface is displayed and operational in the system.
Before making any configurations, always doing initial check:
-
Check active interfaces:
-
Check existing NetworkManager profiles:
-
Check device status:
If a profile is missing, you need to create it before proceeding with further configuration:
1. SSH Connection
Basic connection
2. Initial Network Diagnostics
-
View network interfaces
-
Check current connections
3. Location of Configuration Files
Main directories:
- Connection files:
/etc/NetworkManager/system-connections/
- Additional configurations:
/etc/NetworkManager/conf.d/
- Main config:
/etc/NetworkManager/NetworkManager.conf
How to Configure a Static IP Address¶
Creating a new connection
```bash
nmcli connection add type ethernet con-name "static-eth0" \
ifname eth0 \
ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8"
```
Modify an existing one
```bash
nmcli connection modify "System eth0" \
ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8"
```
Editing Configuration Files:
-
Find the necessary config
-
Open the file for editing
-
Set correct access permissions
Example content of the file for a static IP:
[connection]
id=static-eth0
type=ethernet
interface-name=eth0
[ipv4]
method=manual
addresses=192.168.1.100/24
gateway=192.168.1.1
dns=8.8.8.8
How to Configure the Interface for DHCP¶
Attention
Having an active DHCP server responding in your company's network is prohibited by the Terms and Conditions of Service and Website Use.
Applying Configuration Changes¶
After modifying the configuration file, you need to reload the interface by following these steps:
-
Reload Configuration:
-
Restart Connection:
You can verify network settings using the following commands:
-
Check Connection Status:
-
Check IP Address: