How to Add Static Route in Linux | Ubuntu & RHEL | ip route add Command Explained
52 views
Jun 10, 2025
In this quick and practical Linux tutorial, you will learn how to add static route in Linux — both temporarily and permanently — using the ip route add command. We will walk through examples on Ubuntu 24.04 Server and Red Hat Enterprise Linux 9 (RHEL 9). ✅ In This Video You’ll Learn: 📌 What is a Static Route? 📌 When and why you need static routing in Linux 📌 How to use ip route add to set a temporary route 📌 How to make routes permanent with: 🟢 Netplan on Ubuntu 🔴 nmcli on RHEL / Rocky Linux 🖥️ Example Command: sudo ip route add 192.168.50.0/24 via 192.168.1.1 dev enp0s3 📂 For Permanent Static Routes: Ubuntu/Debian → Edit /etc/netplan/*.yaml
View Video Transcript
0:00
hi everyone welcome back to the channel
0:02
in this video I will show you how to add
0:05
a static route in Linux step by step i
0:08
will use Ubuntu and RHS system for the
0:10
demonstration static routes are
0:12
essential when your Linux server needs
0:14
to reach specific networks through a
0:16
particular gateway whether you are
0:19
working on a cloud VM or on premises
0:22
server this guide will help you set up
0:25
static routes permanently and
0:26
temporarily well what is a static route
0:30
a static route tells your Linux system
0:32
exactly where to send network packets
0:35
when they are destined to a specific IP
0:38
or network unlike dynamic routing these
0:42
routes do not change unless you modify
0:44
them manually it's useful in multi-
0:47
network environments especially when the
0:49
default routing is not enough let's say
0:52
you want to reach a
0:54
network 192.168
0:59
50.0/24 via the gateway
1:04
192.168.1.1 so for that we can add a
1:07
static route using the IP command all
1:10
right let's jump into the our Ubuntu
1:13
system first let's verify the network
1:16
details then the command IP add show so
1:21
this is my network interface which is
1:24
currently attached to my Ubuntu system
1:27
and this is the IP address assigned to
1:30
this
1:31
interface if I run IP route
1:35
show this will show me the default
1:38
gateway for this interface all right now
1:42
set the static route using the IP
1:45
command for that run the command sudo
1:51
ip route
1:54
at destin
2:03
network via gateway
2:10
IP dev and then followed by the
2:13
interface name it's
2:16
ENS160 hit
2:20
enter let's break down this command this
2:24
IP route add adds a
2:27
route this is my destin network or the
2:32
network this is my gateway IP address
2:36
and dev
2:41
ensc so for this
2:44
network the next hope is this gateway IP
2:49
address now let's verify the static
2:52
route has been added or not again run
2:55
the command ip route
2:59
show you should see an additional entry
3:02
for our
3:04
route this confirms that our static
3:07
route has been added successfully but
3:09
the static routes added with the IP
3:12
command are temporary to make them
3:15
permanent we need to edit the
3:17
configuration
3:19
file I mean the network configuration
3:21
file on Debian based systems like Ubuntu
3:25
we have a net plan utility which
3:27
controls the network configuration go to
3:29
the folder
3:31
etc net plan
3:35
there you will see a network
3:37
configuration file with the extension yl
3:39
so this name could vary as per your
3:42
setup so let's edit this file using the
3:45
vi
3:48
editor under the route
3:53
section add these entries
4:02
so this choose specify the destined
4:05
network or the IP address and via is
4:08
your gateway IP address so this means
4:11
request towards this network will go via
4:16
this gateway or we can say for this
4:21
network this is the next hope let's save
4:24
and close the
4:27
file and implement these changes using
4:31
the command net
4:33
plan
4:37
apply now rerun the command
4:40
ip
4:42
route show then the static route is now
4:47
persistent across the reboot next move
4:50
to the RHL system
4:52
let's do the same let's first set the
4:55
temporary
4:56
route but before that get the IP details
5:00
first and the command IP add
5:06
show this is the IP
5:08
address this is the interface name and
5:11
if you run IP
5:14
route show so this is the default
5:17
gateway
5:20
in order to set the temporary route on
5:23
RHS system we can use the command ip
5:25
route sudo space ip
5:29
route
5:31
add we want to set the route for this
5:36
network 192.168.0/24
5:43
0/24 via gateway
5:50
192.168.1 and the interface name is
5:55
ENS160 hit
5:59
enter all right again this IP route
6:02
command is used to add the route this is
6:05
my destined network for this network
6:09
this is the next hope or this would be
6:11
the gateway IP for this network and we
6:15
are using the interface ENS
6:17
160 let's verify whether it is
6:21
implemented or not again run the command
6:25
ip route
6:26
show output confirms that the static
6:30
route has been added for this destined
6:33
network but this static route is not
6:35
persistent across the reboot when the
6:37
system get rebooted this static route
6:39
will be removed in order to set the
6:42
static routes permanently we need to
6:45
modify the connection or create a new
6:46
connection using the nmli command let's
6:50
try to add this static route permanently
6:53
run the command sudo
6:56
[Music]
6:59
nmi connection show let's first get the
7:02
connection name so as of now there is
7:04
one
7:05
connection with the name ENS 160 for
7:09
this connection this is the device name
7:11
or the interface name all right now edit
7:14
this
7:15
connection run the command
7:17
sudo
7:19
nmi
7:21
connection modify connection name is ENS
7:26
160 and then plus
7:30
ipv4
7:32
dot
7:35
routes in double
7:37
quotes first specify the destined
7:40
network
7:43
192.168
7:45
6
7:49
0/24 followed by the next hope IP or the
7:52
gateway IP
7:55
192.168
7:58
1.1 hit enter
8:02
in order to make these changes into the
8:04
effect we need to make this connection
8:08
up run the command sudo
8:12
nmi connection up
8:18
ens the output confirms that this
8:21
connection has been activated
8:23
successfully let's verify the changes we
8:26
run the command ip route show
8:31
that's it you have now learned how to
8:34
add both temporary and permanent static
8:37
routes in Linux whether you are using
8:39
Ubuntu RHL Roki Linux or any other
8:41
distribution this method will help you
8:43
control traffic flow on your network if
8:46
you found this video helpful give it a
8:48
thumbs up subscribe to Linux Tech hit
8:50
the bell icon for more Linux tutorials
8:52
every week drop your questions in the
8:55
comments i respond to everyone see you
8:58
in the next video byite
#Networking
#Software