Fedora

How to configure a static IP address on Fedora?

IP address configuration is one of the normal tasks system administrators do on a System.
IP address is used for identifying a device on a network. There are basically two types of IP addresses: 1) Public 2) Private. We can further divide these IP addresses into IPv4 and IPv6.

By default, Fedora uses DHCP-provided IP addresses when it is connected to a DHCP server. We can use the below methods to use static IP addressing and other networking options like vlans, bonds, bridges, teams, etc.

What will we cover?

In this guide, we will see two methods for setting a static IP on Fedora 33 workstation. Although this guide is performed on Fedora 33, it should also work on other Fedora versions. Let’s get started with this process.

Before you start

Please note that we have assumed that you have

  1. a basic understanding of IPv4 addressing and other computer networks basics
  2. knowledge of Linux command-line interface
  3. root access on the system or a user with root privileges.
  4. Fedora 33 OS installed on your system

Method 1. Using nmcli command-line utility for setting a static IP address on Fedora 33

Nmcli or NetworkManager Command Line Interface is a command-line utility for managing network connections. Users and scripts both use the nmcli utility to control NetworkManager. For e.g., you can edit, add, remove, activate or deactivate network connections. We can also use it to display the status of a network device.

The syntax of a nmcli command is as follows:

nmcli [OPTIONS] OBJECT { COMMAND | help }

Step 1. To check the overall status of NetworkManager, use the command:

$ nmcli general status

You can also use the below command to see a terse output about the connection state:

$ nmcli -t -f STATE general

As you can see, it is showing a connected state for now. If you turn off the wired connection, it will change to a disconnected state. This is shown in below picture:

Step 2. Now, after connecting to a network, we can see the active connections on our system using:

$ nmcli con show -a

You can also use the command below to see active and inactive interfaces:

$ nmcli dev status

As you can see, right now, only one connection is active on device enp0s3. To see the current network configuration for enp0s3, use the command:

$ ifconfig enp0s3

You can also use the ip command:

$ ip addr | grep enp0s3

Please note that our current IP is 10.0.2.15; we need to set it to 10.0.2.27.

Step 3. To change the IP of enps03 to a static IP, use the following command format:

$ sudo nmcli connection modify network_uuid IPv4.address new_static_IP/24

Where network_uuid is as obtained in Step 2. ‘new_static_IP’ is the new IP we want to assign statically. If our new IP address is 10.0.2.27, then the command will be:

$ sudo nmcli connection modify f02789f7-9d84-3870-ac06-8e4edbd1ecd9 IPv4.address 10.0.2.27/24

If you are feeling uncomfortable with the network UUID, you can also the connection name (Wired connection 1) as shown below:

$ sudo nmcli connection modify 'Wired connection 1' IPv4.address 10.0.2.27/24

NOTE: To avoid IP conflict, do not use an already assigned IP.

Step 4. Now configure the default gateway for our IP with the command:

$ sudo nmcli connection modify 'Wired connection 1' IPv4.gateway 10.0.2.11

Step 5. Now Set network DNS address using:

$ sudo nmcli connection modify 'Wired connection 1' IPv4.dns 8.8.8.8

Step 6. Now we need to change the IP addressing scheme from DHCP to static:

$ sudo nmcli connection modify 'Wired connection 1' IPv4.method manual

Step 7. Now turn off and then turn on the connection to apply changes:

$ sudo nmcli connection down 'Wired connection 1.'
$ sudo nmcli connection up 'Wired connection 1.'

All the above steps are shown in the below picture:

Now again, check the Gateway and IP with the command:

$ route -n
$ ip addr | grep enp0s3

You can see the Gateway and IP addresses are both changed to the values we have set in the above steps.

Method 2. Using a graphical method for setting a static IP address on Fedora 33

This is a very straightforward way to set a static IP address on Fedora 33 OS; follow the steps below:

Step 1. On the Gnome desktop, go to the activities tab and search for Settings and launch it:

Step 2. In the left panel, you will see the network tab. Inside the network tab, click on the Settings icon as shown below:

Step 3. A new window will open, displaying the already configured IP addresses, Gateway, DNS as shown below:

Step 4. In the above window, select the IPv4 option from the top bar:

Step 5. Inside the IPv4 method segment, select the radio button corresponding to the manual option:

Step 6. When you select the manual method, it will open some text boxes for filling the IP addresses, DNS, Routes, and other information related to network configuration, as shown in the above image. We are adding the following details:

IP addresses: 10.0.1.27
Netmask: 255.255.255.0
Gateway: 10.0.1.0
DNS: 8.8.8.8

We are leaving the Route segment row to be set automatically. See the reference picture below:

Step 7. Now we only need to stop and then restart the network connection using the connection switch in the main Network Tab as shown below:

  1. Switch Off
  2. Switch On

Step 8. Now we will verify if the new IP address, DNS, and Gateway are assigned properly. Go to the main Network Tab and click the settings icon as depicted in the picture below:

Step 9. I noticed that IP address, Gateway, and DNS are all changed to the new values that we have selected in the above steps:

Conclusion

That’s all for now; we have successfully set a static IP address on Fedora 33 workstation. We have seen both the command line and graphical methods. The CLI method is the only way to set the static IP address on non-gui or headless servers. The graphical method is more convenient for desktop users and novice Linux users.

About the author

Ali Imran Nagori

Ali Imran Nagori

Ali imran is a technical writer and Linux enthusiast who loves to write about Linux system administration and related technologies. You can connect with him on LinkedIn
.