Skip to content

Instantly share code, notes, and snippets.

@beddari
Forked from nerdalert/gistify536965.md
Created January 18, 2016 07:55
Show Gist options
  • Save beddari/e5559f36b0b8135c1bc3 to your computer and use it in GitHub Desktop.
Save beddari/e5559f36b0b8135c1bc3 to your computer and use it in GitHub Desktop.
IPVlan L3 Verbose

Verbose L3 Instructions

(a) Create two network namespaces - ns1 / ns2

Machine #1

ip netns add ns1

Machine #2

ip netns add ns2

(b) Create two ipvlan slaves on eth1 (master device)

Machine #1

ip link add link eth1 ipvl1 type ipvlan mode l3

Machine #2

ip link add link eth1 ipvl2 type ipvlan mode l3

(c) Assign slaves to the respective network namespaces

Machine #1

ip link set dev ipvl1 netns ns1

Machine #2

ip link set dev ipvl2 netns ns2

(d) Now switch to the namespace (ns1 or ns2) to configure the slave devices Namespace: ns1

# Host 1
ip netns exec ns1 bash
ip link set dev ipvl1 up
ip link set dev lo up
ip -4 addr add 127.0.0.1 dev lo

# e.g. ip -4 addr add 192.168.1.110 dev ipvl1
# (pick an IP Address from the same subnet as your eth1)
IPADDR_1=192.168.1.110
ip -4 addr add $IPADDR_1 dev ipvl1

#  e.g. ip route add 192.168.1.0/24 dev ipvl1  proto kernel  scope link  src 192.168.1.110
#  ip route add default via 192.168.1.1 dev ipvl1  proto static  metric 1024

ip route add 192.168.1.0/24 dev ipvl1  proto kernel  scope link  src 192.168.1.110
ip route add default via 192.168.1.1 dev ipvl1  proto static  metric 1024

ROUTER=192.168.1.1
ip -4 route add default via $ROUTER dev ipvl1

Namespace: ns2

Machine #2

ip netns exec ns2 bash
ip link set dev ipvl2 up
ip link set dev lo up
ip -4 addr add 127.0.0.1 dev lo

# (pick an IP Address from the same subnet as your eth0)
# e.g. ip -4 addr add 192.168.1.120 dev ipvl2

ip route add 192.168.1.0/24 dev ipvl2  proto kernel  scope link  src 192.168.1.120
ip route add default via 192.168.1.1 dev ipvl2  proto static  metric 1024

IPADDR_2=192.168.1.120
ip -4 addr add $IPADDR_2 dev ipvl2

# e.g. Similar to above for ns0
ROUTER=192.168.1.1
ip -4 route add default via $ROUTER dev ipvl2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment