Adding an IP Address and a Static Route

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

Managing network settings is a crucial ability for a System Administrator to have. In today’s environment, adding and deleting IP addresses and static routes is an expected capability. In this activity, we will be creating one script to add an IP address and a static route, then another script to remove an IP address and a static route.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Use the sudo Command to Start a Root Account Shell

Using sudo -i, start an interactive root shell:

sudo -i
Add and Delete the IP Address from the eth0 Interface, and Create and Scripts

Using the ip a command, add and delete the address from the ens5 interface. Use these commands to create the and scripts:

ip a
ip a add dev ens5
ip a
echo ip a add dev ens5 >
chmod +x
ip a del dev ens5
ip a
echo ip a del dev ens5 >
chmod +x
ip a 
ip a
Update and Scripts to Add and Delete Route Using as a Router to Provide Access to the Network

Using the ip r command add a route to the subnet using as a router with the ens5 device. Add this command to the script file. Delete the new route using the ip r command, and add it to the script.

ip r
ip r add via dev ens5
ip r
echo ip r add via dev ens5 >>
ip r del via dev ens5
echo ip r del via dev ens5 >>
ip r
Verify the Script Adds the Correct Address and Route, and Script Deletes the Address and Route

Execute the script. Check the current IP address information and it should not contain If it does, try fixing until it does not:

ip a | grep

Check the routing table and it should not have the router If it does, try fixing the until it does not:

ip r | grep

Execute the script:


Check the current IP address information, and it and should contain If it does not, try fixing until it does:

ip a | grep

Check the routing table and it should have the router If it does not, try fixing the until it does:

ip r | grep

Double-check our work by repeating the previous steps in this task.

Additional Resources

The lead System Administrator has asked us to create a couple of scripts to be used by a developer which will modify the network interface. They need the IP address assigned to the host, and a static route to provide access to another host which will be provisioned on a different subnet with the specification of Our system already has an address of assigned to the ens5 interface.

We have been asked to create the /root/ script, which will add the address to the ens5 interface, and the /root/ script which will delete the same address from the same interface, using ip a commands.

We have also been asked to have the /root/ script add a route so the host will be used as a router to provide access to the host on the subnet, using the ens5 interface and utilizing the ip r command. The /root/ script should delete the same route from the interface using the ip r command. Unfortunately, the host has not yet been provisioned, so we will have to rely on the routing table output, and will not be able to verify connectivity with this host.

Once we believe our and scripts have been created and updated, we'll have to verify and double-check that they work correctly.

NOTE: eth0 has been replaced with ens5 in the lab environment.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?