Problems with Local DNS Resolution

Modern versions of Linux Mint, and likely others using systemd, can have issues with local DNS resolution. For me it appears as the system not resolving local DNS from my Pi-hole server.

It seems complicated and many solutions have been floated for solving it:

  • Editing nsswitch.conf
  • Editing NetworkManager.conf
  • Disabling various services

The single solution that has worked for me every time is replacing /etc/resolv.conf, or rather symlinking it to a different configuration file that already exists and is auto-generated.

rm /etc/resolv.conf

ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

This maybe breaks DNSSEC resolution because it removes the option “options edns0 trust-ad”, so do your homework if that concerns you.

Restoring it to the previous configuration is as simple as:

rm /etc/resolv.conf

ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf

Subsonic Fails to Stop

On my media server, I found that Subsonic (6.1.6) would start but not stop by issuing ‘service subsonic stop’ or ‘systemctl stop subsonic’. It seems like the default init script does not allow start-stop-daemon to properly identify the process.

Honestly, systemd has been around long enough that the installer should include a subsonic.service file for systemd. I would try to write one, but I only need this to work for a while until I find a replacement media server.

The original line 87 from /etc/init.d/subsonic reads:

start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE

The modified line reads as follows:

start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --user $SUBSONIC_USER --exec /usr/bin/java

–user $SUBSONIC_USER allows start-stop-daemon to identify the server process by the username it is running under. The value is automatically pulled from /etc/default/subsonic.

–exec /usr/bin/java tells start-stop-daemon the exact path of the java process. This could vary from system to system.

The system is a Raspberry Pi 4 running Raspbian 10.

Settings for Transcoding in Subsonic (Linux)

If you also have many music files in flac format, it is frustrating that the default configuration of Subsonic won’t play them.  This is easy to fix.  I began with the following transcoding settings (from the Subsonic Forum,  thanks to jeremyh):


Name: mp3 audio
Convert From: ogg oga aac m4a flac wav wma aif aiff ape mpc shn
Convert To: mp3
Step 1: avconv -i %s -b %bk -q 0 -loglevel error -f mp3 –
Step 2: (blank)


At first this did not work, even though I’d installed avconv and all codecs through my package manager.  I discovered that Subsonic was only searching in /var/subsonic/transcode for the avconv binary.  This limited Subsonic to using the converters that were installed with it.  I suppose this is intentional, to maintain compatibility on diverse systems and avoid the need for users to find/download/install the converters.

Instead of tweaking the environment variable for the Subsonic user, I opted to symlink some specific binaries.

Edit:  Apparently the path for user subsonic is correct.  It could be that Subsonic is hard-coded to ignore it.  If anyone reading this knows the answer it could be interesting, but for now all is working so I’ll leave it alone.

From /var/subsonic/transcode I ran:


ln -s  /usr/bin/avconv avconv

ln -s /usr/bin/nice nice


The reason I symlinked nice is to be able to reduce processor load during transcoding; more about this below.

I had also symlinked lame in the past, but avconv is able to do everything I need now.

With all that done and confirmed working, I edited Step 1 of the transcoding instruction to:


nice -n15 avconv -i %s -b %bk -q 0 -loglevel error -f mp3 –


Each time the avconv process starts, it is reniced to 15.  This means it has a lower priority than most other processes.  If some more important process needs to do something, avconv will get out of the way for a while.

I use the official Android client for Subsonic on my phone.  I set it to preload (cache) an unlimited number of songs from my playlist, which helps me quickly load music for offline listening.  This can occupy the Pi for a while, but renicing avconv helps ensure that this process doesn’t interfere with other tasks on the Pi.

 

Hardware:  Raspberry Pi B+

Operating System:  Raspbian

Subsonic Version:  5.2.1 for Debian/Ubuntu (deb)


Edit June 1/2016:

Now my Subsonic installation is up to version 6 and running on an AMD64 system with Debian 7 (openmediavault).  For a while, even before Subsonic 6, there would be stoppages in playback of flac files.  The backend was transcoding the file over and over during the song, each time getting further from the start and eventually not being able to keep up with playback.

