How To Create a Script, Alias To Run A Command Similar To IPCONFIG /ALL On Linux

When power windows users come over to Linux they are often looking for a command similar to ipconfig /all on Linux. Unfortantly I am not aware of a complete replacement one comamnad to occomplish this. You can use the ifconfig command to view your IP address or cat /etc/resulve to view DNS names. I how ever came a cross a script that could accompish this but seemed to only work on Ubuntu. I customized it a little to make it work on more then just Ubuntu such as CentOS, Debian, Fedora..etc.

In this tutorial we will create a script to return similar information to ipconfig /all and then create a alais to allow you to easy launch the script in one command.



Microsoft Windows IPCONFIG /ALL Example




Creating The Script:

Open up your favorite text editor such as gedit, Vim, Nano, Emacs..etc. In this example we will use gedit to keep it simple.

Paste the following code in your editor


#! /bin/bash
echo Gateway" "Interface
/sbin/route -n | awk '/UG/ {printf "%-21s %s\n",$2,$8}'
echo DNS Servers
awk '/nameserver/ {print $2}' /etc/resolv.conf



Paste the code above into Gedit or other text editor



Before we save the file were going to want to put it in a place that we won't forget what it is and delete it at a later time. I am going to create a folder called scripts and put it in my home dir.



Create a folder to store you script



Now we are going to want to save the script as shell script with the extension .sh. In this example I am going to call it but you can name it what ever you want, just make sure you adjust the steps later to reflect your changes. If you want to share this with other users on your system I would recommend saving it in a shared directory such as in a sub folder in /opt or /usr.



Save script in your new created folder



We will need to make one more change to the file. We will want to make it executable. Below you will find two examples on setting the fle executable one in the gui and the other in the terminal.


Setting the file executable in the gui:

To keep things simple you can set the file execurable in the GUI (Graphic User Interface).

Navigate to your new file right click on it and select Properties.



Right Click and Select Properties



Select the Permissions tab.



Permission Tab



Put a check mark in the Allow executing file as program.



Check Excute Option




Setting the file executable in the terminal:

Run the follwing command:

chmod a+x ~/scripts/






Creating The Alias:

Now that we have the script created we can create an alias, so every time we want to run it we don't have to type in the full path. (example: /home/eric/scripts/ In this example we are going to set it in the local .bashrc file. This setting will be held just for the user. You could also set this in the global setting for all users.

Navigate to your home folder.



Navigate to your home folder cd ~



Hit Ctrl + H to show hidden files and folders.



Hidden Folders > locate .bashrc



Open up the file .bashrc in your favorite text editor.

Add the following line of code at the end of the file. Make sure you change the path to your location.

alias ipconfig='/home/eric/scripts/'



Add alias settings to .bashrc



Now just save the file, logout and back in for the changes to take effect.

Once you have logged back in, open up a terminal and type ipconfig in your terminal.



issue ipconfig



Hope you found this helpful!