ip netns add <name-net-space>
: to addip netns
: to list
red
network namespace, only lo is listed. This is because it’s in an isolated environment.arp
(i.e address resolution protocol) command.veth-blue
interface and veth-red
together
ip link add veth-blue type veth peer name veth-red
ip link add <p1-name> netns <p1-ns> type veth peer <p2-name> netns <p2-ns>
ip link set veth-red net-ns red
ip link set veth-blue net-ns blue
red
ns: .15.1 is its ip with veth-red
interfaceblue
ns: .15.2 is its ip with veth-blue
interface
ip -n red addr add 198.168.15.1 dev veth-red
ip -n blue addr add 198.168.15.2 dev veth-blue
ip -n red link set veth-red up
ip -n blue link set veth-blue up
bridge
to host : ip link add v-net-0 type bridge
ip link set dev v-net-0 up
ip link add veth-red type veth peer name veth-red-br
ip link add veth-blue type veth peer name veth-blue-br
...
ip link set veth-red netns red
ip link set veth-red-br master v-net-0
[!Note]
ip link set
, when used withmaster
, it associates a network device (like a virtual interface) with a bridge, effectively adding it to the bridge
ip -n red addr add 192.168.15.1 dev veth-red
ip -n blue addr add 192.168.15.2 dev veth-blue
ip -n red link set veth-red up
ip -n blue link set veth-blue up
[!Important] The network that contains
veth-red
,veth-blue
andv-net-0
for the virtual switch are isolated. That is, if the host try to ping one of the namespaces, it’s not reachable Nothing from the outside world can reach this namespace and vice versa
v-net-0
with an ip adress
ip addr add 192.168.15.5/24 dev v-net-0
eth0
is the interface to the external networkv-net-0
is the interface for the virtual network switch of all the namespaces (i.e: red-veth, blue-veth,etc.)- Add destination ip to routing table of the network namespace:
```bash
ip netns exec blue ip route add 192.168.1.0/24 via 192.168.15.5
[!Reminder]
192.168.15.5
is the ip address assigned tov-net-0
interface
ip netns exec blue ping 8.8.8.8
ip route add default via 192.168.15.5
iptables -t nat -A PREROUTING --dport 80 --to-destination 192.168.15.2:80 -j DNAT