How to change IP Address on AlmaLinux

These days, most systems are configured to connect to a network automatically through DHCP by obtaining an IP address assigned through your ISP or your home router. But there may come a time when you wish to opt for a static IP address and you will want to change it. It may be that you are configuring a home LAN and you don’t want to use DHCP or simply want a static IP address that you can access from outside your home.

In this tutorial, we will learn how we can change the IP address on an AlmaLinux system. You can follow this guide whether you’ve migrated from CentOS to AlmaLinux or have performed a normal AlmaLinux installation.

In this tutorial you will learn:

  • How to change the IP address in AlmaLinux using GNOME GUI
  • How to change the IP address by editing configuration files
  • How to manually change your DNS server
  • How to restart networking in AlmaLinux
Change IP address in AlmaLinux

Change IP address in AlmaLinux

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System AlmaLinux
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Change IP address via GUI



If you’re running the default GNOME GUI on AlmaLinux, you can follow the steps below to change your IP address.

  1. First, click on the top right taskbar area of the GNOME desktop to open the network settings menu.
  2. Open the settings menu of GNOME

    Open the settings menu of GNOME

  3. Next, open the settings for the network interface you wish to configure.
  4. Open the settings for the interface you wish to configure

    Open the settings for the interface you wish to configure



  5. Click on the IPv4 or IPv6 tab, depending on which type of IP you want to configure. Then, select “manual” and fill in your desired IP address, subnet mask, and default gateway. Optionally, you can also fill in a DNS server. Click “apply” when you’re done.
  6. Configure the network interface with an IP address, subnet mask, and default gateway

    Configure the network interface with an IP address, subnet mask, and default gateway

Change IP address via command line

Follow along with the commands below to change your IP address on AlmaLinux.

  1. Start by checking your current IP address and the name of the network interface you wish to configure.
    $ ip a
    ...
    2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
        link/ether 00:0c:29:14:b7:83 brd ff:ff:ff:ff:ff:ff
        inet 192.168.137.132/24 brd 192.168.137.255 scope global dynamic ens160
           valid_lft 1299sec preferred_lft 1299sec
        inet6 fe80::20c:29ff:fe14:b783/64 scope link noprefixroute 
           valid_lft forever preferred_lft forever
    


  2. In our example, ens160 will be the network interface for which we will change the IP address. Thus, edit the following file.
    # nano /etc/sysconfig/network-scripts/ifcfg-ens160
    
  3. In this file, we need to make a few changes. First, make sure that BOOTPROTO is set to none.
    BOOTPROTO=none
    

    And then add the following lines to the end of the file or right after the BOOTPROTO line. Edit the values to your own liking, as this is just an example. Exit the file and save your changes when done.

    IPADDR=192.168.1.5
    NETMASK=255.255.255.0
    GATEWAY=192.168.1.1
    
  4. Fill in the network settings for this interface

    Fill in the network settings for this interface



  5. Nameservers are located in the /etc/resolv.conf file, so we will edit that too if needed.
    # nano /etc/resolv.conf
    
  6. Change the nameserver line to something like 8.8.8.8, which is one of Google’s DNS servers. Save your changes and exit this file afterwards.
    nameserver 8.8.8.8
    
  7. Lastly, we need to restart the network in order for the new changes to take effect.
    # nmcli networking off
    # nmcli networking on
    

Closing Thoughts

In this guide, we saw how to change the IP address of a network interface on AlmaLinux. We learned a GUI and command line method, so you can apply the steps to both a server or desktop system. If you want to use a static address instead of DHCP you can use the above guide to manually configure each of your network cards.