This article shows 2 methods to enable a network interface and configure static IP address on CentOS 7 which are as following:
Watch on YouTube
Step-by-step
Configure IP address in GUI mode
- Login to the server.
- Type this command to see network interfaces on this server.
nmcli d
And type this command to open Network Manager.
nmtui
- On NetworkManager TUI, select Edit a connection.
- Select a network interface that you want to configure. In this example, the network device name is ens33.
- On this window, you can configure static IP address for this network interface:
- Change IP v4 configuration to Manual and click Show button on the right
- Enter IP address with network mask, for instance, 192.168.0.201/24
- Enter gateway address
- Enter DNS servers
- Check Require IPv4 addressing for this connection option
- Check Automatically connect option
- Click OK and click Back
Note: If you want to configure this network interface as DHCP, only check Automatically connect option and click OK.
- You can also modify hostname by select Set system hostname.
- Type new hostname and click OK.
- Select Quit to exit Network Manager.
- Restart network service by type this command. The network interface will be enabled and configured with static IP address.
systemctl restart network
Configure IP address using command line
- Login to the server and type this command to see network interfaces.
nmcli d
In this example, I have single network interface which name is ens33 and currently disabled.
- To configure the network interface, type this command to edit config file.
vi /etc/sysconfig/network-scripts/ifcfg-ens33
Note: You have to change ens33 to match your device name that you want to configure.
- On the editor, change ONBOOT to yes.
Note: To enter edit mode in vi editor, press Insert.
- Change BOOTPROTO to static and insert IP address, gateway, and DNS servers for this network interface.
- Exit edit mode by press Esc and type :wq to save file and exit the editor.
- Restart network service by type this command. The network interface will be enabled and configured with static IP address.
systemctl restart network