How to Set the Default Gateway on Fedora Linux

A default gateway is like a traffic security system for your internet connection. It is a gateway to the vast expanse of interconnected networks, notably the internet, as the bridge between your local network and the global web.

When your device within the local network seeks to communicate with external destinations, all data traffic passes through this gateway. Hence, setting up the default gateway for your system ensures that your computer can communicate to the internet and other devices properly. In this guide, we will briefly explain the methods to set the default gateway on Fedora Linux.

How to Setup the Default Gateway on Fedora Linux

You can follow two different commands that you can use to setup the default gateway without getting any error.

The Ip Command

Run the following command to check your current network configuration:

ip address

Let’s use the network interface “lo” with the specified gateway IP. Now, set the default gateway by running the following command:

sudo ip route add default via GATEWAY_IP dev INTERFACE_NAME

For example, the network interface is “lo” and the gateway IP is “

sudo ip route add default via dev eth0

Finally, verify the new default gateway configuration by executing the following command:

ip route show

The Nmcli Command

First, list your network connections to identify the name of the network interface for the configuration.

nmcli connection show

Now, check the name of the connection and run the following command to set the default gateway on it:

sudo nmcli connection modify CONNECTION_NAME ipv4.gateway GATEWAY_IP

Replace CONNECTION_NAME with the name of your network connection and GATEWAY_IP with the IP address of your desired gateway.

Once you are done, finalize the changes by running the following command:

sudo nmcli connection up CONNECTION_NAME

Verify that the default gateway has been set correctly using the following command:

nmcli connection show CONNECTION_NAME | grep ipv4.gateway


Configuring a default gateway on your Fedora Linux system is fundamental in ensuring that your network connectivity functions smoothly. You can set the default gateway on Fedora Linux through the given commands. Moreover, we recommend using the methods correctly. Otherwise, you may make your system vulnerable to third-party attacks.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.