Day 4/100daysofK8s
Network Namespaces — are what the name suggests, namespaces for networks. So anything created within that namespace, will only be accessible within the namespace, and nothing outside it can be accessed.
Network namespace can be created with — ip netns add <name>
To access networks, routes, arp(address resolution protocol) or anything within the namespace, run — ip netns exec <netnsname> <cmd>
.
Establishing connectivity between 2 namespaces —
- Create an interface or say virtual wire that will connect both the namespaces with
ip link add <netns1> type veth peer name <netns2>
- Attach the interface of
netns1interface
to itself, and that ofnetns2interface
to itself. —ip link set <netns1interface> netns <netns1>
,ip link set <netns2interface> netns <netns2>
- Assign the IP address to both the interfaces with —
ip -n <netns1> addr add <ip address> dev <netns1interface>
,ip -n <netns2> addr add <ip address> dev <netns2interface>
- Bring up the interfaces so that they’re ready to use with —
ip -n <netns1> link set <netns1interface> up
,ip -n <netns2> link set <netns2interface>
.
The connectivity can be tested by pining the ipaddresses from either of the network namespaces with — ip netns exec <netns1> ping <ip address of netns2>
Anything done within the namespaces is unknown to the host and vice versa.