Question
To finish out the lab, you are going to write a script that gathers a bunch of the important network settings in one place. As
To finish out the lab, you are going to write a script that gathers a bunch of the important network settings in one place. As you saw earlier, the network information is scattered across a rather large number of commands and files, and it would be very convenient to have a script that outputs all of the important information together. Write a scripted named get_network_info.sh that will report the following: current IPv4 address, MAC address, gateway router, DNS servers, DNS domain, NIC speed, and NIC duplex. In addition, the script must output whether or not the IPv4 address is a dynamic address or static address. To do all of this, you will need to run many of the commands we used at the beginning of the lab and use our standard tools like grep and awk to only list the specific details we want. The script should assume that you are gathering the information for the enp0s3 NIC. Here is a sample run:
[user@user lab7]$ sudo ./get_network_info.sh
dynamic IPv4 address: 10.0.2.15
MAC address: 08:00:27:B2:23:6D
Gateway router: 10.0.2.2
DNS server: 10.8.150.76
DNS server: 10.8.150.75
DNS domain: wit.private
DNS domain: comp3100
NIC speed: 1000Mb/s
NIC duplex: Full
[user@user lab7]$
Here are a few other notes to help get you going. Note that you need to run it with sudo to keep ethtool from complaining. First, you should figure out how to get each individual piece of information on the command line directly before putting anything in your script. In each case, you will run some command we used earlier in the lab, then grep for a specific line of output, and finally use awk to get out only the values you want from the line. Be sure your script will work no matter what the system is (that is, some systems have longer or shorter IP addresses).
Finally, for both the DNS server and DNS domain entries you might have more than one value. Your script should print out each value separately (as in the example above). To do this, you can use a very simple for..in loop to loop through each value and print them out separately. Note that you must look at the search line in /etc/resolv.conf to get all of the domains rather than the domain line.
Again, you should determine how to find each value on the command line directly to make sure you get it right, and only then copy it in to the script. Remember this is a bash script to be ran in CentOS 7.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started