Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Networking & Security
  • Search

BIND in chroot on gentoo with systemd

Having problems getting connected to the internet or running a server? Wondering about securing your box? Ask here.
Post Reply
Advanced search
3 posts • Page 1 of 1
Author
Message
Dr_b_
n00b
n00b
Posts: 33
Joined: Sun Jan 18, 2004 10:39 pm
Contact:
Contact Dr_b_
Website

BIND in chroot on gentoo with systemd

  • Quote

Post by Dr_b_ » Sun Sep 10, 2023 10:07 pm

Has anyone gotten bind/named working with gentoo running systemd in chroot jail, couldn't find any scripts or documentation regarding that, the bind wiki only covers openrc
Top
alamahant
Advocate
Advocate
Posts: 4034
Joined: Sat Mar 23, 2019 12:12 pm

  • Quote

Post by alamahant » Mon Sep 11, 2023 10:55 am

Ok I tried it.Its a little buggy.
This is what I did
First in /etc/conf.d/named i set chroot dir to /var/chroot/bind.
Then

Code: Select all

mkdir /var/chroot
emerge --config =net-dns/bind-9.16.42 ### specify your version.
/etc/init.d/named restart ####in your case systemctl restart named
#### for me it failed here complaining there is no named.conf in chroot.So I did
cp -pa  /var/bind/* /var/chroot/bind/var/bind/
cp -pa /etc/bind/* /var/chroot/bind/etc/bind/
/etc/init.d/named restart ####  systemctl restart named
###It worked.
To unset comment out chroot dir in /etc/conf.d/named and rerun

Code: Select all

emerge --config =net-dns/bind-9.16.42  ### ignore the error about failing to UNSET CHROOT
/etc/init.d/named restart ####in your case systemctl restart named
reboot
Then

Code: Select all

rm -rf /var/chroot/bind
:)
Top
Dr_b_
n00b
n00b
Posts: 33
Joined: Sun Jan 18, 2004 10:39 pm
Contact:
Contact Dr_b_
Website

  • Quote

Post by Dr_b_ » Mon Sep 11, 2023 9:52 pm

Here's what had to be done to get it to work with systemd:

Using the original /etc/conf.d/named config, set your chroot directory

Code: Select all

CHROOT="/named"
Run the emerge config script to populate the chroot directory:

Code: Select all

emerge --config =net-dns/bind-9.16.42
Create 2 new scripts, one to mount the bind mounts, and another to unmount them

bindmount.sh:

Code: Select all

#!/bin/bash

_mount() {
  from="$1"
  to="$2"

  # Check if mounted, else mount
  if ! mountpoint -q "$to"; then
    mount "$from" "$to" -o bind
  fi
}

# Mount the directories 
_mount "/etc/bind" "/named/etc/bind"
_mount "/var/bind" "/named/var/bind"
_mount "/var/log/named" "/named/var/log/named"
bindunmount.sh

Code: Select all

#!/bin/bash

_unmount() {
  mount_point="$1"

  # Check if mounted and unmount
  if mountpoint -q "$mount_point"; then
    umount "$mount_point"
  fi
}

# Unmount directories
_unmount "/named/etc/bind"
_unmount "/named/var/bind"
_unmount "/named/var/log/named"
modify the systemd unit file "systemctl edit named":

Code: Select all

[Service]
ExecStartPre=
ExecStartPre=/usr/local/bin/bindmount.sh
ExecStartPre=/usr/libexec/generate-rndc-key.sh
ExecStartPre=/usr/sbin/named-checkconf -z /etc/bind/named.conf
ExecStart=
ExecStart=/usr/sbin/named -t /named -u named -f
ExecStop=
ExecStop=/usr/sbin/rndc stop
ExecStopPost=/usr/local/bin/bindunmount.sh
then systemctl daemon-reload

systemctl start named and systemctl stop named should now properly start and stop named, and mount/unmount the directories.

The /etc/init.d/named rc-scripts are doing a few other things and consider addons like geoip, but this is the minimal necessary to get up and running with a base install
Top
Post Reply

3 posts • Page 1 of 1

Return to “Networking & Security”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic