Skip to content

Instantly share code, notes, and snippets.

@mrunalp
Created February 13, 2015 18:38
Show Gist options
  • Save mrunalp/5bed5daa39a88713f1cc to your computer and use it in GitHub Desktop.
Save mrunalp/5bed5daa39a88713f1cc to your computer and use it in GitHub Desktop.
ipvlan setup
1. Setup a Fedora 21 VM using virt-builder and import into virt-manager.
2. Download and compile https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.19.tar.xz with CONFIG_IPVLAN=m.
3. Copy the kernel to /boot and add it to grub using grub2-mkconfig and dracut. Reboot.
4. Steps from https://github.com/torvalds/linux/blob/master/Documentation/networking/ipvlan.txt with additional comments --
(a) Create two network namespaces - ns0, ns1
ip netns add ns0
ip netns add ns1
(b) Create two ipvlan slaves on eth0 (master device)
ip link add link eth0 ipvl0 type ipvlan mode l2
ip link add link eth0 ipvl1 type ipvlan mode l2
(c) Assign slaves to the respective network namespaces
ip link set dev ipvl0 netns ns0
ip link set dev ipvl1 netns ns1
(d) Now switch to the namespace (ns0 or ns1) to configure the slave devices
- For ns0
(1) ip netns exec ns0 bash
(2) ip link set dev ipvl0 up
(3) ip link set dev lo up
(4) ip -4 addr add 127.0.0.1 dev lo
(5) ip -4 addr add $IPADDR dev ipvl0 (pick an IP Address from the same subnet as your eth0)
e.g. ip -4 addr add 192.168.122.37 dev ipvl0
(6) ip -4 route add default via $ROUTER dev ipvl0
e.g. ip route add 192.168.122.0/24 dev ipvl0 proto kernel scope link src 192.168.122.37
ip route add default via 192.168.122.1 dev ipvl0 proto static metric 1024
- For ns1
(1) ip netns exec ns1 bash
(2) ip link set dev ipvl1 up
(3) ip link set dev lo up
(4) ip -4 addr add 127.0.0.1 dev lo
(5) ip -4 addr add $IPADDR dev ipvl1 (pick an IP Address from the same subnet as your eth0)
e.g. e.g. ip -4 addr add 192.168.122.47 dev ipvl1
(6) ip -4 route add default via $ROUTER dev ipvl1
e.g. Similar to above for ns0
5. One should be able to ping the IP addresses from each other and ping www.google.com from each namespace.
6. With kvm, one can also ping these IPs from the host because of the routes.
7. For production, we will need to assign a subnet to each node and then router will have to be programmed to keep track
of those routes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment