Steam Link

Steam Link

Steam Link DNS server
I've gotten dnsmasq working on the Steam Link if you wanted to use it as a local DNS server. It's simple to get working. You will need a USB drive, and another computer or device that allows you to connect to the Steam Link via SSH, to run update.sh. It will run in the background and should not affect the Steam Link's operation aside from memory usage. Shouldn't ever be more than 13MB of the Steam Link's 256MB of memory with default settings. You can find the manual for dnsmasq at the bottom.

File is here. Make sure you set sleep mode to never if you plan on using it.
https://drive.google.com/file/d/1HvZPT3ZxS3gBOna8sDvA2W3pFl6Y5aTa/view?usp=share_link
2022-12-04
Correctly doing startup this time with /etc/init.d/startup/S90dnsmasq
Cache changed to 1000

2022-11-27 - Should be final barring any reported bugs.
Includes the build script with the Zip file.
- Creates script to generate uninstaller.
- Adds auto start as part of install
- Updated the update.sh to be more robust.
- Changed cache to 100 and updated conf files.
- Detects Gateway IP and Steam Link IP for file creation.
- New icon for the menu



Instructions:
File needs to be extracted and put on a USB.
Put the USB drive in the Steam Link and reboot it or power it up.

You will need to ssh into the device from a terminal. From Windows you can use the command prompt (cmd). I have yet to meet a Linux that this command doesn't work on as well.
ssh -l root 192.168.x.x
x being the Steam Link's IP. steamlink123 is the default password.
Note: you can use the command passwd to change it, and it is recommended.

If you get the command line #, then we are connected, run these
cd /home/apps/dnsmasq ./update.sh

All set. From there you can put the Steam Link IP into your router's primary DNS so that the router looks to the Steam Link first when it tries to resolve an address. You can find information on how to access your router from the vendor or other internet sources. You should be able to get your router's IP from the auto detection that was put in hosts.conf. You can display it with
cat /home/apps/dnsmasq/hosts.conf
You can usually put that first number in a web browser to connect to the router if you are on the same network.




Note:
The Zip file includes /steamlink/config/system/enable_ssh.txt which turns on SSH access to the Steam Link.

Note:
You can get the IP address from the network menu on the Steam Link. Highly recommended to change it from dynamic IP to static IP. It is possible otherwise that the Steam Link will acquire a new IP address in the future and the config will not match. Note that if switching between Wireless and Ethernet there will be a different IP if it isn't changed to static on both. If you run into an issue, you can rerun update.sh and it will find the IP again and fix the files. The update.sh is designed so it can be run any number of times and not change anything that isn't needed. It does require a reboot on each run.

Note:
If the USB is left plugged in, it will reinstall dnsmasq and reset settings on every reboot. So unplug before restarting. If you decide that you no longer want to use dnsmasq there is an uninstall.sh that will revert any changes. (Removes user and group for dnsmasq and the startup from the shell.sh and removes --no-dns-proxy from connmand. Also restores the original hosts file and removes conf files for dnsmasq in /etc). You will need to ssh into the Steam Link to use the uninstall.sh and it needs to be made executable before you can run it (chmod +x uninstall.sh then ./uninstall.sh) After that you can remove the /home/apps/dnsmasq folder.

Note:
You can modify dnsmasq.conf parameters and run ./update.sh again at anytime and it will ask to reboot to apply new settings. Update will check that the file has proper context before updating so it won't write bad values.

Note:
You can modify resolv.conf and run ./update.sh again to change the DNS servers that dnsmasq will use when it doesn't know an address. 8.8.8.8 and 4.2.2.2 are Google if you wanted to change to use those.

Note:
You can modify hosts.conf and run ./update.sh again to push a hosts file. You can use hosts to block or blackhole certain addresses. There are host files available on the internet that target ads or block malicious sites that you can use, or you can add your own manually. Keep at least the first 2 lines in the hosts file so that we have our Steam Link's local information.

Note:
dnsmasq.sh checks if it's already running and won't start multiple copies. It shouldn't anyway because port 53 will already be taken by itself, but it checks anyway.




Further information:
update.sh does the below steps for you.

There are several steps below that are one time changes that need to be made on the Steam Link if not using update.sh

"dnsmasq: failed to create listening socket for port 53: Address already in use"
Port 53 is blocked. You need to change etc/init.d/connmand.sh (--nodnsproxy)
From
connmand -n --wifi=nl80211 ${DEBUG_OPTIONS}
To
connmand -n --nodnsproxy --wifi=nl80211 ${DEBUG_OPTIONS}

"dnsmasq: unknown user or group: nobody" (Defaults to user nobody group dip)
adduser nobody
addgroup dip
addgroup -S nobody dip

Then create or copy a text file called dnsmasq.conf to /etc. You can get options from the dnsmasq man page that is linked at the bottom of this discussion.
no-resolv
interface=eth0
interface=mlan0
server=76.76.10.0#53
listen-address=127.0.0.1
cache-size=150
local-ttl=3600

interface=eth0 is if you use an ethernet cable, mlan0 if using wireless. You can keep both interfaces in the config but take note that switching between the two will change the IP Address if you don't assign as static.

The cache defaults to 50 but I upped it to 100. Bigger is slower as the whole cache is stored in memory, but it will remember more entries. This may be the most important option and is where your mileage will vary. You want as many possible up until it causes issues. 150 seemed to be a bit much during my testing, but there could be other factors.

You can check if it's running with another computer
telnet 192.168.x.x 53
x being the Steam Link's IP. If it doesn't time out then it's connecting (note port 53)

or sudo apt install dig
and dig 192.168.x.x

Or if you are on the Steam Link you can check if ./dnsmasq is running with
top

Or if you want to build your own from scratch with the Steam Link SDK, the build_steamlink.sh is included in the zip file. You will need to copy the file to your SDK build environment and chmod +x the file. It is not to be run on the Steam Link.

It builds all the necessary files and creates dnsmasq/dnsmasq.tgz ready to drop in place on a USB drive. It does not do the enable_ssh.txt file for the USB. And you will need /steamlink/config/system/enable_ssh.txt on the USB to enable it. A blank file is fine, it just needs that path and filename.

If there is another update it may have an optional kill mode that terminates as many processes as possible on startup to bare bones it as purely a DNS server. This isn't currently planned. Seems simple to implement and should be non destructive as the processes would just restart on a reboot. Possibly a menu button or something along those lines. Would rather not have it do something like that automatically as it would require running SSH again to disable the kill feature so that the menu operates normally again.

If you find any bugs, have ideas, or have recommended changes please contribute to the discussion here.

Default setting is 100 cache entries so even grossly overestimating 128bytes per entry, 12.8MB of the 256MB on the Steam Link. The default settings are what I recommend to start with, but cache size tuning is explained in far better detail than I could over here.
http://flux242.blogspot.com/2012/06/dnsmasq-cache-size-tuning.html

The manual for dnsmasq
https://linux.die.net/man/8/dnsmasq
You can use it as a DHCP server too if you wanted to change the dnsmasq.conf.

-F, --dhcp-range=[[net:]network-id,]<start-addr>,<end-addr>[[,<netmask>],<broadcast>][,<lease time>]