Linux Network Namespaces – Background

http://www.opencloudblog.com/?p=116

How to Create a Network Namespace and add iptables rules and Test it

http://fosshelp.blogspot.com/2014/07/create-network-namespace-iptables-rules.html

 

iptables example DNAT SNAT and MASQUERADE with network namespace

http://fosshelp.blogspot.com/2014/07/iptables-dnat-snat-masquerade-with.html

Namespaces

Managing network namespaces using the ip command is the prefered way. It is helpful to understand, what’s going on in the (kernel) background.

If you create two network namespaces using

you find to entries in the directory /var/run/netns/

Each process has an unique inode assigned. This inode makes it possible to check, if two processes belongs to a name namespace. Look in /proc/self/ns/  to the entry net:

The shell process, which we are using and the namespaces ns1 and ns2 have different net:[] inodes assigned. These inodes are the inodes of the entries in /var/run/netns/ . If this is the default network namespace you will not see an entry.

Network namespaces might also be assigned to PIDs.

Newer versions if ip have the commands ip netns identify PID (This command walks through /var/run/netns and finds all the network namespace names for network namespace of the specified process) and ip netns pids NAME (This command walks through proc and finds all of the process who have the named network namespace as their primary network namespace).

A cat /proc/self/mounts shows the total number of network namespaces in the system:

If you exectute the same command in a network namespace using ip netns exec ns1 cat /proc/self/mounts you get:

 Interfaces

If you create a veth pair and assign one side to ns1 and the other sinde to ns2 using the commands

Interfaces may also be assigned to a process:

This attaches the interface veth-f not only to PID 1234, it attaches the interface to the network namespace to which the process 1234 is belonging to. The network namespace survives, even if the process terminates.

How do you find the namespaces to which the interface are belonging to?

How do you find all interfaces in your system and the mapping to network namespaces/pids?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值