Network namespaces have their own network protocol stacks distinct
from those of the hosts. This means that a namespace can have its own
internal routing rules, independent of those of the host.
Setup
To play with this, let’s create a pair of network namespaces, connect
them with veth pairs and experiment with pinging between them. I
borrowed this
script
that I found on stackoverflow to create this situation. The script
must be invoked with sudo.
Experiment
Now that the two namespaces, test-1 and test-2, have been created,
use ip netns exec test-1 /bin/bash to open a shell to test-1
and similarly open one to test-2. In test-1, ping the other
container at address 192.168.2.1 while watching the packet counts for
the various rules using:
Disable the ping response from test-2 to observe only the
INPUT chain counters incrementing.
Experiment with adding chains and rules to the chains and seeing the
effect on the rule counters.
To restore the original table,
Alternatively, delete the namespace itself in a shell on the host,