Virtual Ethernet - HaymonEdmur/DockerConfiguration GitHub Wiki
Virtual Ethernet
Virtual Ethernet Configuration
Virtual ethernet is like a UNIX named pipe. By default both ends are in root netns. Hence both ends are visible in root netns.
# ip link add Z0 type veth peer name Z1
Z1 and Z2 and two ends of virtual ethernet visible in root name space.
# ip addr show dev Z1
2: Z1@Z0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 52:18:87:20:14:5e brd ff:ff:ff:ff:ff:ff
# ip addr show dev Z0
3: Z0@Z1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 7e:78:e6:86:eb:8a brd ff:ff:ff:ff:ff:ff
Connecting two network spaces
Keep Z0 in root namespace Add Z1 to braintree namespace If Z1 is added to braintree then it won't be visible in root space
# ip link set Z1 netns braintree
Configure Virtual Ethernet IP addresses
Configure Z0 in root space
# ip addr add 20.20.1.1/24 dev Z0
# ip link set Z0 up
# ip addr show dev Z0
3: Z0@if2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN group default qlen 1000
link/ether 46:b9:84:77:c1:53 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 20.20.1.1/24 scope global Z0
valid_lft forever preferred_lft forever
Configure Z1 in child netns
# ip addr add 20.20.1.2/24 dev Z1
# ip link set Z1 up
Set default route for Z1
# ip route add default via 20.20.1.1
# ip route show default
default via 20.20.1.1 dev Z1
20.20.1.0/24 dev Z1 proto kernel scope link src 20.20.1.2
# ping 20.20.1.1
PING 20.20.1.1 (20.20.1.1) 56(84) bytes of data.
64 bytes from 20.20.1.1: icmp_seq=1 ttl=64 time=0.039 ms
64 bytes from 20.20.1.1: icmp_seq=2 ttl=64 time=0.027 ms
64 bytes from 20.20.1.1: icmp_seq=3 ttl=64 time=0.046 ms
^C
--- 20.20.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms