Skip to content

Instantly share code, notes, and snippets.

@tomty89
Created February 1, 2022 11:28
Show Gist options
  • Save tomty89/8604e6c4755c4db67d49cd4a3208b2fa to your computer and use it in GitHub Desktop.
Save tomty89/8604e6c4755c4db67d49cd4a3208b2fa to your computer and use it in GitHub Desktop.
dhcp0
port=0
dhcp-range=192.168.150.2,192.168.150.252
dhcp-option=option:router,192.168.150.1
dhcp-option=option:dns-server,192.168.150.1
[Unit]
Description=dnsmasq - A lightweight DHCP and caching DNS server
Documentation=man:dnsmasq(8)
BindsTo=netns-dhcp0.service
After=network.target netns-dhcp0.service
Before=network-online.target nss-lookup.target
Wants=nss-lookup.target
[Service]
NetworkNamespacePath=/run/netns/dhcp0
ExecStartPre=/usr/bin/ip addr add 192.168.150.254/24 dev dhcp0
ExecStartPre=/usr/bin/ip link set dhcp0 up
ExecStartPre=/usr/bin/dnsmasq --test
ExecStart=/usr/bin/dnsmasq -k --user=dnsmasq --pid-file -C /etc/dnsmasq/dhcp0.conf
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
PrivateDevices=true
ProtectSystem=full
[Install]
WantedBy=multi-user.target
[Unit]
Description=netns for dhcp0
Requisite=systemd-networkd.service
After=systemd-networkd.service
PartOf=dnsmasq-dhcp0.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/ip netns add dhcp0
ExecStart=/usr/bin/ip link set dhcp0 netns dhcp0
ExecStop=/usr/bin/ip -n dhcp0 link set dhcp0 netns 1
ExecStopPost=/usr/bin/ip netns delete dhcp0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment