nin: The Interactive nmcli Script

This, is a love story. About two months ago, I embarked on a small adventure. Getting familiar with nmcli, I was smitten. We spent late nights together, we talked for hours, we even shared our most private addresses secrets. But then things took a turn. I started to find hanging out quite tedious. Having to go through the same sequences over and over just made me ache. Things had to change. We’d still see each other, but it just wouldn’t be the same.


In all seriousness, I was getting tired of having to type in the full length of commands every single time. I decided to write a script that would prompt for all the usual suspects when using nmcli like addresses, gateway, and dns, then set those things for me. I didn’t intend the script to be so large but I was determined to get it right.

I started with configuring a static IP, since it seemed to be the simplest task to overcome. Prompt me for the interface I want to configure, the address, prefix length, the gateway IP and a DNS address, then set those values and reload the interface. It was pretty straightforward and used a whole 22 lines without the author information and extra newlines for legibility. This was version 0.1 . I had a goal in mind for the 1.0 release, but this was far from ready for that goal.

In version 0.2, I implemented the choice of using dynamic addressing. One would think it’d be simple to do this, but my script more than doubled in size. This, I would attribute, to organization and if statements everywhere. You could be prompted for the choice of static or dynamic, but now you could also pass an argument. This would eliminate a single prompt.

0.3 added a “usage” argument that you could pass to get the syntax of nin.

0.4 was a release that was kind of important. This was the first version that included IP validation accross the board. Initially, it only checked the format but not the values, so you could put values above 255.255.255.255, but I figured for something that wasn’t for production use, this could work for now. This was fixed in 0.5 and logging was added.

0.6 is when I changed the name of the script from nmcli-basic to nin. I didn’t particularly like the first name I gave the script. It was ugly and was basically just the name of the tool I was using, with -basic tacked on. I fielded some better names and settled on nin. nin stands for “nin is nmcli” and I found this to be very apt. Along with the name change, I did some UX prettification and did some spring cleaning of the behind the scenes stuff.

And here we are, a month after 0.6, at version 1.0. With this milestone, nin introduces IPv6 compatibility. You can use DHCP or SLAAC if you wish, and even change the address generation type (eui64 or pseudorandom for privacy/security). I’m so excited to be able to present you all with this script, and I hope that you, the reader, will find it useful.

You can download the script from here or use the following commands to download and make it executable:

wget https://bnolet.me/brandon/nin/raw/branch/master/nin.sh
chmod +x nin.sh

The script itself it written solely in bash so provided you have a bash-compatible shell, you shouldn’t have any issues. Depending on your distro, you might have to run it with sudo or root, but please peruse the script before you do so. I want you to know exactly what the script does before you run it with root privileges, so you can feel safe. I am not responsible to any damage you do with my script, whether or not you modified it.

For the future, there are some plans. I want to minimize the amount of code used in this, as it’s a little inefficient. I want to get this as a “package” on an official distro repo. I have some other plans, but I’ll refrain from indulging in my narcissism.


My blog is self-hosted on a VPS running Ubuntu nested in Digital Ocean’s VPS service. If you want to get a VPS from Digital Ocean, I’d like to ask you to graciously use this referral link: https://m.do.co/c/fa082b6466bf . You’ll get $10 in free credit and once you’ve spent $25 of your own money, I’ll receive $25 myself, meaning that you’ll be indirectly supporting my blog.

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.