{"id":22051595,"url":"https://github.com/parlaynu/sonos-over-vpn","last_synced_at":"2025-05-09T02:19:41.409Z","repository":{"id":64586433,"uuid":"576779725","full_name":"parlaynu/sonos-over-vpn","owner":"parlaynu","description":"Remotely access and control your Sonos speakers over VPN.","archived":false,"fork":false,"pushed_at":"2024-05-28T21:23:18.000Z","size":104,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-31T21:27:36.235Z","etag":null,"topics":["ansible","raspberry-pi","sonos","terraform","vpn","wireguard"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parlaynu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-11T00:16:12.000Z","updated_at":"2024-07-31T04:36:43.000Z","dependencies_parsed_at":"2024-05-29T00:18:19.263Z","dependency_job_id":"0615ca98-5c77-41eb-b15c-a149b4a75137","html_url":"https://github.com/parlaynu/sonos-over-vpn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parlaynu%2Fsonos-over-vpn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parlaynu%2Fsonos-over-vpn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parlaynu%2Fsonos-over-vpn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parlaynu%2Fsonos-over-vpn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parlaynu","download_url":"https://codeload.github.com/parlaynu/sonos-over-vpn/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253176507,"owners_count":21866154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","raspberry-pi","sonos","terraform","vpn","wireguard"],"created_at":"2024-11-30T15:09:53.726Z","updated_at":"2025-05-09T02:19:41.384Z","avatar_url":"https://github.com/parlaynu.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sonos over VPN\n\nThis project describes how to remotely access and control your Sonos speakers using the app over a VPN \nconnection into your home network. The final build looks like this:\n\n![Network Diagram](docs/sonos-vpn.png)\n\nThese instructions assume that you run a very simple network with just your ISP provided router on your local\nnetwork. If you're doing something more advanced, the details below will be different.\n\nSee below for the challenges that need to be overcome. \n\nInstructions for setting up the vpn server and networking are [here](docs/server-and-network.md).\n\nInstructions for setting up clients are [here](docs/client-setup.md).\n\n## Challenges\n\nThere are three challenges to overcome to get this to work:\n\n* the app only works on wifi networks\n* the multicast service discovery protocol doesn't cross network boundaries\n* return traffic from the speakers to the app use the app's VPN IP address\n\nThe build and operational instructions below address all these issues.\n\nOnce the app has discovered the speakers and the speakers know about the app, the traffic seems to be\nunicast traffic and it all works smoothly... it's the discovery and setting up the initial connection\nthat has special challenges.\n\n### Challenge #1: Wifi Network\n\nThe app checks if your device is on a wifi network, and if it isn't, then it refuses to operate.\n\nThe way I use it is, as shown in the diagram above, to setup a hotspot on my mobile phone and then connect \nmy tablet to it and start the VPN on my tablet. When that's all up, I can start the Sonos app and control \nthe speakers.\n\n### Challenge #2: Multicast Service Discovery \n\nMulticast packets aren't normally forwarded by routers (in this case, the RaspberryPi VPN server) which \nmeans that by default, the discovery packets arriving at your VPN server will be dropped and never make it \ninto your home network to find your sonos speakers.\n\nThis is solved with these two steps:\n\n* incrementing the multicast packet TTL so it can be forwarded into the home network\n* installing a multicast router on the VPN server to do the forwarding\n\nAn 'iptables' rule (in the 'mangle' table) is installed to increment the packet TTL. If you were to install\nthe rule manually, the command would look something like this:\n\n    iptables -t mangle -A POSTROUTING -o eth0 -j TTL --ttl-inc 1\n\nThe ansible scripts install the multicast router 'pimd' on the vpn server to forward the packets. \nIt works with the default installation and configuration.\n\nThese two steps are handled automatically by the ansible setup.\n\n### Challenge #3: Return Traffic to App Host's VPN IP Address\n\nIt appears that the multicast service discovery protocol being used sends the IP address and port of \nthe device running the app as part of the packet payload. This means the speakers always want to talk \nback to the app on it's actual VPN IP address.\n\nThere are two consequences of this:\n\n* can't have NAT anywhere between the app and the speakers\n* the speakers need to be able to route traffic back to the VPN network\n\nThere are a number of ways to make this work and they are things you will need to do manually. The approach\ndocumented below uses static routes on your ISP provided router.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparlaynu%2Fsonos-over-vpn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparlaynu%2Fsonos-over-vpn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparlaynu%2Fsonos-over-vpn/lists"}