this post was submitted on 26 Nov 2023
2 points (100.0% liked)

Self-Hosted Main

21 readers
1 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

For Example

We welcome posts that include suggestions for good self-hosted alternatives to popular online services, how they are better, or how they give back control of your data. Also include hints and tips for less technical readers.

Useful Lists

founded 1 year ago
MODERATORS
 

Hi, when I am at home I don't need Wireguard, while when I go out of the house I would like it to turn on.

In summary by passing the mac address of my iPhone to the script, it is checked if it is present in the ARP table and if it is connected to the LAN by scanning with nmap. If I don't find it connected, I starto Wireguard. If it is connected, however, I turn it off.

I was planning to schedule it with crontab every 15 minutes.

Do you see any potential security issues with that? Could it be done better?

network=192.168.1.0/24
if [ “$#” -ne 1 ]; then echo Usage example: $0 aa:bb:cc:dd:ee:ff; exit 2; fi;
nmap -sP -T4 $network >& /dev/null
ip=$(sudo arp -n | grep $1 | awk ‘ { print $1 }’)
ping $ip -n -q -c 2 -i 0.2 -w 1 >& /dev/null
if [ $? -eq 0 ]; then
   echo Device is online \($ip\)
   sudo wg-quick down wg0
   echo Wireguard killed
else
   echo Device is offline
   sudo wg-quick up wg0
   echo Wireguard started
   exit 1
fi;
top 4 comments
sorted by: hot top controversial new old
[–] BunnyEruption@alien.top 2 points 1 year ago (1 children)

What's the point of this? If you don't think wireguard is secure enough to leave running 24/7 I'm not sure only running it some number of hours a day is going to be much more secure?

[–] subven1@alien.top 1 points 1 year ago

Some people turn off their router at night or when they leave home. Does it make sense? Not really. Can you still do it? Of course...

[–] ElevenNotes@alien.top 2 points 1 year ago

Funny idea but I see no point in it?

[–] sidusnare@alien.top 1 points 1 year ago

I'd use a state file, test for state change, and only run wg-quick on change. This way you can run every minute, and avoid weirdness about running up when already up or down when down.