Blog

Network Name space howto.

Prepared by Team ElectroMech Corporation

Nilesh Vaghela

Let us check whether any network name space exist or not.

[root@emc ~]# ip netns list

Adding emc1 network name space

[root@emc ~]# ip netns add emc1

Checking for added network name space

[root@emc ~]# ip netns list

emc1

Adding v-eth pair

Interface v-eth1 will remain inside the root network namespace, while its peer, v-peer1, will be moved to the emc1 namespace.

[root@emc ~]# ip link add v-eth1 type veth peer name v-peer1

Let us check added link

[root@emc ~]# ip l

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: enp5s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000

link/ether e8:9a:8f:fe:02:e8 brd ff:ff:ff:ff:ff:ff

3: wlp6s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT qlen 1000

link/ether 74:de:2b:b1:1a:d0 brd ff:ff:ff:ff:ff:ff

4: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT

link/ether 8e:a4:dc:29:42:3c brd ff:ff:ff:ff:ff:ff

5: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT

link/ether 52:54:00:d4:4b:7d brd ff:ff:ff:ff:ff:ff

6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN mode DEFAULT qlen 500

link/ether 52:54:00:d4:4b:7d brd ff:ff:ff:ff:ff:ff

7: v-peer1@v-eth1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000

link/ether 9a:81:02:7d:61:e2 brd ff:ff:ff:ff:ff:ff

8: v-eth1@v-peer1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000

link/ether 1e:cf:ff:eb:81:c7 brd ff:ff:ff:ff:ff:ff

Attached v-peer1 to emc1 netspace

[root@emc ~]# ip link set v-peer1 netns emc1

Assign ip address to v-eth1 link

[root@emc ~]# ip addr add 10.200.1.1/24 dev v-eth1

Let us up v-eth1

[root@emc ~]# ip link set v-eth1 up

Add ip address in network name space emc1

[root@emc ~]# ip netns exec emc1 ip addr add 10.200.1.2/24 dev v-peer1

Let us up v-peer1 up

[root@emc ~]# ip netns exec emc1 ip link set v-peer1 up

Loop back interface up

[root@emc ~]# ip netns exec emc1 ip link set lo up

Checking ip address assignment in emc1 network Name space

[root@emc ~]# ip netns exec emc1 ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

valid_lft forever preferred_lft forever

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

7: v-peer1@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether 9a:81:02:7d:61:e2 brd ff:ff:ff:ff:ff:ff link-netnsid 0

inet 10.200.1.2/24 scope global v-peer1

valid_lft forever preferred_lft forever

inet6 fe80::9881:2ff:fe7d:61e2/64 scope link

valid_lft forever preferred_lft forever

[root@emc ~]#

Adding route to 10.200.1.1 to root name space

[root@emc ~]# ip netns exec emc1 ip route add default via 10.200.1.1

Checking route added or not

[root@emc ~]# ip netns exec emc1 ip route

default via 10.200.1.1 dev v-peer1

10.200.1.0/24 dev v-peer1 proto kernel scope link src 10.200.1.2

[root@emc ~]#

Let us check we can ping or not.

[root@emc ~]# ip netns exec emc1 ping 10.200.1.1

PING 10.200.1.1 (10.200.1.1) 56(84) bytes of data.

64 bytes from 10.200.1.1: icmp_seq=1 ttl=64 time=0.172 ms

64 bytes from 10.200.1.1: icmp_seq=2 ttl=64 time=0.111 ms

64 bytes from 10.200.1.1: icmp_seq=3 ttl=64 time=0.119 ms

^C

— 10.200.1.1 ping statistics —

3 packets transmitted, 3 received, 0% packet loss, time 1999ms

rtt min/avg/max/mdev = 0.111/0.134/0.172/0.027 ms

[root@emc ~]# ip netns exec emc1 ping 192.168.2.1

PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.

64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.124 ms

64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.121 ms

^C

— 192.168.2.1 ping statistics —

2 packets transmitted, 2 received, 0% packet loss, time 999ms

rtt min/avg/max/mdev = 0.121/0.122/0.124/0.011 ms

AWS Blog

aws_logo_consulting_partner-small