Linux routing lab

From k-space wiki
Jump to: navigation, search

Intro

In this lab we see how any Linux distribution can be used as a router.

Equipment

For this lab you need:

  • PC with 4 or more network interfaces and 64GB+ SSD
  • Memory stick to install Debian


Steps

Set up Debian as router

Start off by configuring eth0 as WAN interface, use available IP address from range 193.40.101.107-126 as the IP address, netmask 255.255.255.192, 193.40.101.65 as the gateway. Verify that you can ping 8.8.8.8 and google.com. Configure bridge over remaining network interfaces as LAN interface, use 10.107-126.0.1 as the IP address, netmask 255.255.0.0.

You need to install couple essential packages for networking basics:

apt install vlan bridge-utils

Your /etc/network/interfaces should eventually look something like this:

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
	address 193.40.101.107
	netmask 255.255.255.192
	gateway 193.40.101.65
	dns-nameservers 8.8.8.8

auto br-lan
iface br-lan inet static
	address 10.107.0.1
	netmask 255.255.0.0
	bridge_ports eth1 eth2 eth3 eth4 eth5 eth6 eth7

Configure static IP address on your laptop from the same subnet and verify that you can access the machine via LAN network interface.

Enable packet forwarding and add iptables rules for masquerading traffic on the outgoing interface:

# This will permanently enable packet forwarding
echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf
sysctl -p

Configure DHCP and DNS

Easy way to get started is to use dnsmasq which by default serves as DHCP server and DNS cache.

apt install dnsmasq

Configure /etc/dnsmasq.conf:


  • Install dnsmasq to serve DHCP and DNS caching on the LAN segment. Revert your laptop back to DHCP and verify it works.

Add wireless network interface

Install hostapd to configure wireless network interface as an access point.