How To: Create a Linux Script to display DNS and IP Address Information
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How To: Create a Linux Script to display DNS and IP Address Information
So I have been playing with Linux consistently for a couple of months now. I've been a Windows sys. admin for most of my career, so Linux is pretty strange for me. I started off with computers way back with the TRS-80 and then eventually moved to DOS systems. So the command line interface (CLI) of Linux was not completely alien to me, yet my lack of knowledge on the syntax and commands is holding me back. I have come a long way.
Recently I needed to play around with some DNS settings and one of the commands I used frequently in Windows, IPCONFIG /ALL, doesn't have a direct relative that displayed the same information. If you run ifconfig, it doesn't return the DNS servers you are currently using. You have to run a separate command to retrieve that information.
What I have done is created a super simple script that displays the network information for my primary LAN adapter, which is ETH0 in my case. After that, it shows the domain and name server information. Then it pauses for 20 seconds before closing the terminal window.
Here are the contents of the script file:
ifconfig -a eth0
cat /etc/resolv.conf
sleep 20
I simply right-clicked the Linux desktop, choose Create Document, Empty File. I named it something like Network Info. Then I opened it and put this information in it, saved it, and closed it. I renamed the file and added a .sh extension to the end which makes it into a script file. Next, right-click the script and go to properties. In the Permissions tab, check the box next to Execute: Allow executing file as a program. Then click close.
To run the script, just double-click the icon and then click Run In Terminal at the prompt. The terminal window opens, displays the information, and exits after 20 seconds. If you need it longer than that or need a different interface (such as wlan0 for your wireless), you can change or even add that in.
This was all done in Ubuntu 10.10.
I know it is very simple and very straight forward and welcome thoughts and feedback about simpler ways to do this. For me, the old-school Windows admin, it's a baby step in the right direction. I am really enjoying learning the Linux OS.
Cheers!
Why don't you execute your script on the commandline?
Note: I'm a Windows-admin as well, but I would be lost without my Linux-laptop in a network where I can check many things from the commandline in a short amount of time.
When I write batchfiles for a Windows-server, I do it on a Linux-computer since here I have the powerful tools to get my work done.
About your script: it will not work in most cases! it depends on the Windowmanagers configuration (which options with rightclick you have).
Sorry, but that's nuts. Last week someone else posted a similar 'ipconfig replacement' script, and as above... Why?? Just learn linux properly, and don't try to lie to yourself.
I'd also suggest that ipconfig is a stupid command in itself, a arbitrary assortment of slightly related data, with a few noddy actions tagged on for luck.
Last edited by acid_kewpie; 01-05-2011 at 04:02 PM.
Thanks for the feedback and the links. Like I said, I am just getting to learn it. As I have time at work, I have been playing around and using it on my laptop. I haven't read any books or gone through any courses, but I do plan to learn it "properly". Just finding the time is hard right now. I think switching from Windows to Linux is akin to learning a foreign language. Take the word house for example. In Engligh, it's house. In Spanish, it is casa. If I were speaking Spanish, I wouldn't think what is the translated word for house and then speak it. I would just say casa, because it is a casa, not a house. Clear as mud I know, but I do understand what you mean by learn it properly.
In the meantime though, if I want to keep using Linux and getting used to the UI and all of that, I'll have to look things up online and find good reference to get information in a pinch. Sometimes scripts like that, though not very efficient, at least get me the information I need in a quick moment. It lets me keep myself in Linux rather that running to a Window box to get that same info. Would you guys rather I didn't try at all? Markus, I definitely want to get to the point where you are now. I manage an organization that has more than 20 locations in 8 states - all Windows based. I know the power that Linux has, especially with networking, hence my desire to learn. Thanks again for the comments guys. I'll keep learning, I promise.
Dave
Ubuntu is fine and will teach you plenty. Also more likely to find Ubuntu in enterprise compared to Slackware. Personal preference doesn't equate to good advice always.
I don't intend to say that Ubuntu is not a good distribution.
Quote:
Originally Posted by acid_kewpie
... Personal preference doesn't equate to good advice always.
Well, personal preference maybe, but when I compare the knowledge of the people here in the forums I see that the most of the Slackware-users seem to have more the ability to understand their systems than Ubuntu-users do. I know that this is partially due to the fact that many newbies try Ubuntu as their first distribution, but I've also read the threads about Slackware-user's occupations and how they came to Slackware (the links in my post). And so I feel that Slackware is more suitable when it comes to learn the basics of Linux.
Quote:
more likely to find Ubuntu in enterprise compared to Slackware
you're right. But my experience is that I can easily transfer my Slackware-knowledge to other distributions which often is very helpful.
You hit the nail on the head with your language analogy. You are just at that stage where you are still thinking Enlgish(windows) and trying to translate in your head to speak Spainish(Linux). As you well know, that does not work very well. Give it some time and practice and you will be thinking in Linux, after that life becomes much simpler. As far as the script goes, good job. Most new users never learn to write scripts at all.
If you are serious about eventually being in a Linux business environment you may(after six months or so) want to switch to one of the distros that a significant number of businesses run. People will probably scream about this, but RHEL(Red Hat Enterprise Linux) is pretty much the gold standard of the Linux business class. Unfortunately RHEL charges a subscription fee for support and access to updates. Fortunately Centos is RHEL with the proprietary bits(mostly logos) stripped out. It is free to install and update. With a five year plus support life you will not have to reinstall every year(like a lot of other distros). Any book, hardware, software, or information in gerneral about RHEL applies equally well to Centos.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.