Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Configure Static ipADD

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

How to configure static IP address

on AlmaLinux
17 February 2021 by Korbin Brown
When it comes to IP addresses on AlmaLinux, you have two main options for how
you configure your network interfaces. You can either obtain an IP address
automatically with DHCP, or configure the system to use a static IP address, which
never changes.

In this guide, we’ll show how to configure a static IP address on AlmaLinux. This can
be done either through GUI or command line, and we’ll be going over both methods.
Once a static IP address is configured, it won’t change again unless you
manually change the IP address later, or turn DHCP on. You can follow this guide
whether you’ve migrated from CentOS to AlmaLinux or have performed a
normal AlmaLinux installation.

DID YOU KNOW?


You can also configure your DHCP server (or router) to assign your AlmaLinux
system a static IP address. This means that your system would still use DHCP,
but the server or router will reserve the same IP for the MAC address of your
computer’s network interface. Instructions for this will vary, depending on your
network environment and DHCP server.
In this tutorial you will learn:

 How to configure a static IP address via GNOME GUI


 How to set a static IP address by directly editing an interface file
 How to set a static IP address using the nmcli utility
 How to set a static IP address using nmtui
Configuring a static IP address on 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.

# – requires given linux commands to be executed with root privileges either directly as a root us
Conventions of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Configure static IP address via GUI

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

1. First, click on the top right taskbar area of the GNOME desktop to open the network
settings menu.
Open network settings from top right corner of GNOME desktop
2. Next, open the settings for the network interface you wish to configure.
Open the network settings of the interface that you want to configure
3. 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.
Fill out the desired network information for the interface
Configure static IP address via command line
There are several methods we can use to configure a static IP address on AlmaLinux
via command line. Which one you choose will mostly boil down to personal
preference. Follow along with the step by step instructions for any of the methods
below.

Identifying our network interface


The first thing we want to do is find the interface that we want to modify. To list all
the interfaces on our system, we can use the ip a command:

$ 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

On our test machine, the interface we’re interested in working with is ens160. Take
note of your interface name, as you’ll need to know it when following along with the
steps below.

Method 1 – modifying interface configuration file manually


For each network interface managed by the NetworkManager daemon, a configuration
file is created inside the /etc/sysconfig/network-scripts directory. The name of
the file is composed by the ifcfg- prefix plus the name of the interface. If we inspect
the file related to our NIC, we can see its actual setup:
# vi /etc/sysconfig/network-scripts/ifcfg-ens160
Our network interface boot protocol is currently configured for DHCP
In the screenshot above, you can see that the BOOTPROTO option is set to DHCP. This
option sets the protocol to use at boot to set the IP address of the interface. The
possible options to use are:

 none – No protocol should be used


 bootp – Use the bootp protocol
 dhcp – Use the dhcp protocol
Since we want to set a static IPv4 address, we want to change the value
of BOOTPROTO to none, and configure our IP, route prefix (a.k.a. subnet mask),
gateway and DNS server statically. We can do that by editing the file with the
following lines.

BOOTPROTO="none"

IPADDR=192.168.122.66

PREFIX=24

GATEWAY=192.168.122.1

DNS1=192.168.122.1
Fill out your desired network settings in the interface file
In this example, we’ve set our static IP to 192.168.122.66 and set both our gateway
and DNS server to 192.168.122.1. Now, to make our changes to take effect,
we’ll restart the network.
# nmcli connection down ens160 && nmcli connection up ens160

Method 2 – using nmcli


Nmcli is a command line tool used to control NetworkManager. We can use it to
change network settings for a specific interface. In the following commands, we use
the nmcli utility to set an IP address, subnet mask, default gateway, and DNS server
on our ens160 interface.

# nmcli connection modify ens160 IPv4.address 192.168.122.66/24

# nmcli connection modify ens160 IPv4.gateway 192.168.122.1

# nmcli connection modify ens160 IPv4.dns 192.168.122.1

Finally, we set the method to manual to avoid using any other boot protocol for the
interface. This command sets the BOOTPROTO option to none in the interface
configuration file.

# nmcli connection modify ens160 IPv4.method manual

Method 3 – using nmtui


Other than changing the parameters of a network interface by modifying its file
manually or by using the nmcli utility, we can also control NetworkManager by using
a text user interface. To launch it we just invoke nmtui in our terminal.

# nmtui
Choose to edit a connection
Select “Edit a connection” and then the name of the interface you want to configure.
Then, you can proceed in changing the desired values. For example:
Fill out the desired network information for the interface
Once you’re done with the configuration, select “OK” and press enter. You will be
taken back to the interface selection menu. Now you can select “back”, and then
choose “quit” to exit. To apply the settings, we need to reload the interface
connection.

# nmcli connection down ens160 && nmcli connection up ens160

Closing Thoughts
In this guide, we saw several methods for configuring a static IP address on
AlmaLinux. This involved GNOME GUI, editing interface configuration files
manually, using nmcli, and using nmtui. As you can see, AlmaLinux gives us no
shortage of options for configuring static IPs. All methods are equally effective, and
the one you use should depend on your situation and preference – whether it’s for
GUI, text files, commands, or an ncurses interface.

You might also like