Configure static IP address on CentOS 7

CentOS 7 network interfaces are disabled by default. If you want to use networking, you have to enable it.

This article shows 2 methods to enable a network interface and configure static IP address on CentOS 7 which are as following:

  1. Configure IP address in GUI mode
  2. Configure IP address using command line

Watch on YouTube

Step-by-step

Configure IP address in GUI mode

  1. Login to the server.
    Login to CentOS 7 server
  2. Type this command to see network interfaces on this server.
    nmcli d

    And type this command to open Network Manager.

    nmtui

    Open Network Manager

  3. On NetworkManager TUI, select Edit a connection.
    Edit a connection
  4. Select a network interface that you want to configure. In this example, the network device name is ens33.
    Select a network interface
  5. On this window, you can configure static IP address for this network interface:
    1. Change IP v4 configuration to Manual and click Show button on the right
    2. Enter IP address with network mask, for instance, 192.168.0.201/24
    3. Enter gateway address
    4. Enter DNS servers
    5. Check Require IPv4 addressing for this connection option
    6. Check Automatically connect option
    7. Click OK and click Back

    Note: If you want to configure this network interface as DHCP, only check Automatically connect option and click OK.
    Configure network interface

  6. You can also modify hostname by select Set system hostname.
    Configure hostname on CentOS 7
  7. Type new hostname and click OK.
    Enter new hostname for this server
  8. Select Quit to exit Network Manager.
    Exit Network Manager
  9. Restart network service by type this command. The network interface will be enabled and configured with static IP address.
    systemctl restart network

    Restart network service

Configure IP address using command line

  1. 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.
    List network interfaces on CentOS 7

  2. 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.
    Configure network interface

  3. On the editor, change ONBOOT to yes.
    Note: To enter edit mode in vi editor, press Insert.
    Enable network interface
  4. Change BOOTPROTO to static and insert IP address, gateway, and DNS servers for this network interface.
    Configure static IP address on CentOS 7
  5. Exit edit mode by press Esc and type :wq to save file and exit the editor.
    Save changes on vi editor
  6. Restart network service by type this command. The network interface will be enabled and configured with static IP address.
    systemctl restart network

    Restart network service

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.