CKA: Network Namespace module

Hi

Relates to the Prerequsite Network Namesapces module of the CKA course linked here:

As directed in the course, running these commands on a Ubuntu 18.04 system after fresh OS install results in not being able to ping. Has anyone been able to get this working as instructed in the course module? Ping in step 6 results in “connect: Network is unreachable”. What am I missing?:

  1. Create two new network namespaces:
    ip netns add red
    ip netns add blue

  2. Create the virtual cable with two interfaces on either ends:
    ip link add veth-red type veth peer name veth-blue

  3. Attach each interface to the appropriate namespace:
    ip link set veth-red netns red
    ip link set veth-blue netns blue

  4. Assign IP addressed to each interface:
    ip -n red addr add 192.168.15.1 dev veth-red
    ip -n red addr add 192.168.15.2 dev veth-blue

  5. Bring up the new interfaces within their respective namespaces:
    ip -n red link set veth-red up
    ip -n blue link set veth-blue up

  6. Yet, ping does not work between the interfaces as it should:
    ip netns exec red ping 192.168.15.2

connect: Network is unreachable

Thanks in advance.

SMK

Hello sadamahan,
please try to add subnet when adding IP to ns.

ip -n red addr add 192.168.15.1/24 dev veth-red

ip -n blue addr add 192.168.15.2/24 dev veth-blue

check the following:
2020-05-15_18-23-33-a22f7e3ca277cec74eda7b1849a20e5c

1 Like

It works!

Thank you for the quick reply.

You are welcome @sadamahan

Hi,
I had the same problem and this fixed it also but for the single link.

However, it did not work when I tried it with the virtual switch. Do I need to add the subnet when configuring the virtual switch also?
Here is the output of my commands:

[root@k8scourse ~]# ip netns add red
[root@k8scourse ~]# ip netns add blue
[root@k8scourse ~]# ip link add v-net-0 type bridge
[root@k8scourse ~]# ip link set dev v-net-0 up
[root@k8scourse ~]# ip link add veth-red type veth peer name veth-red-br
[root@k8scourse ~]# ip link add veth-blue type veth peer name veth-blue-br
[root@k8scourse ~]# ip link set veth-red netns red
[root@k8scourse ~]# ip link set veth-red-br master v-net-0
[root@k8scourse ~]# ip link set veth-blue netns blue
[root@k8scourse ~]# ip link set veth-blue-br master v-net-0
[root@k8scourse ~]# ip -n red addr add 192.168.15.1/24 dev veth-red
[root@k8scourse ~]# ip -n blue addr add 192.168.15.2/24 dev veth-blue
[root@k8scourse ~]# ip -n red link set veth-red up
[root@k8scourse ~]# ip -n blue link set veth-blue up
[root@k8scourse ~]# ip netns exec red ping 192.168.15.2
PING 192.168.15.2 (192.168.15.2) 56(84) bytes of data.
^C
— 192.168.15.2 ping statistics —
10 packets transmitted, 0 received, 100% packet loss, time 9181ms

[root@k8scourse ~]# ip -n red link
1: lo: mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
7: veth-red@if6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN mode DEFAULT group default qlen 1000
link/ether 9e:88:1e:08:53:4f brd ff:ff:ff:ff:ff:ff link-netnsid 0