Owning the network with Linux

And scaring proprietary-only people, in the process!

Guido Trotter <ultrotter@debian.org>

  • Debian, Google, Ganeti, and such

Once upon a time

...

Why this talk

A few precautions

But if you want to do it in a corporation:

Old reliables

# Interfaces:
ip addr add 192.168.3.1/24 dev eth0
ip link set eth0 up
# Bridging:
brctl addbr br0
brctl addbr addif br0 eth0
brctl show
# Routing:
ip route
echo 1 > /proc/sys/net/ipv4/conf/all/forwarding
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding

Overview

VLAN Tagging

# your switch must be either very dumb, or quite helpful
ip link add link eth0 name eth0.3 type vlan id 3
ip addr add 192.168.3.1/24 dev eth0.3
ip link set eth0.3 up
# ...and now play with it (bridge it, route it, etc)

Tunneling

Basic tunneling

On host0 (172.16.15.33):

ip tunnel add gre0 mode gre local 172.16.15.33 \
  remote 172.16.22.9 key 42 dev eth0
ip addr add 192.168.4.1 peer 192.168.4.2 dev gre0
ip link set gre0 up

On host1 (172.16.22.9):

ip tunnel add gre0 mode gre local 172.16.22.9 \
  remote 172.16.15.33 key 42 dev eth0
ip addr add 192.168.4.2 peer 192.168.4.1 dev gre0
ip link set gre0 up

Unbound tunneling

# on each hostN (<ipN>):
ip tunnel add gre0 mode gre key 42 dev eth0
ip addr add 192.168.4.<N>/24 dev gre0
ip link set gre0 up

# for multicast, add to tunnel add:
#   local <ipN> remote 224.66.66.66

# for neighbor table lookup:
ip neigh replace 192.168.4.<N> lladdr <ipN> \
    nud permanent dev gre0

# Also doable via a specialized arpd (eg. opennhrp)

Policy routing

"Basic" policy routing

ip rule add dev gre0 table 100
ip rule add dev tun0 table 100

ip route replace table 100 proto static \
  192.168.4.0/24 dev gre0
ip route replace table 100 proto static \
  192.168.5.0/24 dev gre0 via 192.168.4.254 onlink
# Default routing via gateway
ip route replace table 100 proto static default \
  dev gre0 via 192.168.4.254 onlink

More policy routing

# Policy routing specific packets:
ip rule add fwmark 100 table 100
iptables -t mangle -I OUTPUT -d 192.168.4.0/24 \
  -p icmp --icmp-type fragmentation-needed \
  -j MARK --set-mark 100

# Asymmetric policy routing
ip route replace table 100 proto static \
  throw 192.168.0.0/16

Routing daemons

Quagga

apt-get install quagga

Anycast

Load balancing

Network namespaces

Network namespaces

# shell1:
lxc-unshare -s NETWORK -- /bin/bash
ip link set lo up
# ...wait for shell2...
ip addr add 192.168.4.2 peer 192.168.4.1 dev veth1
ip link set veth1 up

# In the meantime, on another shell (shell2):
ip link add name veth0 type veth \
  peer name veth1 netns <pid>
ip addr add 192.168.4.1 peer 192.168.4.2 dev veth0
ip link set veth0 up

Userspace fun

Q&A