I think it’s something to do with the adaptive transcoding, adjusting the bitrate as the song plays but being unable to transcode only part of the file as needed rather than starting from the beginning.  It could be due to the use of metaflac as the first step in playback.

Using instructions from the Arch Wiki (https://wiki.archlinux.org/index.php/Subsonic) I set my flac transcoding to:

Step 1:  flac –silent –decode –stdout %s

Step 2: lame –silent -h -b %b –

Now it works interruption-free except it takes a long time for playback to start in the default Subsonic web interface.  It’s seamless with D-sub though.

The whole reason for employing metaflac in step 1 was to overcome playback problems with certain flac files.  Now I can’t remember which files were the problem, so I’ll need to test further.

Block Web Nasties With Tomato Firmware and a Hosts File

To add network-wide protection from known ad/malware sites on the internet, load this WAN-UP script into your router running Tomato firmware:

logger WAN UP Script Executing
sleep 5
test -s /tmp/dlhosts
if [ $? == 1 ] ; then
echo -e "#!/bin/shnwget -O - http://winhelp2002.mvps.org/hosts.txt | grep .0.0. | sed -e '2,$s/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//' > /etc/dnsmasq/hosts/blkhostsnlogger DOWNLOADED http://winhelp2002.mvps.org/hosts.txtnkillall -1 dnsmasq" > /tmp/dlhosts
chmod 777 /tmp/dlhosts
/tmp/dlhosts
fi
cru a Gethosts "45 23 * * 5 /tmp/dlhosts"

As of this date the downloaded hosts file is 499KB, so it does take up a not insignificant amount of RAM. Still, if your router is less than 10 years old it’ll probably handle it. Before loading the script you can check the router’s Total/Free Memory from the status page.

I have seen this or similar scripts in various places, but I took this one from this forum post. Thanks to the author and all the people who have tweaked and improved the script over time. Thanks especially to the maintainer of the hosts file hosted on winhelp2002.mvps.org.

One last point; many websites depend on ad revenue to survive. If you frequent sites that depend on ad revenue and you appreciate their content, please adjust the script to unblock their ad servers. If you don’t know how to determine which ad servers they use, contact the page maintainer and they’ll be happy to help.

Reset Nagios Admin Password

Hash and store a new password. If Nagios was installed manually then htpasswd.users may not exist. In that case this creates a new user account for Nagios:

#htpasswd -c /etc/nagios3/htpasswd.users nagiosadmin

Restart nagios to make settings take effect:

#service nagios3 restart

Debian 7
Nagios Core V3.4.1
Apache 2.2.22 (Debian)

Auto-start of SSH Agent on Cygwin

Here is how to get ssh-agent started automatically every time you run Cygwin. If you’re also burdened with working on a Windows machine all day, having Cygwin at your disposal can be essential.

Until recently I didn’t know Cygwin included ssh-agent; simply typing ssh-add at the command prompt doesn’t start it as it does within most distributions.

First, create a bash profile from within Cygwin, if you don’t already have one:

touch ~/.bash_profile
chmod a+x ~/.bash_profile

Add the following commands to the file:

SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
eval `$SSHAGENT $SSHAGENTARGS`
trap "kill $SSH_AGENT_PID" 0
fi

Next time you open Cygwin, you can run ssh-add to load your keys. Maybe best of all, it unloads the authentication agent when your Cygwin session is closed.

All credit and many thanks to the author of the “Kill The Radio” blog (original post)

Using netcat to copy files between servers

Here’s a real gem posted by tiagofischer here on commandlinefu.com for fast copying of files across a trusted network:


On target: “nc -l 4000 | tar xvf -”
On source: “tar -cf – . | nc target_ip 4000”

Using netcat to copy files between servers. It bypasses encryption overhead of SSH and depending on configuration can be significantly faster. It’s recommended to use only in trusted networks.


I lost track of it once and had a tough time finding it again.


Edit 2014-04-12: For some reason the above isn’t working for me anymore, but this one does:

On target: "nc -l -p 9000 | tar x"
On source: "tar cf - folder | nc other_server 9000"

I found this at this site.