Creating a new network namespace on Linux

2

1

I'd like to create a new network namespace on Linux.

http://www.spinics.net/lists/linux-containers/msg10895.html tells me that I can attach a shell to an existing namespace with ID X by running:

$ chnetns X /bin/sh

This works fine if the namespace already exists, but if I try with a non-existent namespace, I get the following:

$ chnetns 100 /bin/sh
setsocketopt: Invalid argument

How can I create the namespace? I'm on Red Hat Linux, V6.1.

thomson_matt

Posted 2012-05-25T09:18:42.013

Reputation: 121

Quite an old question but I had need of an introduction to linux network namespaces / virtual networking myself. – gaoithe – 2014-09-26T11:36:00.030

Answers

2

The answer is 'ip netns add vnet1'.

ip netns list
ip netns add vnet1

See also introduction to linux virtual networking: blog.scottlowe.org: Linux networking namespaces intro, opencloudblog.com: Linux networking namespaces shiny and more beautiful and opencloudblog.com: Linux networking namespaces shiny and even more detailed with beautiful diagrams

Links to other references to help others get started with virtual networking namespaces. See also also LWN article on network namespaces, Open Stack Networking example, iproute2, linux vrf patchset Virtual Routing and Forwarding for Linux, and OpenStack networking concepts.

man ip netns

NAME
   ip-netns - process network namespace management

SYNOPSIS
   ip [ OPTIONS ] netns  { COMMAND | help }

   ip netns { list }

   ip netns { add | delete } NETNSNAME

   ip netns identify PID

   ip netns pids NETNSNAME

   ip netns exec NETNSNAME command ...

   ip netns monitor

gaoithe

Posted 2012-05-25T09:18:42.013

Reputation: 423