CentOS 7 Network Configuration without NetworkManager

by Remy Pereira on 04th February 2018

CentOS 7 comes with Network Manager, a service that runs by default and has a graphical, text as well as command line interface. You can use Network Manager to create, edit and remove interfaces and it can be used to configure Ethernet, WiFi, Mobile, DSL and PPPoE connections. Using the GUI is pretty straight forward. To invoke the text interface just type:

# nmtui

The command line interface can be invoked by the command nmcli. For example to get a list if all NICs (Ethernet cards):

# nmcli d

However you may not want to run NetworkManager service on your server because of various reasons. Advanced configuration options are limited and it does not yet support some device types like ISDN, IPSec to name a few. If you decide to disable NetworkManager service and use just the network service, you can configure your network by editing some config files and restarting the network service.

List all network interfaces

To list and manipulate devices, routing, tunnels etc you can use the ip command.

# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 08:00:27:66:17:c2 brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 08:00:27:c3:a3:a7 brd ff:ff:ff:ff:ff:ff

Configure DHCP on an interface

Edit the config files in /etc/sysconfig/network-scripts directory. In this directory, each device should have a configuration file named ifcfg-<device-name>. If you want to configure DHCP on device enp0s3, edit the file ifcfg-enp0s3

For the device to be activated at startup time ste ONBOOT=yes

To enable DHCP, set BOOTPROTO=dhcp

Leave the other settings as such and restart networking

# systemctl restart network

Configure static IP

Edit the config file /etc/sysconfig/network-scripts/ifcfg-<devicename>. Using the example interface enp0s3 from above, the file to edit is /etc/sysconfig/network-scripts/ifcfg-enp0s3. Change ONBOOT to "yes" if you want interface to be UP on boot. Change BOOTPROTO to "static" and set a IP address and network mask as shown below.

ONBOOT=yes
BOOTPROTO=static
IPADDR=10.16.1.108
NETMASK=255.255.255.0

You could also add a Gateway address as below.

GATEWAY=10.16.1.1

The default gateway can also be added to /etc/sysconfig/network file like below:

NETWORKING=yes
GATEWAY=10.16.1.1

Remember to restart the network service

# systemctl restart network

The ip command can be used to verify the settings

# ip addr

The ip command can be also used to change IP addresses, but the change won't be permanent. For permanent changes you need to edit the config files and restart networking.


Post a comment

Comments

Nothing yet..be the first to share wisdom.