Setting the IP address on CentOS 7,8¶
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: