Router – OpenBSD Setup

Network Overview

                ┌─────────────────────┐
                │      Gateway        │
                │                     │
                │                     │
                │                     │
                └───────▲─────────────┘
                        │                       
                        │                       
                        │                 
                ┌───────▼─────────────┐   
                │    **  Router **    │   
                └───────▲─────────────┘  
                        │
                        │
                        │
                ┌───────▼──────────────────────────────┐
                │                  LAN                 │
                │   - Desktops                         │
                │   - Laptops                          │
                │   - Wifi AP                          │
                │   -                                  │
                │   - NAS (network‑attached storage)   │
                └──────────────────────────────────────┘

The router will be reachable at 10.0.10.1

Interface Configuration

First enable IP forwarding

# echo 'net.inet.ip.forwarding=1' >> /etc/sysctl.conf
# sysctl net.inet.ip.forwarding=1
    

Interfaces are in this example re0 and ure0

/etc/hostname.re0

inet autoconf
    

/etc/hostname.ure0

inet 10.0.10.1 255.255.255.0
    

After editing, reload the network:

# sh /etc/netstart
    

Unbound DNS – Ad‑blocking Setup

  1. Run the script that builds the blocklist: $ ./unbound_blocklist.sh
  2. Create the directory for Unbound’s ad‑block config: # mkdir -p /var/unbound/etc/adblock
  3. Copy the generated config file: # cat unboundadblock.conf > /var/unbound/etc/adblock/unboundadblock.conf

/var/unbound/etc/unbound.conf

server:
    interface: 10.0.10.1
    access-control: 10.0.10.0/24 allow
    do-ip6: no
    verbosity: 1
    hide-identity: yes
    hide-version: yes 
    harden-glue: yes 
    harden-dnssec-stripped: yes
    use-caps-for-id: yes 
    auto-trust-anchor-file: "/var/unbound/db/root.key"
    prefetch: yes
    include: "/var/unbound/etc/adblock/unboundadblock.conf"
    include: "/var/unbound/etc/adblock/omat.conf"
    port:53
    tls-cert-bundle: "/etc/ssl/cert.pem"

forward-zone:
    name: "."
    forward-tls-upstream: yes
    forward-addr: 9.9.9.9@853#dns.quad9.net
    

Create conf for your own shit
Create /var/unbound/etc/adblock/omat.conf file:

    # Block
    local-zone: "cdn.privacy-mgmt.com" static

    # Redirect to internal web server
    local-zone: "tiktok.com" redirect
    local-data: "tiktok.com A 10.0.10.1"
    

Internal web server will be set up later.

Initialize the trust anchor and test the configuration:

# unbound-anchor -a /var/unbound/db/root.key
$ unbound-checkconf
    

Enable and start Unbound:

# rcctl enable unbound
# rcctl start unbound
    

Check that it is running:

# rcctl ls started
    

Check that it is enabled:

$ rcctl ls on
    

/etc/resolv.conf

nameserver 10.0.10.1
    

If resolvd keep overwriting resolv.conf disable and stop resolvd

# rcctl disable resolvd
# rcctl stop resolvd 
    

Test a lookup:

$ dig @10.0.10.1 example.com
    

Log output can be watched with:

$ tail -f /var/log/messages
    

Increase verbosity on unbound.conf for more detailed logging

DHCP Server

Copy the example configuration and edit it:

# cp -v /etc/examples/dhcpd.conf /etc/
    

/etc/dhcpd.conf

In this example MAC adresses are replaced with 00:00:00:00:00:xx

# DHCP server options.
# See dhcpd.conf(5) and dhcpd(8) for more information.
#

# Network:		10.0.10.0/255.255.255.0
# Domain name:		my.domain
# Name servers:		10.0.10.1
# Default router:	10.0.10.1
# Addresses:		10.0.10.100 - 10.0.10.127
#
#option  domain-name "my.domain";
option  domain-name-servers 10.0.10.1;

subnet 10.0.10.0 netmask 255.255.255.0 {
	option routers 10.0.10.1;
	
	range 10.0.10.100 10.0.10.127;
	default-lease-time 86400;
	max-lease-time 604800;


        host old-shitty {
                hardware ethernet 00:00:00:00:00:01;
                fixed-address 10.0.10.5;
        }	

 	host ryzen3600 {
		hardware ethernet 00:00:00:00:00:02;
                fixed-address 10.0.10.10;
        }

        host thinkpad {
                hardware ethernet 00:00:00:00:00:03;
                fixed-address 10.0.10.11;
        }


        host intel4770 {
                hardware ethernet 00:00:00:00:00:04;
                fixed-address 10.0.10.12;
        }

	host kamera-autotalli {
		hardware ethernet 00:00:00:00:00:05;
		fixed-address 10.0.10.30;
		}

	host kamera-kuisti {
		hardware ethernet 00:00:00:00:00:06;
  		fixed-address 10.0.10.31;
		}

	host kamera-talonkulma {
  		hardware ethernet 00:00:00:00:00:07;
  		fixed-address 10.0.10.32;
		}

	host kamera-soittokamppa {
  		hardware ethernet 00:00:00:00:00:08;
  		fixed-address 10.0.10.33;
	}

	host ryzen-9600x {
  		hardware ethernet 00:00:00:00:00:09;
  		fixed-address 10.0.10.40;
		}

	host ryzen-9700x {
  		hardware ethernet 00:00:00:00:00:10;
  		fixed-address 10.0.10.50;
		}

	host iPadH {
  		hardware ethernet 00:00:00:00:00:11;
  		fixed-address 10.0.10.52;
		}

	host Ryzen-2600x {
  		hardware ethernet 00:00:00:00:00:12;
  		fixed-address 10.0.10.57;
		}

	host ryzen-2500u {
		hardware ethernet 00:00:00:00:00:13;
		fixed-address 10.0.10.58;
		}

        host usb-ethernet {
                hardware ethernet 00:00:00:00:00:14;
                fixed-address 10.0.10.59;
                }

	host Intel-i5-6600K {
  		hardware ethernet 00:00:00:00:00:15;
  		fixed-address 10.0.10.60;
		}

	host Raspberrypi {
  		hardware ethernet 00:00:00:00:00:16;
  		fixed-address 10.0.10.69;
		}
}
    

Enable and start the DHCP daemon

# rcctl enable dhcpd
# rcctl set dhcpd flags ure0
# rcctl start dhcpd
    

If you modify the config later, restart it:

# rcctl restart dhcpd
    

View active leases:

$ cat /var/db/dhcpd.leases
    

Watch the DHCP log:

$ tail -f /var/log/daemon
    

Internal Web Server (httpd)

# mkdir -p /var/www/htdocs/web
# chmod -R 755 /var/www/htdocs/web
# chown -R www:www /var/www/htdocs/web
    

/etc/httpd.conf

server "default" {
    listen on * port 80
    root "/htdocs/web"
}
    

Start the web server:

# httpd -n
# rcctl enable httpd
# rcctl start httpd
    

Confirm it’s running:

# rcctl ls started
    

Put index.html to /var/www/htdocs/web/

Packet Filter (pf) Configuration

/etc/pf.conf

ext_if="re0"
int_if="ure0"
localnet="ure0:network"

table <martians> { 0.0.0.0/8 10.0.0.0/8 127.0.0.0/8 169.254.0.0/16     \
                   172.16.0.0/12 192.0.0.0/24 192.0.2.0/24 224.0.0.0/3 \
                   192.168.0.0/16 198.18.0.0/15 198.51.100.0/24        \
                   203.0.113.0/24 }

set skip on lo

match in all scrub (no-df random-id max-mss 1440)

antispoof quick for { $int_if $ext_if }

match out on $ext_if inet from $localnet nat-to ($ext_if)

block log all

pass out on $ext_if inet

pass in on $int_if inet 

block return in quick log on $int_if proto { udp tcp } to ! $int_if port { 53 853 }
block return in quick log on $int_if proto udp to ! $int_if port 123

block in quick log on $ext_if from <martians> to any
block return out log quick on $ext_if from any to <martians>

# By default, do not permit remote connections to X11
block return in on ! lo0 proto tcp to port 6000:6010

# Port build user does not need network
block return out log proto {tcp udp} user _pbuild
    

NTP Server (OpenNTPD)

Add a listen directive to /etc/ntpd.conf

listen on *
    

Restart the daemon. 10.0.10.1 can now be used as a NTP server inside the LAN.

 # rcctl restart ntpd
    

Additional settings

Edit /etc/ssh/sshd_config

PermitRootLogin no
ListenAddress 10.0.10.1
    
kuva

Heikki Vuojolahti

www.ghr.fi