Sometimes we are on connections that have a dynamic ip. This will add your current external ip to
Each time the script is run, it will
dig an OpenDNS resolver to grab your external ip. If it is different from what is in
~/.external-ip it will echo the new ip. Otherwise it will return nothing.
#!/bin/sh # Check external IP for change # Ideal for use in a cron job # # Usage: sh check-ext-ip.sh # # Returns: Nothing if the IP is same, or the new IP address # First run always returns current address # # Requires dig: # Debian/Ubuntu: apt install dnsutils # Solus: eopkg install bind-utils # CentOS/Fedora: yum install bind-utils # # by Sina Cutie <email@example.com> # Released under CC0 # Where we will store the external IP EXT_IP="$HOME/.external-ip" # Check if dig is installed if [ "$(command -v dig)" = "" ]; then echo "This script requires 'dig' to run" # Load distribution release information . /etc/os-release # Check for supported release; set proper package manager and package name if [ "$ID" = "debian" ] || [ "$ID" = "ubuntu" ]; then MGR="apt" PKG="dnsutils" elif [ "$ID" = "fedora" ] || [ "$ID" = "centos" ]; then MGR="yum" PKG="bind-utils" elif [ "$ID" = "solus" ]; then MGR="eopkg" PKG="bind-utils" else echo "Please consult your package manager for the correct package" exit 1 fi # Will run if one of the above supported distributions was found echo "Installing $PKG ..." sudo "$MGR" install "$PKG" fi # We check our external IP directly from a DNS request GET_IP="$(dig +short myip.opendns.com @resolver1.opendns.com)" # Check if ~/.external-ip exists if [ -f "$EXT_IP" ]; then # If the external ip is the same as the current ip if [ "$(cat "$EXT_IP")" = "$GET_IP" ]; then exit 0 fi # If it doesn't exist or is not the same, grab and save the current IP else echo "$GET_IP" > "$EXT_IP" fi
Solus comes with Samba installed by default, as I am sure some other distributions do too. Last time I dealt with Samba, I wanted to gouge my eyes out, it was so complicatedly awful. This time, however, it was extremely simple by comparison.
If you're new to the command line, please remember that the dollar sign (
$) is not part of the command. It denotes that I'm running as a regular user. (Root console has a hash mark (
#) instead, on most default setups.)
First thing I needed to do was copy
$ sudo cp /usr/share/defaults/samba/smb.conf /etc/samba/smb.conf
Originally, I had tried to create my Samba password before doing that, but it tossed a ton of errors. I ended up doing that as the last step.
Since I don't want Samba user to be the same as mine, I decided to use a different name. That user must also exist as a Linux user, so we have to first add that:
$ sudo useradd -s /sbin/nologin -m share
The command above creates the user "share" with a default home directory of
/home/share and no shell, since it doesn't need to be able to log in via SSH.
Now we'll edit
/etc/samba/smb.conf to include the location to our shared folder. I recommend adding this to the end of the file, though I added mine after the
comment = Share Folder
path = /home/share
browsable = yes
read only = no
Since this is temporary and I plan on removing these things later, I did not bother commenting out the Printer section, which I usually do. I don't own a printer and there's no reason for it to try and share one. You can if you want; it's your configuration file, after all.
testparm to make sure that there were no typoes. It checks the
smb.conf for any errors:
```text $ sudo testparm Load smb config files from /usr/share/defaults/samba/smb.conf rlimitmax: increasing rlimitmax (10000) to minimum Windows limit (16384) Processing section "[homes]" Processing section "[homes]" Processing section "[share]" Loaded services file OK. Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions ```
If there are no errors, it should look similar to what's above. You can either press "enter" or "ctrl+c" — either is up to you.
Since everything is working as intended, we'll finally add the Samba password with
smbpasswd before restarting Samba:
$ sudo smbpasswd -a share
New SMB password:
Retype new SMB password:
Added user share.
If all goes well, it should look like the above. Let's restart Samba, then test on a Windows computer:
$ sudo systemctl restart smb
Note: In Solus, the Samba daemon we went to restart is
smb, but the name might vary between distributions.
On the Windows machine, I visited my computer by opening the file explorer and typing
\\REMEDIOS in the address box, then pressed "enter." I was presented with the folder "share", and was able to log in with the username
share and the password I set!
This is a very basic Samba setup, so I encourage you to check out the SambaWiki for more info.