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
|Category||Requirements, Conventions or Software Version Used|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – 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.
- First, click on the top right taskbar area of the GNOME desktop to open the network settings menu.
- Next, open the settings for the network interface you wish to configure.
- 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.
Change IP address via command line
Follow along with the commands below to change your IP address on AlmaLinux.
- 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
- In our example,
ens160will be the network interface for which we will change the IP address. Thus, edit the following file.
# nano /etc/sysconfig/network-scripts/ifcfg-ens160
- In this file, we need to make a few changes. First, make sure that
BOOTPROTOis set to none.
And then add the following lines to the end of the file or right after the
BOOTPROTOline. 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
- Nameservers are located in the
/etc/resolv.conffile, so we will edit that too if needed.
# nano /etc/resolv.conf
- Change the
nameserverline to something like
18.104.22.168, which is one of Google’s DNS servers. Save your changes and exit this file afterwards.
- Lastly, we need to restart the network in order for the new changes to take effect.
# nmcli networking off # nmcli networking on
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.