Challenge ·Easy

Create a Linux Network Namespace

Learn how to create fully isolated virtual network environment using Linux network namespaces.

Premium Challenge

Upgrade your membership to unlock this and all other premium materials.

Upgrade

Docker (and the like) gives the containerized application the illusion of running in a dedicated network environment. This is achieved by using Linux network namespaces that provide a fully isolated set of network devices, IP protocol stacks, routing tables, firewall rules, etc., for each container.

Linux network namespace visualized.

In this challenge, you'll need to create a new network namespace manually and then inspect its network interfaces.

First, create a new network namespace called my-net-ns.

Hint 1

There are multiple ways to create a network namespace. For instance, you can use the unshare command or the ip netns command. man unshare and man ip-netns are your friends.

Now, list the network interfaces of the my-net-ns namespace. How many interfaces a freshly created network namespace has? Store the output of ip link ls in the /tmp/my-net-ns-interfaces.txt file.

Hint 2

To list interfaces of a network namespace, you need to execute the ip link ls command in that namespace.

Hint 3

Again, there are multiple ways to execute a command in a network namespace. You can either nsenter it or use the ip netns exec utility. Try man nsenter or man ip-netns for more information.