<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.ihitc.net/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=KreidKolo</id>
	<title>ITCwiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.ihitc.net/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=KreidKolo"/>
	<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/w/Special:Contributions/KreidKolo"/>
	<updated>2026-04-07T08:46:54Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.38.5</generator>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9585</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9585"/>
		<updated>2021-03-19T19:45:35Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Checking Your Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will be introduced to the following commands:&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
* You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
: [[File:Bind_named_conf.png | 500px]]&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
* Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
: [[File:Nslookup_inverhillsedu.png | 500px]]&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial - Adding an AAAA Record]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial - Adding a Delegated Domain]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial - Manually Editing a Zone File]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Checking Your Work==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Check the directories and files:&amp;lt;/li&amp;gt;&lt;br /&gt;
# &amp;lt;code&amp;gt;/etc/bind/named.conf.options&amp;lt;/code&amp;gt; should have the ip address 172.17.139.11 saved.&lt;br /&gt;
# &amp;lt;code&amp;gt;/etc/network/interfaces&amp;lt;/code&amp;gt; should have the ip address 127.0.0.1 saved.&lt;br /&gt;
# Your &amp;lt;code&amp;gt;/var/lib/bind/*.hosts&amp;lt;/code&amp;gt; file should have a MX, CNAME, and AAAA record.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Automatically check your results by running this command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/mnjk-inver/Linux-2480-Rebuild/main/lab_08_test.py | python3&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9584</id>
		<title>Lab 4 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9584"/>
		<updated>2021-03-19T19:40:16Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Checking your Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Linux is a very text file-oriented operating system. As we&#039;ve learned most of the settings for the operating system are held in text files in the /etc directory and most of the commands that are used to manipulate the system take text input or give text output. Beause of this it&#039;s very important to be able to edit and manipulate text on the system which will be a key focus of this lab. In addition, we&#039;ll practice creating compressed files, which is useful for backing up files, and creating links between locations on the system.&lt;br /&gt;
&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
* Edit text files using nano and vi&lt;br /&gt;
* Learn how to manipulate command output&lt;br /&gt;
* Search for files&lt;br /&gt;
* Archive and Compress files using tar&lt;br /&gt;
* Create links between directories&lt;br /&gt;
&lt;br /&gt;
You will be introduced to the following commands:&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/vi vi]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nano nano]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/less less]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/find find]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/locate locate]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/updatedb updatedb]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ln ln]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
==Prerequisites==&lt;br /&gt;
Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
==Text File Editing==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=LnVsTA8_mQo Video Tutorial - Text File Editing]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change to the &#039;&#039;/var/www/html&#039;&#039; directory which is where the Apache webserver stores it&#039;s site files by default.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Verify you can see an &#039;&#039;index.html&#039;&#039; file inside of this directory by listing the contents of the directory. Note who the &#039;&#039;owner&#039;&#039; and &#039;&#039;group owner&#039;&#039; of the file are.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Open up a web browser on your host computer and verify that you can browse to the IP address of your Linux system and still see the &amp;quot;It works&amp;quot; page that you saw in [[Franske ITC-2480 Lab 2#Install the Apache 2 Webserver|lab 2]] after installing Apache.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Before we start making any changes it&#039;s a good idea to save an unmodified copy of the file you&#039;ll be working on so make a copy of the &#039;&#039;index.html&#039;&#039; file and name the copy &#039;&#039;index.html.orig&#039;&#039; so that you can always copy it back if you make a mistake.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are many different text editors available for Linux but systems almost always include some version of &#039;&#039;&#039;vi&#039;&#039;&#039; or &#039;&#039;&#039;nano&#039;&#039;&#039; so those are the two we&#039;ll focus on.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; In your ssh window open the &#039;&#039;index.html&#039;&#039; file in nano.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;NOTE: Because your user does not own this file you may need to edit the file as the superuser.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nano index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:nano_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/d/d3/Nano_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:nano_index_html.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try navigating around the file with your arrow keys and changing the &amp;quot;Apache2 Debian Default Page&amp;quot; text at the top of the page to &amp;quot;Welcome to My Linux Webserver&amp;quot;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Basic instructions for using nano abound on the Internet. You can get a basic introduction [http://staffwww.fullcoll.edu/sedwards/Nano/IntroToNano.html here] but it basically comes down to the menu lines at the bottom of the screen showing what your options are. The ^ character is commonly used to indicate the CTRL key so to exit the program (you will be prompted to save changes if you have made any) press CTRL-X or to save without exiting press CTRL-O and follow the prompts at the bottom of the screen.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Save your file with the changed text and then reload the page in your browser on your host system to see if the changes have taken effect.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Experiment with some of the nano menu options such as cutting and &amp;quot;un-cutting&amp;quot; lines of text and searching/replacing text. Once you are comfortable with the nano editor save your changes and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Make a note of which user and group owns your &#039;&#039;index.html&#039;&#039; file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete your &#039;&#039;index.html&#039;&#039; file and copy your &#039;&#039;index.html.orig&#039;&#039; file back to &#039;&#039;index.html&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Try loading the website again and see if it&#039;s back to the original text. If you encounter an error it&#039;s possible that your &#039;&#039;index.html&#039;&#039; file is not readable by the webserver account so you should use the appropriate command to set the &#039;&#039;index.html&#039;&#039; file back to the owner and group of the original file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now open the &#039;&#039;index.html&#039;&#039; file in vi&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; vi index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[File:vi_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/f/fd/Vi_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[Media:vi_index_html.png| Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; The vi editor is probably considered more powerful than nano but is less user friendly without the menu at the bottom and a COMMAND mode as well as an INSERT mode. In the COMMAND mode you cannot directly change the text of the file by typing which can be frustrating to new users. Read through the vi tutorial [http://www.washington.edu/computing/unix/vi.html here] and try making some edits to your webpage. Once you are familiar with how the vi editor works save your file and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Command Output Manipulation==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dgC1r0rXTpA Video Tutorial - Command Output Manipulation]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change back to your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cd ~&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Print out the files in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run &#039;&#039;&#039;ls -al&#039;&#039;&#039; but redirect the output to a file using &#039;&#039;&amp;gt; filename&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al &amp;gt; listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how there is no command output. This is normal as you redirected the command output to the file &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; verify the contents of &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cat listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:cat_listfiles_txt.png|link=https://wiki.ihitc.net/mediawiki/images/e/e1/Cat_listfiles_txt.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:cat_listfiles_txt.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how it contains the exact same output as running &#039;&#039;&#039;ls -al&#039;&#039;&#039; on the command line.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ls -al /var/log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how many files there are in the &#039;&#039;/var/log&#039;&#039; directory. Lets say we wanted to just know the information of the &#039;&#039;debug&#039;&#039; log files. For this, we would use a pipe and the grep command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So, now run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep debug&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:var_log_grep_debug.png|link=https://wiki.ihitc.net/mediawiki/images/7/74/Var_log_grep_debug.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:var_log_grep_debug.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how the output is limited to all files that contain the string &#039;&#039;debug&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; TIP: Grep is very powerful. Here we&#039;re just using it to search for a string but you can use it to search regular expressions as well. We mentioned these in a previous lab too. You can learn more about regular expressions at [https://regexone.com RegexOne] and [https://www.regular-expressions.info Regular-Expressions.info] among many other places. These are frequently used in system administration and programming so it&#039;s worth your while to get at least a basic understanding of them.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Whats nice about pipes and redirects is that they can be used back to back on a command line creating a chain of programs which accept data as standard input and output it to the next program as standard output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So lets say we have a scenario where we want to get a file that contains all of the information from all &#039;&#039;.gz&#039;&#039; files in &#039;&#039;/var/log&#039;&#039;. To do this, we would run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep .gz &amp;gt; gzlogfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now pipe the file into &#039;&#039;&#039;less&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;cat gzlogfiles.txt | less&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; NOTE: Remember that you are now viewing the file in the less program and will need to quite the program to return to a command line. Type the letter &amp;quot;q&amp;quot; to quit the less program.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; In this case the piped &#039;&#039;&#039;cat&#039;&#039;&#039; command is the exact same as running &#039;&#039;&#039;less gzlogfiles.txt&#039;&#039;&#039; however there are many times where you need to connect two programs together with pipes in order to accomplish something which is otherwise not possible. Also, standard output can be non-text data as well. For example, it&#039;s possible to use pipes to pass audio data between programs such as one that scans a WAV file and adjusts the volume before piping it to an MP3 compression utility which saves the result as an MP3 file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; See if you can figure out how to view the output of &#039;&#039;&#039;ls -al /var/log | grep .gz&#039;&#039;&#039; one page at a time without dumping it to a text file first.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now remove the files &#039;&#039;gzlogfiles.txt&#039;&#039; and &#039;&#039;listfiles.txt&#039;&#039; that were created from this part of the lab.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for Files in Linux==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=WSd6fq-jDyE Video Tutorial - Searching for Files in Linux]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
There are several ways to search for files on a Linux system. The simplest is to use the &#039;&#039;&#039;find&#039;&#039;&#039; command which searches through the system directory by directory for files which match your search string. You can specify many options for the find command which do things such as restrict to searching in one particular directory and it&#039;s sub-directories, etc.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try searching your entire drive for files with syslog in the name. &lt;br /&gt;
    &amp;lt;code&amp;gt; find / -name syslog 2&amp;gt; /dev/null&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:find_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/9/96/Find_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:find_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice the &#039;&#039;2&amp;gt; /dev/null&#039;&#039; on the end of the command. This redirects error messages ( &#039;&#039;2&amp;gt;&#039;&#039; redirected stderr, &#039;&#039;&amp;gt;&#039;&#039; redirects stdout as discussed above) to the location &#039;&#039;/dev/null&#039;&#039; which is non-existing location/file where bits are just dropped from the system. The reason we&#039;re redirecting the error messages is that there are a number of files or directories which you may not have permission to access. Each attempt to access these by the &#039;&#039;&#039;find&#039;&#039;&#039; program would create an error message (so lots of errors). We&#039;re basically telling the system to hide these error messages from us.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see some files identified which contain the name &#039;&#039;syslog&#039;&#039;. The problem is that the find command is very slow at moving through all the files on the system, in fact it may even appear to be frozen while searching slowly though the drive. If you have waited a while and are still not getting back to a command prompt you can press CTRL-C to force the find program to quit and return to a command prompt. This means the find program works just fine for searching through a few directories/files (such as your home directory might contain) but is not the best choice for searching the entire system. If you want to learn more about advanced uses of the find command take a look at [http://content.hccfl.edu/pollock/unix/findcmd.htm this tutorial].&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; A faster way to search the entire system is to use the &#039;&#039;locate&#039;&#039; command. Install the &#039;&#039;&#039;locate&#039;&#039;&#039; program&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;This command searches a pre-built database of all files on the system which means it operates much faster than searching though files one at a time. There are two downsides to locate. First, it may not be pre-installed on many Linux systems so you may have to install it. Second, you need to build or update the database before you can search for files. New files are not automatically updated to the database so this only really works if you periodically remember to update the database. We&#039;ll explain how you can schedule that automatically in the future (hint, see the &#039;&#039;&#039;cron&#039;&#039;&#039; program).&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; sudo apt-get install locate&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create an updated database of files on your system&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;sudo updatedb&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Note, it will take a while for this program to find and index all the files on your system so give it a while to run. The advantage is after you do this you can search the database for many different files very quickly instead of waiting for each search as with the find command. We need to run the &#039;&#039;&#039;updatedb&#039;&#039;&#039; program as an administrator so that it can search though all locations on the system, including ones your user does not normally have access to.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note: Programs that may need to run for a long time and do not require user input (like &#039;&#039;&#039;updatedb&#039;&#039;&#039;) can be run in the background by placing an ampersand at the end of the command line like &#039;&#039;&#039;sudo updatedb&amp;amp;&#039;&#039;&#039;. This will immediately return you to a command prompt so you can continue to work on other things while the command finishes running.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Search for files with &#039;&#039;syslog&#039;&#039; in the name again but now using the command &#039;&#039;locate&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; locate syslog&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:locate_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/1/17/Locate_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:locate_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see many files found with this name and it should happen quickly, much faster than with the find command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating Archived/Compressed Files==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=iBsHKvNP88E Video Tutorial - Creating Archived Compressed Files]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding why &#039;&#039;&#039;tar&#039;&#039;&#039; is functioning in a certain way you can find a number of introductory tutorials [http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ like this one] about using &#039;&#039;&#039;tar&#039;&#039;&#039; on the Internet by [https://www.google.com/#q=tar+tutorial searching for them]&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a new directory &#039;&#039;experiments&#039;&#039; in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup1.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory by first changing your working directory to &#039;&#039;/var/log&#039;&#039; and then using the command:&amp;lt;/li&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup1.tar.gz *&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the asterisk (*) which is used to select all files in the current directory for inclusion in the TAR file. This is a type of wildcard character.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change your working directory to the &#039;&#039;experiments&#039;&#039; directory in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory. What happened? What kind of mess could this make when you extract a TAR file when it was created this way?&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try again to create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup2.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory. By running the command from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf logbackup2.tar.gz /var/log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the lack of a slash at the end of the directory we are putting into the TAR file. In some older versions of TAR putting a slash on the end meant to put the files from that directory into the file but not the directory itself (just like when we created logbackup1.tar.gz with the asterisk wildcard). By leaving the slash off the end we are telling TAR to put the log directory,as well as it&#039;s contents, into the TAR file so that when we extract it we will get a log directory made with the files going into it. Even though new versions of TAR automatically prevent you from creating TAR files without a directory path it is still best practice to make sure that you are including a directory as part of the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; What happened? If you extracted a tar file made this way you could potentially end up with several more levels of directories than you really want. In this case we got an extra var directory inside of experiments but if we were archiving something with a deeper path we would have even more extra subdirectories. You can actually see this during the tar file creation if you have verbose output enabled you saw that all the files being added to the tar had var/log/ in front of the filename. There are at least two ways to handle this which we will look at.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If we are creating the TAR file manually we can avoid these extra parts to the path by paying attention to what directory we are in when we create the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; This time change your working directory to &#039;&#039;/var&#039;&#039; first and then run the command.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf ~/experiments/logbackup3.tar.gz log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the different output from the tar command. This time the filenames are prefixed only by &#039;&#039;log/&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup3.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should see that there is just one new subdirectory called log and all of the files are neatly placed inside of it. This is the type of extraction people normally want and expect from a tar file that is distributed.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Empty your &#039;&#039;experiments&#039;&#039; directory&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; If you want to have the same effect without changing your working directory that is possible too. Try running the command below.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup4.tar.gz -C /var log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;This time it doesn&#039;t make any difference which directory on the system because we have again specified a full path for where to save the tar file and we have also told tar to change to the &#039;&#039;/var&#039;&#039; directory before adding the log directory to the file using the -C argument. This automates the process of manually changing directories like we did above.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup4.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should again see that there is just one new subdirectory called &#039;&#039;log&#039;&#039; and all of the files are neatly placed inside of it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are a number of other things you can do with &#039;&#039;&#039;tar&#039;&#039;&#039; such as creating slower but more highly compressed .bz2 bzip files, extracting single files (or directories or groups of files) from an archive, listing the contents of an archive without extracting (which can show you if a new subdirectory will be created), adding files to an existing archive, and preserving file ownership (only by extracting on the same system though) and permissions. You should read the manual page for tar and then try practicing some of these and be familiar with the many ways that &#039;&#039;&#039;tar&#039;&#039;&#039; can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Working With Filesystem Links==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=vBorZKMmvIk Video Tutorial - Working With Filesystem Links]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding how links are functioning in a certain way you can find a number of introductory tutorials [http://www.nixtutor.com/freebsd/understanding-symbolic-links/ like this one] or [http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/ more advanced tutorials] on the Internet by searching for them.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Use root privileges to create a new directory inside the &#039;&#039;var&#039;&#039; directory called &#039;&#039;system-documentation&#039;&#039; and change the ownership permissions so that your standard user has permission to read, write, and execute as a member of a group which owns the documentation directory. You will also need to make sure that all system users have execute permission for the parent directory (&#039;&#039;/var&#039;&#039;) in order to access anything in it including the &#039;&#039;system-documentation&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Instead of needing to go into the &#039;&#039;/var/-system-documentation&#039;&#039; directory all the time it would be more convenient if your user was able to reach that directory through a link in their own home directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Run the command below inside your regular user&#039;s home directory&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ln -s /var/system-documentation documentation&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:ln_documentation.png|link=https://wiki.ihitc.net/mediawiki/images/9/97/Ln_documentation.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:ln_documentation.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Or if you&#039;re in a different working directory you can run the command as &#039;&#039;&#039;ln -s /var/system-documentation ~/documentation&#039;&#039;&#039; Do you understand why?&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should now see a soft link (also called symlink) in your home directory called documentation which points to the &#039;&#039;/var/system-documentation&#039;&#039; folder.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &#039;&#039;&#039;cd&#039;&#039;&#039; into the link just like it was a real directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you use the &#039;&#039;&#039;pwd&#039;&#039;&#039; command to print your working directory while inside the link it will look like it&#039;s a directory. Almost all software on the system will interact with the link just as if it&#039;s a real directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try creating some files and subdirectories inside of the link and then verify they are showing up in the real &#039;&#039;/var/system-documentation&#039;&#039; location as well. This should work correctly if your permissions are all set correctly.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Remove the link&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;rm ~/documentation&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see that all of the files you created are still in &#039;&#039;/var/system-documentation&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you re-create the link you should be able to go back into &#039;&#039;~/documentation&#039;&#039; and remove files and directories and see they are removed from the actual &#039;&#039;/var/system-documentation&#039;&#039; directory as well&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You can also practice creating links to specific files as well as directories. Links do not override permissions so you need to have permission to read, write or execute the file or directory you are linking to just like if you actually changed to the real location of the item. Go ahead and practice creating and removing links until you have a good understanding of how links can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Note: If you are using &#039;&#039;&#039;tar&#039;&#039;&#039; to back up data, depending on exactly what you want to do you may want to use the &#039;&#039;-h&#039;&#039; or &#039;&#039;--dereference&#039;&#039; option which will follow the symlink and backup the data it contains. Normal behavior for tar would just be to back up the link itslef, not the file(s) pointed to by the link. You should try creating some tar files of directories which contain symlinks, deleting the data the symlink points to and the extracting the tar file to some new location to see this in action if you are not confident that you understand this.&lt;br /&gt;
&lt;br /&gt;
=Checking your Work=&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; You should have the following directories and files:&amp;lt;/li&amp;gt;&lt;br /&gt;
# ~/documentation&lt;br /&gt;
# ~/experiments&lt;br /&gt;
# /var/www/html/index.html&lt;br /&gt;
&amp;lt;li&amp;gt; Use the following command to see if locate is installed:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; dpkg -s locate&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Automatically check your results by running this command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
curl https://raw.githubusercontent.com/mnjk-inver/Linux-2480-Rebuild/main/lab_04_test.py | python3&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_10_mnjk&amp;diff=9546</id>
		<title>Lab 10 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_10_mnjk&amp;diff=9546"/>
		<updated>2021-03-02T01:37:26Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Checking your Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dQw4w9WgXcQ Watch the video introduction]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This lab assumes you have successfully set up [[Lab_8_mnjk#Install_BIND_.26_Enable_Caching | DNS]] and [[Lab_9_mnjk#Install_the_Postfix_MTA |email]].  If you had any issues with those labs, you should resolve them before attempting this lab, since you will be unable to properly test the tasks in this lab if those are not fully functional.&lt;br /&gt;
&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Configuring a [https://firewalld.org/ Firewall]&lt;br /&gt;
*Enabling a 2nd interface&lt;br /&gt;
*Configuring [https://en.wikipedia.org/wiki/Network_address_translation NAT]&lt;br /&gt;
*Setting up [https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol DHCP]&lt;br /&gt;
*Installing [https://linuxmint.com/ Linux Mint] on a second VM&lt;br /&gt;
*Enabling [https://en.wikipedia.org/wiki/Port_forwarding Port Forwarding]&lt;br /&gt;
&lt;br /&gt;
You will be introduced to the following commands:&lt;br /&gt;
*&#039;&#039;&#039;[https://firewalld.org/documentation/man-pages/firewall-cmd.html firewall-cmd]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/echo echo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/ifconfig ifconfig]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software.&lt;br /&gt;
# Login with your standard user account.&lt;br /&gt;
# Have a browser window set to the webmin interface for your linux VM.&lt;br /&gt;
&lt;br /&gt;
== Configure a Firewall ==&lt;br /&gt;
&#039;&#039;NOTE: It is suggested that instead of managing a firewall directly  using nftables tools (which would also require us to create a script to reload our rules each time the system is restarted) we use a firewall daemon program to manage it based on a set of rules we create and automatically setup the firewall based on those rules each time the system boots. There are many command line firewall management programs out there but for this lab we will use the [https://firewalld.org/ firewalld] package suggested by Debian. &#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Begin by installing the &#039;&#039;firewalld&#039;&#039; package on your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First, let&#039;s check to see if the firewall is now up and running using the following command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --state&amp;lt;/code&amp;gt;&lt;br /&gt;
: The firewall has been pre-configured with a couple of rules in it to prevent us from getting locked out. &lt;br /&gt;
: [[File:Lab10_firewalld_state.png | link=https://wiki.ihitc.net/mediawiki/images/1/11/Lab10_firewalld_state.png|500px]]&lt;br /&gt;
: [[Media:Lab10_firewalld_state.png | Click for larger image]]&lt;br /&gt;
&amp;lt;li&amp;gt;Let&#039;s see what those rules are by using this command: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --list-all&amp;lt;/code&amp;gt;&lt;br /&gt;
: [[File:Lab10_firewalld_initial_rules.png | link=https://wiki.ihitc.net/mediawiki/images/1/14/Lab10_firewalld_initial_rules.png|500px]]&lt;br /&gt;
: [[Media:Lab10_firewalld_initial_rules.png | Click for larger image]]&lt;br /&gt;
: By default all interfaces are in the public zone (this is set in the &#039;&#039;/etc/firewalld/firewalld.conf&#039;&#039; file). &lt;br /&gt;
: Before we start working on rules for our firewall we should assign our outside interface to the external zone which is designed for NAT routing which we&#039;ll be setting up shortly. &lt;br /&gt;
&amp;lt;li&amp;gt; We can do this with the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --zone=external --add-interface=ens192&amp;lt;/code&amp;gt;&lt;br /&gt;
: We can create custom zones or use pre-defined security zones which will speed up configuring the firewall. Learn more about the [https://firewalld.org/documentation/zone/predefined-zones.html pre-defined zones in firewalld documentation].&lt;br /&gt;
&amp;lt;li&amp;gt;Since we have changed zones on our interface let&#039;s check and see what rules we have started with. Let&#039;s see what those rules are:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --zone=external --list-all&amp;lt;/code&amp;gt;&lt;br /&gt;
: &#039;&#039;NOTE: You can also use the &#039;&#039;&#039;firewall-cmd --list-all-zones&#039;&#039;&#039; command to see a list of all available zones and their rules.&amp;lt;/li&amp;gt;&#039;&#039;&lt;br /&gt;
: If you were watching carefully you may have noted that the dhcpv6-client service which was allowed in the public zone but is not allowed by default on the external zone. &lt;br /&gt;
&amp;lt;li&amp;gt;In our case we want to allow DHCPv6 to operate on our outside interface so we can re-enable it with the following command: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; firewall-cmd --zone=external --add-service=&amp;quot;dhcpv6-client&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Check to see what other services can be allowed on an interface with:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --get-services&amp;lt;/code&amp;gt;&lt;br /&gt;
: If you check you will see that although you can connect with ssh (by default it&#039;s on the allowed service list you saw above) you can&#039;t connect to your webserver or Webmin anymore. Webmin is not a pre-defined service in the list we saw above so we could either set it up as a new service and then allow it or we could create a manual rule to allow the TCP traffic on port 10000 needed to access Webmin. In this case because the service only uses a single port and to see how manual rules can be created let&#039;s manually create a rule to allow access to TCP port 10000. &lt;br /&gt;
&amp;lt;li&amp;gt;Do this by running this command: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --zone=external --add-port=10000/tcp &amp;lt;/code&amp;gt;&lt;br /&gt;
:You should now be able to access Webmin again.&lt;br /&gt;
&amp;lt;li&amp;gt; Using either service rules or manual port rules create additional rules so that the other services on your VM are again accessible from the outside (such as from your home PC over the VPN). &amp;lt;/li&amp;gt;&lt;br /&gt;
:&#039;&#039;HINT: Services we have setup so far include SSH, DNS, SMTP, IMAP, Samba, and HTTP.&#039;&#039;&lt;br /&gt;
: Make sure to test and ensure they are all working again!&lt;br /&gt;
&amp;lt;li&amp;gt; Once you are satisfied your firewall is running correctly you can use the following command to set these rules to automatically load each time the system is started.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; firewall-cmd --runtime-to-permanent &amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setup a 2nd NIC Interface ==&lt;br /&gt;
To start this lab we will need to configure a second network interface, named ens224 on our virtual machines. In our simulated setup our existing ens192 interface will be our WAN interface and ens224 will be our LAN interface which could be connected to a switch and then to multiple allow other computers which will connect to the Internet through our server.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open &#039;&#039;/etc/network/interfaces&#039;&#039; with your favorite text editor. &amp;lt;/li&amp;gt;&lt;br /&gt;
* Go to the bottom of the file.&lt;br /&gt;
: [[File:Lab10_network_interfaces_before.png | link=https://wiki.ihitc.net/mediawiki/images/f/f8/Lab10_network_interfaces_before.png|500px]]&lt;br /&gt;
: [[Media:Lab10_network_interfaces_before.png | Click for larger image]]&lt;br /&gt;
* Add the following to configure the second interface with a static IP of 192.168.1.1/24:&lt;br /&gt;
&amp;lt;pre&amp;gt;auto ens224&lt;br /&gt;
iface ens224 inet static&lt;br /&gt;
	address 192.168.1.1&lt;br /&gt;
	netmask 255.255.255.0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: [[File:Lab10_network_interfaces_after.png | link=https://wiki.ihitc.net/mediawiki/images/8/80/Lab10_network_interfaces_after.png|500px]]&lt;br /&gt;
: [[Media:Lab10_network_interfaces_after.png | Click for larger image]]&lt;br /&gt;
: &#039;&#039;NOTE: As this is a LAN only interface, we do not need to define a gateway for the server VM, as the server VM itself will be the gateway for this network.&#039;&#039;&lt;br /&gt;
&amp;lt;li&amp;gt;Once this is done, save the file &lt;br /&gt;
&amp;lt;li&amp;gt; Run the following command to enable the new interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;ifup ens224&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Verify the second interface is up and running with the correct IP address&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enable Routing ==&lt;br /&gt;
Now we will need to enable NAT so we can route LAN traffic to the Internet and responding Internet traffic back to our LAN interface.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In your console, you will need to edit &#039;&#039;/etc/sysctl.conf&#039;&#039;. This file is used to change and tweak multiple system variables. &amp;lt;/li&amp;gt;&lt;br /&gt;
* Scroll down until you find the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;# Uncomment the next line to enable packet forwarding for IPv4&lt;br /&gt;
#net.ipv4.ip_forward=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Follow the instructions in the file to enable packet forwarding in the kernel. &lt;br /&gt;
: [[File:Lab10_sysctl_after.png | link=https://wiki.ihitc.net/mediawiki/images/1/1e/Lab10_sysctl_after.png|500px]]&lt;br /&gt;
: [[Media:Lab10_sysctl_after.png | Click for larger image]]&lt;br /&gt;
* When you are done, save the file.&lt;br /&gt;
: Changes to the &#039;&#039;sysctl.conf&#039;&#039; file require a reboot, but most can be set without a reboot by echoing response codes to &amp;quot;files&amp;quot; in &#039;&#039;/proc&#039;&#039;. &lt;br /&gt;
&amp;lt;li&amp;gt; We will get into that more in a later chapter, but for now run the following command to enable ip_forwarding without rebooting the machine: &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&#039;&#039;&#039;echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward&amp;lt;/code&amp;gt;&lt;br /&gt;
: &#039;&#039;NOTE: If you are receiving an error when trying to run that command it&#039;s likely that the user you are running it as does not have permission to modify the &#039;&#039;&#039;/proc/sys/net/ipv4/ip_forward&#039;&#039;&#039; file (check the permissions by using &#039;&#039;&#039;ls&#039;&#039;&#039;). Read [http://stackoverflow.com/questions/82256/how-do-i-use-sudo-to-redirect-output-to-a-location-i-dont-have-permission-to-wr this similar question] for more details and possible solutions.&#039;&#039;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setup a DHCP Server ==&lt;br /&gt;
To setup a DHCP server, we will first need to install the required software. &lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In your SSH console use your favorite package manager to install the &#039;&#039;isc-dhcp-server&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
: After you install the package you may get a warning about &#039;&#039;isc-dhcp-server&#039;&#039; being unable to start. This is normal as we have yet to define the interface and settings we want used.&lt;br /&gt;
&amp;lt;li&amp;gt;Now back in Webmin, select the Refresh Modules option. .&amp;lt;/li&amp;gt;&lt;br /&gt;
* After it is done, go to Servers, then DHCP Server&lt;br /&gt;
: Before we define our DHCP range, we need to set our listening interface. &lt;br /&gt;
* Click on the &#039;&#039;Edit Network Interface&#039;&#039; option. &lt;br /&gt;
*Select &#039;&#039;ens224&#039;&#039;. &lt;br /&gt;
* Press save.&lt;br /&gt;
&amp;lt;li&amp;gt;Now under Subnets and Shared Networks, select Add a new subnet. &amp;lt;/li&amp;gt;&lt;br /&gt;
* Use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Subnet description: LAN DHCP Range&lt;br /&gt;
Network Address: 192.168.1.0&lt;br /&gt;
Netmask: 255.255.255.0&lt;br /&gt;
Address Ranges: 192.168.1.100-192.168.1.254&amp;lt;/pre&amp;gt;&lt;br /&gt;
: [[File:Lab10_webmin_dhcp_create_subnet.png | link=https://wiki.ihitc.net/mediawiki/images/4/4e/Lab10_webmin_dhcp_create_subnet.png|500px]]&lt;br /&gt;
: [[Media:Lab10_webmin_dhcp_create_subnet.png | Click for larger image]]&lt;br /&gt;
* When you are done, press Create. &lt;br /&gt;
* Now, click on the network you just created to review the settings, then press Edit Client Options at the bottom.&lt;br /&gt;
: From here we will setup the default gateway and DNS servers for the clients to use. &lt;br /&gt;
&amp;lt;li&amp;gt; Under Default Routers, set the option to 192.168.1.1 &lt;br /&gt;
* Under DNS servers, set it to 192.168.1.1. &lt;br /&gt;
: [[File:Lab10_webmin_dhcp_client_options.png | link=https://wiki.ihitc.net/mediawiki/images/d/d7/Lab10_webmin_dhcp_client_options.png|500px]]&lt;br /&gt;
: [[Media:Lab10_webmin_dhcp_client_options.png | Click for larger image]]&lt;br /&gt;
: Notice how we are setting these options to the IP of ens224 that we setup. This is because our Linux VM will act as the router and DNS for our clients as well.&lt;br /&gt;
* When you are done, press save&lt;br /&gt;
* Then on the Edit Subnet page, press save again.&lt;br /&gt;
&amp;lt;li&amp;gt;Now that you are back on the DHCP server page, press the Start Server button. &lt;br /&gt;
: If all goes well, the button should change to &amp;quot;Stop Server&amp;quot;. If this does not happen, then the server was unable start. If that happens, re-check your DHCP server configurations to make sure everything is correct.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enabling NAT and Firewall Rules for the LAN ==&lt;br /&gt;
Now we will use firewalld to setup NAT so that we can use private addresses on our internal LAN but still have access to the public Internet. &lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First, let&#039;s set our ens224 interface (LAN) to be in the internal zone with the following command.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --zone=internal --add-interface=ens224&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You should now take a minute to allow all of the same services and ports on the internal network that you have allowed on the external network. &amp;lt;/li&amp;gt;&lt;br /&gt;
:In other words, make sure that Webmin, Samba, DNS, etc. are also allowed on the internal zone.&lt;br /&gt;
:In order to activate NAT you need to turn on the &amp;quot;masquerade&amp;quot; feature on your outside interface. This is probably already done if you correctly assigned your outside interface to the pre-defined external zone (it&#039;s one of the features of that zone). &lt;br /&gt;
: &#039;&#039;HINT: you can do this manually as well in case you setup a custom zone by running the &#039;&#039;&#039;firewall-cmd --add-masquerade --zone=external&#039;&#039;&#039; command.&#039;&#039;&lt;br /&gt;
: While routing and NAT should be working for hosts on your LAN interface now they probably still can&#039;t get an IP address! Just like all the other services being blocked by the firewall DHCP is also blocked unless you specifically allow it. &lt;br /&gt;
&amp;lt;li&amp;gt;To do this run the following command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --add-service=dhcp --zone=internal&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once you are satisfied your firewall is running correctly you can use this command to set these rules to automatically load each time the system is started.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --runtime-to-permanent&amp;lt;/code&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setup a 2nd VM as a LAN Host ==&lt;br /&gt;
Now we are going to setup a 2nd VM on the VMware server so we can have a client to connect to the LAN network segment we just created. For this though, we will be using Linux Mint instead of Debian so we have a graphical user interface to help us with testing.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; You&#039;ll need to make a Netlab reservation to work with your Mint system&#039;s GUI so go ahead and do that. &amp;lt;/li&amp;gt;&lt;br /&gt;
* Enter the lab on Netlab&lt;br /&gt;
* Click the &amp;quot;Linux Desktop&amp;quot; tab to access your Mint machine.&lt;br /&gt;
: The VM should be booting from a Linux Mint virtual CD image. &lt;br /&gt;
&amp;lt;li&amp;gt; Get Linux Mint installed using the link on the desktop.&amp;lt;/li&amp;gt;&lt;br /&gt;
: Installation settings are not critical as we&#039;ll be using the system primarily to explore a Linux GUI and to test web browsing capability from our private network.&lt;br /&gt;
: [[File:Lab10_linux_mint_desktop.png | link=https://wiki.ihitc.net/mediawiki/images/f/f1/Lab10_linux_mint_desktop.png|500px]]&lt;br /&gt;
: [[Media:Lab10_linux_mint_desktop.png | Click for larger image]]&lt;br /&gt;
: &#039;&#039;NOTE: By default Linux Mint will boot into a &amp;quot;Live CD&amp;quot; environment where you can use the system without installing. However, the Live CD environment is much slower and memory limited compared with a full installation to the hard drive so be sure to start an installation and reboot into the installed copy instead of from the Live CD. You will know you&#039;re working from an installed copy if you are prompted for your username and password when logging in and don&#039;t see a link on the desktop to Install Linux Mint anymore.&#039;&#039;&lt;br /&gt;
&amp;lt;li&amp;gt; Once you have Linux Mint installed, reboot the machine and login. &amp;lt;/li&amp;gt;&lt;br /&gt;
: Hopefully the machine is able to connect to the Internet through your Debian server which is acting as a DHCP server and router (see the topology diagram tab in Netlab to see a diagram of how they are connected).&lt;br /&gt;
&amp;lt;li&amp;gt; Press the Menu icon in the lower left corner, and enter &amp;quot;Terminal&amp;quot;. &amp;lt;/li&amp;gt;&lt;br /&gt;
* Then, open the terminal application.&lt;br /&gt;
&amp;lt;li&amp;gt; You now have a shell on the system. From here, use the following command to check your network settings. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt;&lt;br /&gt;
: Notice how you have a IP from the DHCP pool we created earlier. &lt;br /&gt;
&amp;lt;li&amp;gt; Now try pinging &#039;&#039;172.17.50.1&#039;&#039;. &amp;lt;/li&amp;gt;&lt;br /&gt;
: Are you able to ping? If so, NAT is working properly on your network because the 172.17.50.0/24 network is outside of the LAN segment this machine is attached to (192.168.1.0/24).&lt;br /&gt;
: &#039;&#039;NOTE: Notice how some Linux distributions like Mint haven&#039;t switched from the old naming of network interfaces with &#039;&#039;eth&#039;&#039; to the new &#039;&#039;ens&#039;&#039; style. You can also try using the older &#039;&#039;&#039;ifconfig&#039;&#039;&#039; way of checking the IP address and compare the output to the new &#039;&#039;&#039;ip address show&#039;&#039;&#039; method which we have been using so far in Debian.&#039;&#039;&lt;br /&gt;
&amp;lt;li&amp;gt; Now run &#039;&#039;&#039;ping google.com&#039;&#039;&#039;. &amp;lt;/li&amp;gt;&lt;br /&gt;
: If you are able to ping, this shows that not only is NAT working, but DNS resolving as well.&lt;br /&gt;
&amp;lt;li&amp;gt; Open a web browser on the system (you can use a graphical browser this time since you have a GUI) and test browsing to a few websites.&amp;lt;/li&amp;gt;&lt;br /&gt;
: At this point we have a fully functional LAN environment.&lt;br /&gt;
&amp;lt;li&amp;gt; In order to allow automatic safe shutdown of your Linux Mint system and improve speed/efficiency use the package manager to install the &#039;&#039;open-vm-tools-desktop&#039;&#039; package. &amp;lt;/li&amp;gt;&lt;br /&gt;
:This provides better drivers and integration between the vmWare host which is running your Linux Mint virtual machine and the virtual machine itself.&lt;br /&gt;
&amp;lt;li&amp;gt; Finally, in the next section we&#039;ll be setting up SSH access to Mint through the Firewall so you&#039;ll want to install the &#039;&#039;openssh-server package&#039;&#039; through the package manager. &amp;lt;/li&amp;gt;&lt;br /&gt;
: Once you&#039;ve done this you should be able to use the ssh program on the command line in Debian to access your Mint system like &#039;&#039;&#039;ssh mintusername@192.168.1.x&#039;&#039;&#039; where you are using a valid username on the Mint system and the IP address of the Mint system.&lt;br /&gt;
&amp;lt;li&amp;gt; Spend a few more minutes exploring the functionality of the Linux GUI and desktop.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding and Firewalling ==&lt;br /&gt;
Now we are going to enable port forwarding to our VM. This will allow you to access the 2nd VM from the ITC network and VPN.&lt;br /&gt;
Because we are already using port 22 on our outside interface to provide SSH access to our main Debian system we need to use a different port to access the Mint system. Instead of changing the port number in the SSH server software on Mint we can have our firewall do it at the same time the NAT masquerading is occurring. &lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Set up a rule by running the following command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --add-forward-port=port=2222:proto=tcp:toport=22:toaddr=192.168.1.100 --zone=external&amp;lt;/code&amp;gt;&lt;br /&gt;
:NOTE: this rule is a little unstable because it forwards the port to 192.168.1.100 which is currently the IP of our Mint system (if yours has a different IP you should change it in the command) but because that system gets an IP from DHCP it is subject to change which would break the rule. Therefore, if we wanted this to be stable in the long term, we would want to set up a static IP on any machines we were forwarding ports to.&lt;br /&gt;
:&#039;&#039;HINT: If your connection is refused, it may be because SSH is not installed in Mint.  Try installing SSH using the package manager or apt.&#039;&#039;&lt;br /&gt;
&amp;lt;li&amp;gt; From a computer on the ITC network, such as one connected to the VPN, try to SSH to port 2222 on the outside (172.17.50.xx) IP address of your Debian system. &amp;lt;/li&amp;gt;&lt;br /&gt;
:If everything was set up successfully, you should be able to sign into the Mint VM based on the port forwarding rule we have put in place.&lt;br /&gt;
&amp;lt;li&amp;gt; Once you are satisfied your firewall is running correctly you can use the following command to set these rules to automatically load each time the system is started.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;firewall-cmd --runtime-to-permanent&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
When you are done testing this section of the lab please power off your new Linux Mint VM as these require far more resources to run than the Debian VMs on our servers.&amp;lt;br&amp;gt;&lt;br /&gt;
: [[File:Lab10_linux_mint_shutdown.png | link=https://wiki.ihitc.net/mediawiki/images/1/1c/Lab10_linux_mint_shutdown.png|500px]]&lt;br /&gt;
: [[Media:Lab10_linux_mint_shutdown.png | Click for larger image]]&lt;br /&gt;
&lt;br /&gt;
=Checking your Work=&lt;br /&gt;
For this lab there are many things you need to check.&lt;br /&gt;
&lt;br /&gt;
#Firewall - attempt to connect using FTP on port 21, this should fail&lt;br /&gt;
#SSH - connect using FTP on port 22&lt;br /&gt;
#DNS - navigate to url of server&lt;br /&gt;
#SMTP - send a mail to auto-respond server&lt;br /&gt;
#IMAP - receive a mail from auto-respond server&lt;br /&gt;
#Samba - Create a file on server using file sharing&lt;br /&gt;
#HTTP - Navigate to ip address of server&lt;br /&gt;
#Webmin - Navigate to &amp;lt;your-ip&amp;gt;:10000&lt;br /&gt;
#PuTTY into linux mint using your ip address and port 2222&lt;br /&gt;
#Linux Mint DNS/NAT - ping google.com from within Linux Mint&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Run this script to automatically check your lab&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; curl https://raw.githubusercontent.com/mnjk-inver/Linux-2480-Rebuild/main/lab_10_test.py | sudo python3 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt; curl https://raw.githubusercontent.com/mnjk-inver/Linux-2480-Rebuild/main/lab_10_test.py | sudo python3 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9515</id>
		<title>Lab 4 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9515"/>
		<updated>2021-02-19T20:54:27Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Creating Archived/Compressed Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Linux is a very text file-oriented operating system. As we&#039;ve learned most of the settings for the operating system are held in text files in the /etc directory and most of the commands that are used to manipulate the system take text input or give text output. Beause of this it&#039;s very important to be able to edit and manipulate text on the system which will be a key focus of this lab. In addition, we&#039;ll practice creating compressed files, which is useful for backing up files, and creating links between locations on the system.&lt;br /&gt;
&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
* Edit text files using nano and vi&lt;br /&gt;
* Learn how to manipulate command output&lt;br /&gt;
* Search for files&lt;br /&gt;
* Archive and Compress files using tar&lt;br /&gt;
* Create links between directories&lt;br /&gt;
&lt;br /&gt;
You will be introduced to the following commands:&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/vi vi]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nano nano]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/less less]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/find find]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/locate locate]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/updatedb updatedb]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ln ln]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
==Prerequisites==&lt;br /&gt;
Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
==Text File Editing==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=LnVsTA8_mQo Video Tutorial - Text File Editing]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change to the &#039;&#039;/var/www/html&#039;&#039; directory which is where the Apache webserver stores it&#039;s site files by default.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Verify you can see an &#039;&#039;index.html&#039;&#039; file inside of this directory by listing the contents of the directory. Note who the &#039;&#039;owner&#039;&#039; and &#039;&#039;group owner&#039;&#039; of the file are.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Open up a web browser on your host computer and verify that you can browse to the IP address of your Linux system and still see the &amp;quot;It works&amp;quot; page that you saw in [[Franske ITC-2480 Lab 2#Install the Apache 2 Webserver|lab 2]] after installing Apache.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Before we start making any changes it&#039;s a good idea to save an unmodified copy of the file you&#039;ll be working on so make a copy of the &#039;&#039;index.html&#039;&#039; file and name the copy &#039;&#039;index.html.orig&#039;&#039; so that you can always copy it back if you make a mistake.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are many different text editors available for Linux but systems almost always include some version of &#039;&#039;&#039;vi&#039;&#039;&#039; or &#039;&#039;&#039;nano&#039;&#039;&#039; so those are the two we&#039;ll focus on.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; In your ssh window open the &#039;&#039;index.html&#039;&#039; file in nano.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;NOTE: Because your user does not own this file you may need to edit the file as the superuser.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nano index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:nano_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/d/d3/Nano_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:nano_index_html.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try navigating around the file with your arrow keys and changing the &amp;quot;Apache2 Debian Default Page&amp;quot; text at the top of the page to &amp;quot;Welcome to My Linux Webserver&amp;quot;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Basic instructions for using nano abound on the Internet. You can get a basic introduction [http://staffwww.fullcoll.edu/sedwards/Nano/IntroToNano.html here] but it basically comes down to the menu lines at the bottom of the screen showing what your options are. The ^ character is commonly used to indicate the CTRL key so to exit the program (you will be prompted to save changes if you have made any) press CTRL-X or to save without exiting press CTRL-O and follow the prompts at the bottom of the screen.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Save your file with the changed text and then reload the page in your browser on your host system to see if the changes have taken effect.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Experiment with some of the nano menu options such as cutting and &amp;quot;un-cutting&amp;quot; lines of text and searching/replacing text. Once you are comfortable with the nano editor save your changes and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Make a note of which user and group owns your &#039;&#039;index.html&#039;&#039; file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete your &#039;&#039;index.html&#039;&#039; file and copy your &#039;&#039;index.html.orig&#039;&#039; file back to &#039;&#039;index.html&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Try loading the website again and see if it&#039;s back to the original text. If you encounter an error it&#039;s possible that your &#039;&#039;index.html&#039;&#039; file is not readable by the webserver account so you should use the appropriate command to set the &#039;&#039;index.html&#039;&#039; file back to the owner and group of the original file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now open the &#039;&#039;index.html&#039;&#039; file in vi&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; vi index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[File:vi_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/f/fd/Vi_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[Media:vi_index_html.png| Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; The vi editor is probably considered more powerful than nano but is less user friendly without the menu at the bottom and a COMMAND mode as well as an INSERT mode. In the COMMAND mode you cannot directly change the text of the file by typing which can be frustrating to new users. Read through the vi tutorial [http://www.washington.edu/computing/unix/vi.html here] and try making some edits to your webpage. Once you are familiar with how the vi editor works save your file and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Command Output Manipulation==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dgC1r0rXTpA Video Tutorial - Command Output Manipulation]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change back to your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cd ~&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Print out the files in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run &#039;&#039;&#039;ls -al&#039;&#039;&#039; but redirect the output to a file using &#039;&#039;&amp;gt; filename&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al &amp;gt; listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how there is no command output. This is normal as you redirected the command output to the file &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; verify the contents of &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cat listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:cat_listfiles_txt.png|link=https://wiki.ihitc.net/mediawiki/images/e/e1/Cat_listfiles_txt.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:cat_listfiles_txt.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how it contains the exact same output as running &#039;&#039;&#039;ls -al&#039;&#039;&#039; on the command line.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ls -al /var/log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how many files there are in the &#039;&#039;/var/log&#039;&#039; directory. Lets say we wanted to just know the information of the &#039;&#039;debug&#039;&#039; log files. For this, we would use a pipe and the grep command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So, now run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep debug&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:var_log_grep_debug.png|link=https://wiki.ihitc.net/mediawiki/images/7/74/Var_log_grep_debug.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:var_log_grep_debug.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how the output is limited to all files that contain the string &#039;&#039;debug&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; TIP: Grep is very powerful. Here we&#039;re just using it to search for a string but you can use it to search regular expressions as well. We mentioned these in a previous lab too. You can learn more about regular expressions at [https://regexone.com RegexOne] and [https://www.regular-expressions.info Regular-Expressions.info] among many other places. These are frequently used in system administration and programming so it&#039;s worth your while to get at least a basic understanding of them.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Whats nice about pipes and redirects is that they can be used back to back on a command line creating a chain of programs which accept data as standard input and output it to the next program as standard output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So lets say we have a scenario where we want to get a file that contains all of the information from all &#039;&#039;.gz&#039;&#039; files in &#039;&#039;/var/log&#039;&#039;. To do this, we would run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep .gz &amp;gt; gzlogfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now pipe the file into &#039;&#039;&#039;less&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;cat gzlogfiles.txt | less&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; NOTE: Remember that you are now viewing the file in the less program and will need to quite the program to return to a command line. Type the letter &amp;quot;q&amp;quot; to quit the less program.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; In this case the piped &#039;&#039;&#039;cat&#039;&#039;&#039; command is the exact same as running &#039;&#039;&#039;less gzlogfiles.txt&#039;&#039;&#039; however there are many times where you need to connect two programs together with pipes in order to accomplish something which is otherwise not possible. Also, standard output can be non-text data as well. For example, it&#039;s possible to use pipes to pass audio data between programs such as one that scans a WAV file and adjusts the volume before piping it to an MP3 compression utility which saves the result as an MP3 file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; See if you can figure out how to view the output of &#039;&#039;&#039;ls -al /var/log | grep .gz&#039;&#039;&#039; one page at a time without dumping it to a text file first.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now remove the files &#039;&#039;gzlogfiles.txt&#039;&#039; and &#039;&#039;listfiles.txt&#039;&#039; that were created from this part of the lab.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for Files in Linux==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=WSd6fq-jDyE Video Tutorial - Searching for Files in Linux]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
There are several ways to search for files on a Linux system. The simplest is to use the &#039;&#039;&#039;find&#039;&#039;&#039; command which searches through the system directory by directory for files which match your search string. You can specify many options for the find command which do things such as restrict to searching in one particular directory and it&#039;s sub-directories, etc.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try searching your entire drive for files with syslog in the name. &lt;br /&gt;
    &amp;lt;code&amp;gt; find / -name syslog 2&amp;gt; /dev/null&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:find_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/9/96/Find_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:find_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice the &#039;&#039;2&amp;gt; /dev/null&#039;&#039; on the end of the command. This redirects error messages ( &#039;&#039;2&amp;gt;&#039;&#039; redirected stderr, &#039;&#039;&amp;gt;&#039;&#039; redirects stdout as discussed above) to the location &#039;&#039;/dev/null&#039;&#039; which is non-existing location/file where bits are just dropped from the system. The reason we&#039;re redirecting the error messages is that there are a number of files or directories which you may not have permission to access. Each attempt to access these by the &#039;&#039;&#039;find&#039;&#039;&#039; program would create an error message (so lots of errors). We&#039;re basically telling the system to hide these error messages from us.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see some files identified which contain the name &#039;&#039;syslog&#039;&#039;. The problem is that the find command is very slow at moving through all the files on the system, in fact it may even appear to be frozen while searching slowly though the drive. If you have waited a while and are still not getting back to a command prompt you can press CTRL-C to force the find program to quit and return to a command prompt. This means the find program works just fine for searching through a few directories/files (such as your home directory might contain) but is not the best choice for searching the entire system. If you want to learn more about advanced uses of the find command take a look at [http://content.hccfl.edu/pollock/unix/findcmd.htm this tutorial].&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; A faster way to search the entire system is to use the &#039;&#039;locate&#039;&#039; command. Install the &#039;&#039;&#039;locate&#039;&#039;&#039; program&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;This command searches a pre-built database of all files on the system which means it operates much faster than searching though files one at a time. There are two downsides to locate. First, it may not be pre-installed on many Linux systems so you may have to install it. Second, you need to build or update the database before you can search for files. New files are not automatically updated to the database so this only really works if you periodically remember to update the database. We&#039;ll explain how you can schedule that automatically in the future (hint, see the &#039;&#039;&#039;cron&#039;&#039;&#039; program).&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; sudo apt-get install locate&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create an updated database of files on your system&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;sudo updatedb&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Note, it will take a while for this program to find and index all the files on your system so give it a while to run. The advantage is after you do this you can search the database for many different files very quickly instead of waiting for each search as with the find command. We need to run the &#039;&#039;&#039;updatedb&#039;&#039;&#039; program as an administrator so that it can search though all locations on the system, including ones your user does not normally have access to.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note: Programs that may need to run for a long time and do not require user input (like &#039;&#039;&#039;updatedb&#039;&#039;&#039;) can be run in the background by placing an ampersand at the end of the command line like &#039;&#039;&#039;sudo updatedb&amp;amp;&#039;&#039;&#039;. This will immediately return you to a command prompt so you can continue to work on other things while the command finishes running.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Search for files with &#039;&#039;syslog&#039;&#039; in the name again but now using the command &#039;&#039;locate&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; locate syslog&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:locate_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/1/17/Locate_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:locate_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see many files found with this name and it should happen quickly, much faster than with the find command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating Archived/Compressed Files==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=iBsHKvNP88E Video Tutorial - Creating Archived Compressed Files]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding why &#039;&#039;&#039;tar&#039;&#039;&#039; is functioning in a certain way you can find a number of introductory tutorials [http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ like this one] about using &#039;&#039;&#039;tar&#039;&#039;&#039; on the Internet by [https://www.google.com/#q=tar+tutorial searching for them]&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a new directory &#039;&#039;experiments&#039;&#039; in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup1.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory by first changing your working directory to &#039;&#039;/var/log&#039;&#039; and then using the command:&amp;lt;/li&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup1.tar.gz *&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the asterisk (*) which is used to select all files in the current directory for inclusion in the TAR file. This is a type of wildcard character.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change your working directory to the &#039;&#039;experiments&#039;&#039; directory in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory. What happened? What kind of mess could this make when you extract a TAR file when it was created this way?&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try again to create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup2.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory. By running the command from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf logbackup2.tar.gz /var/log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the lack of a slash at the end of the directory we are putting into the TAR file. In some older versions of TAR putting a slash on the end meant to put the files from that directory into the file but not the directory itself (just like when we created logbackup1.tar.gz with the asterisk wildcard). By leaving the slash off the end we are telling TAR to put the log directory,as well as it&#039;s contents, into the TAR file so that when we extract it we will get a log directory made with the files going into it. Even though new versions of TAR automatically prevent you from creating TAR files without a directory path it is still best practice to make sure that you are including a directory as part of the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; What happened? If you extracted a tar file made this way you could potentially end up with several more levels of directories than you really want. In this case we got an extra var directory inside of experiments but if we were archiving something with a deeper path we would have even more extra subdirectories. You can actually see this during the tar file creation if you have verbose output enabled you saw that all the files being added to the tar had var/log/ in front of the filename. There are at least two ways to handle this which we will look at.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If we are creating the TAR file manually we can avoid these extra parts to the path by paying attention to what directory we are in when we create the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; This time change your working directory to &#039;&#039;/var&#039;&#039; first and then run the command.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf ~/experiments/logbackup3.tar.gz log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the different output from the tar command. This time the filenames are prefixed only by &#039;&#039;log/&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup3.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should see that there is just one new subdirectory called log and all of the files are neatly placed inside of it. This is the type of extraction people normally want and expect from a tar file that is distributed.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Empty your &#039;&#039;experiments&#039;&#039; directory&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; If you want to have the same effect without changing your working directory that is possible too. Try running the command below.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup4.tar.gz -C /var log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;This time it doesn&#039;t make any difference which directory on the system because we have again specified a full path for where to save the tar file and we have also told tar to change to the &#039;&#039;/var&#039;&#039; directory before adding the log directory to the file using the -C argument. This automates the process of manually changing directories like we did above.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup4.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should again see that there is just one new subdirectory called &#039;&#039;log&#039;&#039; and all of the files are neatly placed inside of it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are a number of other things you can do with &#039;&#039;&#039;tar&#039;&#039;&#039; such as creating slower but more highly compressed .bz2 bzip files, extracting single files (or directories or groups of files) from an archive, listing the contents of an archive without extracting (which can show you if a new subdirectory will be created), adding files to an existing archive, and preserving file ownership (only by extracting on the same system though) and permissions. You should read the manual page for tar and then try practicing some of these and be familiar with the many ways that &#039;&#039;&#039;tar&#039;&#039;&#039; can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Working With Filesystem Links==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=vBorZKMmvIk Video Tutorial - Working With Filesystem Links]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding how links are functioning in a certain way you can find a number of introductory tutorials [http://www.nixtutor.com/freebsd/understanding-symbolic-links/ like this one] or [http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/ more advanced tutorials] on the Internet by searching for them.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Use root privileges to create a new directory inside the &#039;&#039;var&#039;&#039; directory called &#039;&#039;system-documentation&#039;&#039; and change the ownership permissions so that your standard user has permission to read, write, and execute as a member of a group which owns the documentation directory. You will also need to make sure that all system users have execute permission for the parent directory (&#039;&#039;/var&#039;&#039;) in order to access anything in it including the &#039;&#039;system-documentation&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Instead of needing to go into the &#039;&#039;/var/-system-documentation&#039;&#039; directory all the time it would be more convenient if your user was able to reach that directory through a link in their own home directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Run the command below inside your regular user&#039;s home directory&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ln -s /var/system-documentation documentation&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:ln_documentation.png|link=https://wiki.ihitc.net/mediawiki/images/9/97/Ln_documentation.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:ln_documentation.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Or if you&#039;re in a different working directory you can run the command as &#039;&#039;&#039;ln -s /var/system-documentation ~/documentation&#039;&#039;&#039; Do you understand why?&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should now see a soft link (also called symlink) in your home directory called documentation which points to the &#039;&#039;/var/system-documentation&#039;&#039; folder.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &#039;&#039;&#039;cd&#039;&#039;&#039; into the link just like it was a real directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you use the &#039;&#039;&#039;pwd&#039;&#039;&#039; command to print your working directory while inside the link it will look like it&#039;s a directory. Almost all software on the system will interact with the link just as if it&#039;s a real directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try creating some files and subdirectories inside of the link and then verify they are showing up in the real &#039;&#039;/var/system-documentation&#039;&#039; location as well. This should work correctly if your permissions are all set correctly.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Remove the link&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;rm ~/documentation&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see that all of the files you created are still in &#039;&#039;/var/system-documentation&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you re-create the link you should be able to go back into &#039;&#039;~/documentation&#039;&#039; and remove files and directories and see they are removed from the actual &#039;&#039;/var/system-documentation&#039;&#039; directory as well&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You can also practice creating links to specific files as well as directories. Links do not override permissions so you need to have permission to read, write or execute the file or directory you are linking to just like if you actually changed to the real location of the item. Go ahead and practice creating and removing links until you have a good understanding of how links can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Note: If you are using &#039;&#039;&#039;tar&#039;&#039;&#039; to back up data, depending on exactly what you want to do you may want to use the &#039;&#039;-h&#039;&#039; or &#039;&#039;--dereference&#039;&#039; option which will follow the symlink and backup the data it contains. Normal behavior for tar would just be to back up the link itslef, not the file(s) pointed to by the link. You should try creating some tar files of directories which contain symlinks, deleting the data the symlink points to and the extracting the tar file to some new location to see this in action if you are not confident that you understand this.&lt;br /&gt;
&lt;br /&gt;
=Checking your Work=&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Testing your work goes here&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; Commands to use&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Description of what you should see&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Mail_server_mnjk&amp;diff=9506</id>
		<title>Mail server mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Mail_server_mnjk&amp;diff=9506"/>
		<updated>2021-02-19T01:29:37Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* DNS Section */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
:This section documents the creation of the Auto-Reply Mail Server.  This section will likely be created by an instructor or administrator.&lt;br /&gt;
==Mail Server Documentation==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Power on you Virtual machine&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:* This server may reside in the VMware ESXi or NetLab as long as the network configuration allows connection to the course VLAN and student VM&#039;s.&lt;br /&gt;
&amp;lt;li&amp;gt;Install Debian Linux&amp;lt;/li&amp;gt;&lt;br /&gt;
: Once the system has booted and is on the &amp;quot;Debian GNU/Linux installer menu&amp;quot; choose &amp;quot;Install&amp;quot; and &#039;&#039;&#039;not&#039;&#039;&#039; &amp;quot;Graphical Install&amp;quot;. If you make an incorrect choice you can reboot your virtual machine (power off and on) before installing to get back to the menu.&lt;br /&gt;
: In the installer you will use the space bar to select and unselect &amp;quot;checkboxes&amp;quot;, the tab key to move between fields and buttons, and the enter key to continue. You will be prompted for the following choices&lt;br /&gt;
* Select &#039;&#039;English&#039;&#039; as the language, &#039;&#039;United States&#039;&#039; as your location, and &#039;&#039;American English&#039;&#039; as the keymap.&lt;br /&gt;
* Set &#039;&#039;ens192&#039;&#039; as your primary network interface.&lt;br /&gt;
* Set a hostname for the system to 2480 followed by a dash and then your pod ID letter, like &#039;&#039;2480-Z&#039;&#039; for LSA Pod Z. If you have forgotten your pod ID letter look up at the top of your screen above the line with the &amp;quot;Topology&amp;quot; and &amp;quot;Linux Server&amp;quot; tabs and you should see a line with &amp;quot;LSA Pod&amp;quot; followed by a letter, that letter is your pod ID letter.&lt;br /&gt;
:&#039;&#039; Note: These steps are critical to future success in labs, check your spelling carefully&#039;&#039; &lt;br /&gt;
: [[File:Lab1_hostname.png|link=https://wiki.ihitc.net/mediawiki/images/5/57/Lab1_hostname.png|500px]]&lt;br /&gt;
: [[Media:Lab1_hostname.png|Click here for a larger image]]&lt;br /&gt;
* Set the domain name to &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;&lt;br /&gt;
: [[File:Lab1_domainname.png|link=https://wiki.ihitc.net/mediawiki/images/5/5a/Lab1_domainname.png|500px]]&lt;br /&gt;
: [[Media:Lab1_domainname.png|Click here for a larger images]]&lt;br /&gt;
* Set the root password to something you will NOT FORGET, this is the administrator account, &#039;&#039;cisco&#039;&#039; might be a good choice for our purposes though that would not be secure for a system directly accessible from the Internet (we are protected by a firewall which you are bypassing via the VPN connection)&lt;br /&gt;
* Create a new user account by entering your name. The system will automatically use your first name (all lowercase) as the username and then you should set the password to another password you will not forget&lt;br /&gt;
* Select your timezone&lt;br /&gt;
* Choose &amp;quot;Guided - Use entire disk&amp;quot; as the partitioning method and select the &#039;&#039;sda&#039;&#039; drive and &amp;quot;All files in one partition&amp;quot; as the partitioning scheme, &amp;quot;Finish partitioning and write the changes to the disk&amp;quot;, and then finally confirm you want to write the changes.&lt;br /&gt;
* You do not want to scan any other CDs or DVDs at this time.&lt;br /&gt;
* You want to select a mirror located close to you with good speed. Because your VM is actually running from the campus and is connected to the campus Internet connection a good option is &amp;quot;debian.uchicago.edu&amp;quot; with no http proxy.&lt;br /&gt;
* Choose whether you want to participate in the package usage survey, for our purposes either choice is just fine.&lt;br /&gt;
* On the software selection screen UNSELECT &amp;quot;Debian desktop environment&amp;quot; and &amp;quot;Print server&amp;quot; and make sure that &amp;quot;SSH server&amp;quot; and &amp;quot;Standard system utilities&amp;quot; are the only two selected options.&lt;br /&gt;
:&#039;&#039; Note: To select and unselect options move your cursor over the option and press the space bar.&lt;br /&gt;
* Choose that yes you want to install GRUB to the master boot record on the &#039;&#039;/dev/sda&#039;&#039; device.&lt;br /&gt;
&amp;lt;li&amp;gt;Complete the installation&amp;lt;/li&amp;gt;&lt;br /&gt;
: When the installation is complete you can select continue to &amp;quot;eject&amp;quot; the virtual CD and reboot into the new install&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Install Basic Tools==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install &#039;&#039;&#039;sudo&#039;&#039;&#039; from the command line using:&lt;br /&gt;
: &#039;&#039;Note: A good practice is to update your system before installing any packages, this should be completed using &#039;&#039;&#039;apt update&#039;&#039;&#039;, ensure to use &#039;&#039;&#039;sudo&#039;&#039;&#039; when not logged in as root.&lt;br /&gt;
: &amp;lt;code&amp;gt;apt update&amp;lt;/code&amp;gt;&lt;br /&gt;
: &amp;lt;code&amp;gt;apt install sudo&amp;lt;/code&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
: For security purposes it is usually the case that you do not want to log in as the root user. Instead, best practice is to log in as a standard user and then execute specific commands that require root access with administrative privileges through the &#039;&#039;&#039;sudo&#039;&#039;&#039; program. The &#039;&#039;&#039;sudo&#039;&#039;&#039; program is not installed by default so after you have logged in to the root account enter &#039;&#039;&#039;apt update&#039;&#039;&#039; and press enter which will update the list of software available for installation and then &#039;&#039;&#039;apt install sudo&#039;&#039;&#039; and press enter to install the sudo software.&lt;br /&gt;
&amp;lt;li&amp;gt;Add sudo privileges to our standard user account.&lt;br /&gt;
:&amp;lt;code&amp;gt;adduser &amp;lt;username&amp;gt; sudo&amp;lt;/code&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
: We now need to add our standard user account to the group which is allowed to have administrative access to do this enter the command &#039;&#039;&#039;sudo adduser &#039;&#039;&amp;lt;username&amp;gt;&#039;&#039; sudo&#039;&#039;&#039; and press enter, replacing &#039;&#039;&amp;lt;username&amp;gt;&#039;&#039; with the name of your standard user account (set during the setup process, probably your first name in lowercase). We&#039;ll learn more about these commands later in the course.&lt;br /&gt;
&amp;lt;li&amp;gt;Reboot system&amp;lt;/li&amp;gt;&lt;br /&gt;
: &amp;lt;code&amp;gt;shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
: Reboot your system using the &#039;&#039;&#039;shutdown -r now&#039;&#039;&#039; command to apply the changes&lt;br /&gt;
&amp;lt;li&amp;gt;Log in as your standard user account, determine system IP address.&lt;br /&gt;
: Once you are logged in use the following command at the command line to determine the IP address of your system&lt;br /&gt;
:&amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
: Using the &#039;&#039;&#039;ip address show&#039;&#039;&#039; command will allow you to check the IP address of your system. The IP address should be something like &#039;&#039;172.17.50.xxx&#039;&#039; and be an &#039;&#039;inet&#039;&#039; address on the &#039;&#039;ens192&#039;&#039; adapter.&lt;br /&gt;
: [[File:Lab1_ip_address_show2.PNG|500px]]&lt;br /&gt;
&amp;lt;li&amp;gt;Test sudo privileges&amp;lt;/li&amp;gt;&lt;br /&gt;
: Try running the same command as the administrator by typing &#039;&#039;&#039;sudo ip address show&#039;&#039;&#039;, you will need to enter in your password again when you run this command.&lt;br /&gt;
: &amp;lt;code&amp;gt;sudo ip address show&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install &#039;&#039;&#039;open-vm-tools&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
: Run the &#039;&#039;&#039;sudo apt install open-vm-tools&#039;&#039;&#039; command to install the vmWare Tools. You will be prompted about several additional software packages required to be installed, type &#039;&#039;&#039;y&#039;&#039;&#039; and press enter to install the software.&lt;br /&gt;
:&amp;lt;code&amp;gt;sudo apt install open-vm-tools&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install nmap&amp;lt;/li&amp;gt;&lt;br /&gt;
:Nmap is a tool we will learn more about later in the course but it will likely be used to check many of the labs for completion while working through the course.  This course&#039;s labwork often builds upon the work you have done in previous labs.  The self-check scripts are to assist you in ensuring you have not missed any &#039;&#039;critical&#039;&#039; steps in your work that would affect your success in subsequent labs.&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;NOTE: Before we begin the installation of this tool it is important to remember that scanning a system is often seen as an attack against the system and should not be done unless you are the administrator of both the system that you are scanning from and the system you are scanning or have the explicit permission of the system administrator of those systems! In some areas people have been legally charged and prosecuted for scanning of systems which they are not authorized to do. You have been warned!&lt;br /&gt;
:*At this time all you will be doing is installing the tool as it will be used to self-check your lab work to verify you are ready to move on to the next lab.&lt;br /&gt;
:* Run the following command at the command line.&lt;br /&gt;
:&amp;lt;pre&amp;gt;sudo apt install nmap&amp;lt;/pre&amp;gt;&lt;br /&gt;
: Run the &#039;&#039;&#039;sudo apt install nmap&#039;&#039;&#039; command to install the nmap tool. You will be prompted about additional software packages required to be installed, type &#039;&#039;&#039;y&#039;&#039;&#039; and press enter to install the software.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Exit from the local console&amp;lt;/li&amp;gt;&lt;br /&gt;
: To log out of the console type &#039;&#039;&#039;exit&#039;&#039;&#039; and press enter.&lt;br /&gt;
: Because your Debian Linux server is running as a virtual machine on a vmWare host system in order to achieve the best performance and driver integration we should install the vmWare Tools software package in your virtual machine.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Add User &amp;quot;Ping&amp;quot;, Install Webmin==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new user account &#039;&#039;&#039;ping&#039;&#039;&#039; using the &#039;&#039;&#039;adduser&#039;&#039;&#039; program&amp;lt;/li&amp;gt;&lt;br /&gt;
: &amp;lt;code&amp;gt; adduser ping&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use the &#039;&#039;&#039;links&#039;&#039;&#039; browser or &#039;&#039;&#039;wget&#039;&#039;&#039; to download the &#039;&#039;&#039;DEB&#039;&#039;&#039; package file from &#039;&#039;&#039;[https://www.webmin.com www.webmin.com]&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
: &#039;&#039;NOTE: Because this DEB file was downloaded directly instead of automatically by APT from a package repository the installation command is slightly different and some other commands such as &#039;&#039;&#039;apt show&#039;&#039;&#039; will not work.&#039;&#039;&lt;br /&gt;
&amp;lt;li&amp;gt;Install the package with &#039;&#039;&#039;apt install&#039;&#039;&#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;apt install ./&amp;lt;filename.deb&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
: Don&#039;t forget that installation of software must be done with system administrator permissions.&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
:[[File:Apt-install-webmin.png | link= https://wiki.ihitc.net/mediawiki/images/f/f8/Apt-install-webmin.png | 500px]]&lt;br /&gt;
:[[Media:Apt-install-webmin.png | Click for Larger Image]]&lt;br /&gt;
: &#039;&#039;NOTE: You can get similar information to what you can get with &#039;&#039;&#039;apt show&#039;&#039;&#039; from a &#039;&#039;&#039;DEB&#039;&#039;&#039; package file using the following command:&#039;&#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;dpkg -I &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Notice the additional packages which are required by Webmin (dependencies) which will be downloaded and installed by &#039;&#039;&#039;apt&#039;&#039;&#039; from a repository in order to complete the installation.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open a web browser on your host system and visit https://xxx.xxx.xxx.xxx:10000 where your IP replaces xxx.xxx.xxx.xxx&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Login using your Debian username and password &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Explore the Webmin interface&lt;br /&gt;
:[[file:Webmin-dashboard.png | link= https://wiki.ihitc.net/mediawiki/images/0/0f/Webmin-dashboard.png | 500px]]&lt;br /&gt;
:[[media:Webmin-dashboard.png | Click for Larger Image]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Set Static IP Address==&lt;br /&gt;
&lt;br /&gt;
: An important first step is to learn how to diferenciate between network interfaces. Take a look at [https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ this site] and [https://github.com/systemd/systemd/blob/master/src/udev/udev-builtin-net_id.c#L20 this site] to understand how network interface names in Debian 9 and later are identified.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Set a static IP for your server&amp;lt;/li&amp;gt;&lt;br /&gt;
:* Using your text editor of choice, open up the file &#039;&#039;/etc/network/interfaces&#039;&#039;&lt;br /&gt;
:* Notice how it is currently set to dhcp for the &#039;&#039;ens192&#039;&#039; interface.&lt;br /&gt;
:* To set a static IP, you will need to change &#039;&#039;iface ens192 inet dhcp&#039;&#039; to &#039;&#039;iface ens192 inet static&#039;&#039;.&lt;br /&gt;
:* Now, under the iface line you just edited, you will need to enter the address, netmask, and gateway for the static network.&lt;br /&gt;
:&#039;&#039;&#039; Reminder: it is common practice to indent (tab) static network configuration information in the interfaces file.&lt;br /&gt;
&#039;&#039; Note: Your configuration should be similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;allow-hotplug ens192&lt;br /&gt;
iface ens192 inet static&lt;br /&gt;
	address xxx.xxx.xxx.xxx&lt;br /&gt;
	netmask 255.255.255.0&lt;br /&gt;
	gateway 172.17.50.1&lt;br /&gt;
	dns-nameservers 172.17.139.11 172.17.139.111&amp;lt;/pre&amp;gt;&lt;br /&gt;
: * Now save the file, and exit your file editor.&lt;br /&gt;
&amp;lt;li&amp;gt;Apply your static IP address&amp;lt;/li&amp;gt;&lt;br /&gt;
: * Now we are going to apply the static IP change. Try using &#039;&#039;&#039;ip address show&#039;&#039;&#039; to view your active configuration now and you should see that your old address is still active.&lt;br /&gt;
:&#039;&#039;NOTE: You should only make network configuration changes when you have physical access to a machine. This way, if you mess up your configuration you will be able to fix it from a local console.&#039;&#039;&#039; If you lose working SSH access to your system after making these changes you&#039;ll need to connect in through the NetLab console interface (which is equivalent to physical access) and find and correct your configuration issues.&lt;br /&gt;
:* Using the &#039;&#039;&#039;ifdown&#039;&#039;&#039; and &#039;&#039;&#039;ifup&#039;&#039;&#039; command, we are going to restart the network interface, this step is required to apply the change.&lt;br /&gt;
&#039;&#039; Note: A good method to watch this change is to have to ping windows open on your local machine ping both your old IP address and your new IP address with a &#039;&#039;&#039;ping 172.17.50.xx -t&#039;&#039;&#039; this will allow you to see how quickly the change will happen.  The first image below is with the DHCP address, the second is after the static address is applied.&lt;br /&gt;
:[[File:Lab5_ping_ifup_ifdown.png|link=https://wiki.ihitc.net/mediawiki/images/2/2f/Lab5_ping_ifup_ifdown.png|500px]]&lt;br /&gt;
:[[Media:Lab5_ping_ifup_ifdown.png|Click here for a larger image]]&lt;br /&gt;
:* In a SSH terminal, run &#039;&#039;&#039;sudo ifdown ens192 &amp;amp;&amp;amp; sudo ifup ens192&#039;&#039;&#039;. Notice the two &#039;&#039;&amp;amp;&amp;amp;&#039;&#039; symbols. This tells the Linux shell that it should run the second command right after the first. If we do not define this, then we would be left with a machine that has its networking turned off.&lt;br /&gt;
: &amp;lt;code&amp;gt;sudo ifdown ens192 &amp;amp;&amp;amp; sudo ifup ens192&amp;lt;/code&amp;gt;&lt;br /&gt;
&#039;&#039; Note: you will lose your SSH connection because the IP your SSH session is connected to is no longer in use by your VM.&lt;br /&gt;
:* At this point, your machine should now be using a static address. You may receive an error message indicating that an address cannot be assigned which is related to your old DHCP address still being on the interface as well. Use &#039;&#039;&#039;ip address show&#039;&#039;&#039; to verify the new IP address is assigned to the interface.&lt;br /&gt;
&amp;lt;li&amp;gt;Verify the new static IP address&amp;lt;/li&amp;gt;&lt;br /&gt;
:* Used a &#039;&#039;&#039;ping&#039;&#039;&#039; command from your local PC to try pinging both the old DHCP address as well as your new static address of your VM. &lt;br /&gt;
:* Once you have verified the VM is responding on the new static IP address reboot the system to ensure the old DHCP address is removed by restarting your VM with &#039;&#039;&#039;sudo shutdown -r now&#039;&#039;&#039; Note you will lose your SSH connection because the IP your SSH session is connected to is no longer in use by your VM.&lt;br /&gt;
&amp;lt;li&amp;gt;Reconnect through SSH to your new IP address and verify it is now applied using the &#039;&#039;&#039;ip address show&#039;&#039;&#039; command.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==DNS Section==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
* You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
: [[File:Bind_named_conf.png | 500px]]&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
* Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your system name, &amp;quot;automail&amp;quot; was used when setting the mail server up.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;.&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well. (This will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Make sure to apply the changes using the button in the top right that shows two arrows in a cricle.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;After applying the changes and rebooting everything should be working. just make sure to test it using the nslookup and dig commands.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Auto Reply Configuration==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install vacation&amp;lt;/li&amp;gt;&lt;br /&gt;
: Vacation is a Linux package that will auto-respond to received emails for the receiving users. &lt;br /&gt;
&amp;lt;code&amp;gt;sudo apt install vacation&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the vacation program in the profile you wish to set up the reply message from&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;vacation&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Follow the prompts, for now reply with the default answer (Y)&amp;lt;/li&amp;gt;&lt;br /&gt;
: [[File:MAILSVR_vaca_prompts.png|link=https://wiki.ihitc.net/mediawiki/images/7/76/MAILSVR_vaca_prompts.png|500px]]&lt;br /&gt;
: [[Media:MAILSVR_vaca_prompts.png|Click here for a larger image]]&lt;br /&gt;
&amp;lt;li&amp;gt;Edit the vacation.msg file&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nano vacation.msg&amp;lt;/code&amp;gt; &lt;br /&gt;
: [[File:MAILSVR_vaca_msg.png|link=https://wiki.ihitc.net/mediawiki/images/b/b9/MAILSVR_vaca_msg.png|500px]]&lt;br /&gt;
: [[Media:MAILSVR_vaca_msg.png|Click for a larger image]]&lt;br /&gt;
:* Enter the message that you would like to have in the auto-response.&lt;br /&gt;
&amp;lt;li&amp;gt;Set the response to auto mail every message&amp;lt;/li&amp;gt;&lt;br /&gt;
: The default response is every one week to send an auto-reply, for our use it is important to reply to every email.&lt;br /&gt;
&amp;lt;code&amp;gt;vacation -i -r 0&amp;lt;/code&amp;gt;&lt;br /&gt;
: &#039;&#039;NOTE: It is important to understand this command sets the auto-reply delay. Using the &#039;&#039;&#039;-r 0&#039;&#039;&#039; sets the vacation program to reply to EVERY message it receives.  In a production environment, this is not recommended as it can create mail loops.&lt;br /&gt;
&amp;lt;li&amp;gt;Test your reply message from the CLI &#039;&#039;&#039;mailutils&#039;&#039;&#039; package or the MTA chosen to use on client computers&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9505</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9505"/>
		<updated>2021-02-19T01:05:06Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;NOTE: You will have to run some of these scripts as &#039;&#039;&#039;SUDO&#039;&#039;&#039; for them to work. If something doesn&#039;t work try running as &#039;&#039;&#039;SUDO&#039;&#039;&#039;.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;##!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;sudo&amp;quot;, &amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&lt;br /&gt;
* After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&lt;br /&gt;
&amp;lt;ul&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME = &amp;quot;sample-file&amp;quot;&lt;br /&gt;
print(&amp;quot;Welcome to the sample file generation utility!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Files will be created using the filename format &amp;quot; + BASENAME + &amp;quot;X.extension&amp;quot;)&lt;br /&gt;
NUM = int(input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = input(&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(0, NUM):&lt;br /&gt;
    subprocess.call([&amp;quot;touch&amp;quot;, BASENAME + str(CURNUM) + &amp;quot;.&amp;quot; + EXTENSION])&lt;br /&gt;
print(&amp;quot;Created &amp;quot; + str(NUM) + &amp;quot; file(s).&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;input()&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;input()&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
* Try running the script and see if you were correct about what it does and how it works.&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
* See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&lt;br /&gt;
* See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
def helloname():&lt;br /&gt;
    name = input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
    print(&amp;quot;Hello &amp;quot; + name + &amp;quot;!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;This program will welcome you twice to be extra nice!&amp;quot;)&lt;br /&gt;
helloname()&lt;br /&gt;
print(&amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;)&lt;br /&gt;
helloname()&lt;br /&gt;
print(&amp;quot;Thanks for playing!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
def askname():&lt;br /&gt;
    yourname = input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
    return yourname&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
    print(&amp;quot;Hello &amp;quot; + thename + &amp;quot;!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;)&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print(&amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;)&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print(&amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;)&lt;br /&gt;
somevariable = &amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print(&amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;)&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print(&amp;quot;Thanks for playing &amp;quot; + userentry + &amp;quot;!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9504</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9504"/>
		<updated>2021-02-19T00:44:03Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts. &#039;&#039;&#039;You will have to run some of these scripts as SUDO for them to work. If something doesn&#039;t work try running as SUDO.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;##!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;sudo&amp;quot;, &amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&lt;br /&gt;
* After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&lt;br /&gt;
&amp;lt;ul&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME = &amp;quot;sample-file&amp;quot;&lt;br /&gt;
print(&amp;quot;Welcome to the sample file generation utility!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Files will be created using the filename format &amp;quot; + BASENAME + &amp;quot;X.extension&amp;quot;)&lt;br /&gt;
NUM = int(input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = input(&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(0, NUM):&lt;br /&gt;
    subprocess.call([&amp;quot;touch&amp;quot;, BASENAME + str(CURNUM) + &amp;quot;.&amp;quot; + EXTENSION])&lt;br /&gt;
print(&amp;quot;Created &amp;quot; + str(NUM) + &amp;quot; file(s).&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;input()&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;input()&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
* Try running the script and see if you were correct about what it does and how it works.&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
* See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&lt;br /&gt;
* See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
def helloname():&lt;br /&gt;
    name = input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
    print(&amp;quot;Hello &amp;quot; + name + &amp;quot;!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;This program will welcome you twice to be extra nice!&amp;quot;)&lt;br /&gt;
helloname()&lt;br /&gt;
print(&amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;)&lt;br /&gt;
helloname()&lt;br /&gt;
print(&amp;quot;Thanks for playing!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
def askname():&lt;br /&gt;
    yourname = input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
    return yourname&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
    print(&amp;quot;Hello &amp;quot; + thename + &amp;quot;!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;)&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print(&amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;)&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print(&amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;)&lt;br /&gt;
somevariable = &amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print(&amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;)&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print(&amp;quot;Thanks for playing &amp;quot; + userentry + &amp;quot;!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9474</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9474"/>
		<updated>2021-02-16T00:58:41Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Functions and Experimenting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;##!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;sudo&amp;quot;, &amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&lt;br /&gt;
* After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&lt;br /&gt;
&amp;lt;ul&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME = &amp;quot;sample-file&amp;quot;&lt;br /&gt;
print(&amp;quot;Welcome to the sample file generation utility!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Files will be created using the filename format &amp;quot; + BASENAME + &amp;quot;X.extension&amp;quot;)&lt;br /&gt;
NUM = int(input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = input(&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(0, NUM):&lt;br /&gt;
    subprocess.call([&amp;quot;touch&amp;quot;, BASENAME + str(CURNUM) + &amp;quot;.&amp;quot; + EXTENSION])&lt;br /&gt;
print(&amp;quot;Created &amp;quot; + str(NUM) + &amp;quot; file(s).&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;input()&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;input()&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
* Try running the script and see if you were correct about what it does and how it works.&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
* See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&lt;br /&gt;
* See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
def helloname():&lt;br /&gt;
    name = input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
    print(&amp;quot;Hello &amp;quot; + name + &amp;quot;!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;This program will welcome you twice to be extra nice!&amp;quot;)&lt;br /&gt;
helloname()&lt;br /&gt;
print(&amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;)&lt;br /&gt;
helloname()&lt;br /&gt;
print(&amp;quot;Thanks for playing!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
def askname():&lt;br /&gt;
    yourname = input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
    return yourname&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
    print(&amp;quot;Hello &amp;quot; + thename + &amp;quot;!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;)&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print(&amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;)&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print(&amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;)&lt;br /&gt;
somevariable = &amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print(&amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;)&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print(&amp;quot;Thanks for playing &amp;quot; + userentry + &amp;quot;!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_13_mnjk&amp;diff=9473</id>
		<title>Lab 13 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_13_mnjk&amp;diff=9473"/>
		<updated>2021-02-16T00:39:10Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic BASH scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple BASH Scripts ==&lt;br /&gt;
At their core BASH scripts are really just lists of commands which could have been entered directly into the command line but have been pre-entered into a file to be run later instead. We can see how this works by creating a couple of very simple BASH scripts which each just run a single command. Your ability to write BASH scripts that do something useful is really only limited by how well you know Linux commands and utilities which could be included in the script. The &#039;&#039;&#039;echo&#039;&#039;&#039; command can be used on your system to print information out to the standard output.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Lets try running a command echo on your computer:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;echo Hello World!&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You should see the text &amp;quot;Hello World!&amp;quot; printed out on the screen below your command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.sh&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
* In order to turn that command into a script we just need to put the command into a text file and add one more line, called a &#039;&#039;sha-bang&#039;&#039; because it is made up of a hash (pound) sign and a bang (exclamation) sign. This line tells the system what program to use to interpret the commands in the script. In this case we&#039;re going to be writing BASH scripts so we&#039;ll set it for the BASH program.&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
echo Hello World!&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.sh&#039;&#039; file to be executable by all users on the system so that we will be able to run it.&lt;br /&gt;
* &#039;&#039;NOTE: As a safety precaution against mistakenly executing something you don&#039;t really want to the shell will not allow you to run a file by just typing the filename, even if you are in the correct directory. The location of the file must either be included in your system&#039;s PATH, you must specify the full path to the file (such as &#039;&#039;&#039;/home/jsmith/hello.sh&#039;&#039;&#039;), or if you are in the correct directory already you can put in a relative path like &#039;&#039;&#039;./hello.sh&#039;&#039;&#039;. Remember, a single period is a shortcut which means the current directory so ./ means a file in the current working directory. Try running your &#039;&#039;hello.sh&#039;&#039; script now. If your system outputs &#039;&#039;Hello World!&#039;&#039; just like when you ran the &#039;&#039;&#039;echo&#039;&#039;&#039; command from the command line directly you have successfully written your first BASH script!&#039;&#039;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.sh&#039;&#039; which executes the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039; when the script is run.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in BASH Scripts ==&lt;br /&gt;
Variables are a key part of turning a simple list of instructions you could type into a command line into something much more powerful by allowing you to reuse code and do something very similar (remember programmers are lazy!) but with a little tweak each time without re-writing the whole thing. Variables can be defined in the script itself but there are also special variables which are part of the BASH environment we can use. Variables can be identified in bash scripts as starting with a &#039;&#039;$&#039;&#039;. One type of these variables allows us to access arguments which have been supplied as part of the command line calling the script. Sometimes we only want to run certain sections of the script or we want to modify the script depending on the outcome of some test, called a conditional. This is often used in combination with variables as we&#039;ll see in the example below. In BASH the script filename is assigned to the &#039;&#039;$0&#039;&#039; variable, the first argument to &#039;&#039;$1&#039;&#039; and so on. Let&#039;s see how we can modify our &#039;&#039;hello.sh&#039;&#039; script to make it a bit more personable by including a name.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.sh&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
echo Hello $1!&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
* Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try just running &#039;&#039;&#039;./hello.sh&#039;&#039;&#039; again and see what happens.&lt;br /&gt;
&amp;lt;ul&amp;gt; It might be the case that we want to go back to the simple &#039;&#039;Hello World!&#039;&#039; and maybe add some instructions if they don&#039;t specify an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.sh&#039;&#039; script again and adding a conditional like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can predict what these changes will do when the script is run and then try it out to see if you are correct.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
    echo Hello $1!&lt;br /&gt;
else&lt;br /&gt;
    echo Hello World!&lt;br /&gt;
    echo Try running $0 yourfirstnamehere to get a personal greeting!&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
* It&#039;s also possible to capture the standard output of a command executed by the script and put that into a variable for later use. For example, try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer.&lt;br /&gt;
&amp;lt;li&amp;gt;  Save this script as &#039;&#039;better-backup.sh&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=$(date +%Y%m%d)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;$USER&amp;quot;-backup-&amp;quot;$TODAY&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
echo Beginning backup for $USER on $TODAY&lt;br /&gt;
tar -czf $BACKUPFILE /home/$USER/&lt;br /&gt;
echo Backup completed for $USER saved to $BACKUPFILE&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable. Can you do this with a change to only one line?&lt;br /&gt;
* After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&lt;br /&gt;
&amp;lt;ul&amp;gt; It is important to note that while this script works, it&#039;s just a simple example and not well written because it is easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
Sometimes you want a program to do something over and over again several times. This is typically done using a loop. Let&#039;s say you wanted to create a bunch of sample files to do some further practice with in the current directory named &#039;&#039;sample-fileX.extension&#039;&#039; where &#039;&#039;X&#039;&#039; was a number that would keep incrementing by 1 each time and you could specify any extension you wanted. We could certainly use arguments to capture that user input but it is also possible to accept input from the user directly while the script is running. This would create what we call an &amp;quot;interactive&amp;quot; script because the user is interacting with it while it runs.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.sh&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
BASENAME=sample-file&lt;br /&gt;
echo &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
echo &amp;quot;Files will be created using the filename format &amp;quot;$BASENAME&amp;quot;X.extension&amp;quot;&lt;br /&gt;
echo &amp;quot;Enter the number of files you wish to create, then press Enter:&amp;quot;&lt;br /&gt;
read NUM&lt;br /&gt;
echo &amp;quot;Enter the extension (without the leading period) to put on the files&amp;quot;&lt;br /&gt;
read EXTENSION&lt;br /&gt;
for CURNUM in `seq 1 $NUM`; do&lt;br /&gt;
    touch $BASENAME$CURNUM.$EXTENSION&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Created &amp;quot;$NUM&amp;quot; file(s).&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a few things to note about this script. First, we have used one type of loop, a FOR loop, but there are others and other ways to make this work. Second you can see several more examples of calling another program inside your script. In this case we have used the &#039;&#039;&#039;read&#039;&#039;&#039;, &#039;&#039;&#039;seq&#039;&#039;&#039;, and &#039;&#039;&#039;touch&#039;&#039;&#039; programs to accomplish our goal. The &#039;&#039;&#039;seq&#039;&#039;&#039; program is especially useful while writing scripts. It can be used to generate a series of numbers from a starting number (1 in this case) to a stopping number (&#039;&#039;$NUM&#039;&#039; in this case). There are many other helpful programs you can use while writing scripts including some you know about already such as &#039;&#039;&#039;grep&#039;&#039;&#039; and &#039;&#039;&#039;find&#039;&#039;&#039;, and others you don&#039;t such as &#039;&#039;&#039;sed&#039;&#039;&#039; and &#039;&#039;&#039;awk&#039;&#039;&#039;. You can even use programs like &#039;&#039;&#039;wget&#039;&#039;&#039; to get information from the Internet and process it for use in a script instead of using it for just downloading a file. For example, if you know of a web site that lists the sunrise and sunset times you can use a combination of &#039;&#039;&#039;wget&#039;&#039;&#039; and &#039;&#039;&#039;grep&#039;&#039;&#039;/&#039;&#039;&#039;awk&#039;&#039;&#039;/&#039;&#039;&#039;sed&#039;&#039;&#039; to pull that time out of the webpage and use it as part of a script. The possibilities are almost endless, time spent learning about the ins and outs of these little utilities is time well spent if you will be writing shell scripts!&amp;lt;/li&amp;gt;&lt;br /&gt;
* Try running the script and see if you were correct about what it does and how it works.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: Also, it is important to note that while this script works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
* See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&lt;br /&gt;
* See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters &#039;&#039;N&#039;&#039; then do not create the files.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
One final programming structure we should discuss is the function. In shell scripting you can think of a function like something you could have put into a separate script so that you could call it to do something multiple times from inside of your script but instead of making it a completely separate file you decided to include it in a single script.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;  Here is a sample script using a function:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
function helloname {&lt;br /&gt;
    echo &amp;quot;Type your name, followed by enter:&amp;quot;&lt;br /&gt;
    read NAME&lt;br /&gt;
    echo &amp;quot;Hello &amp;quot;$NAME&amp;quot;!&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
echo &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname&lt;br /&gt;
echo &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname&lt;br /&gt;
echo &amp;quot;Thanks for playing!&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. Also, it&#039;s possible to pass information to a function using arguments just like you would with a separate script.&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of BASH scripting see if you can write a script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again. Also, loops can be used to operate on a list of things such as a list of filenames.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9472</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9472"/>
		<updated>2021-02-16T00:37:26Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Using Loops and Reading User Input */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;##!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;sudo&amp;quot;, &amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&lt;br /&gt;
* After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&lt;br /&gt;
&amp;lt;ul&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME = &amp;quot;sample-file&amp;quot;&lt;br /&gt;
print(&amp;quot;Welcome to the sample file generation utility!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Files will be created using the filename format &amp;quot; + BASENAME + &amp;quot;X.extension&amp;quot;)&lt;br /&gt;
NUM = int(input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = input(&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(0, NUM):&lt;br /&gt;
    subprocess.call([&amp;quot;touch&amp;quot;, BASENAME + str(CURNUM) + &amp;quot;.&amp;quot; + EXTENSION])&lt;br /&gt;
print(&amp;quot;Created &amp;quot; + str(NUM) + &amp;quot; file(s).&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;input()&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;input()&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
* Try running the script and see if you were correct about what it does and how it works.&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
* See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&lt;br /&gt;
* See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9471</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9471"/>
		<updated>2021-02-16T00:34:20Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Using Loops and Reading User Input */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;##!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;sudo&amp;quot;, &amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&lt;br /&gt;
* After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&lt;br /&gt;
&amp;lt;ul&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME = &amp;quot;sample-file&amp;quot;&lt;br /&gt;
print(&amp;quot;Welcome to the sample file generation utility!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Files will be created using the filename format &amp;quot; + BASENAME + &amp;quot;X.extension&amp;quot;)&lt;br /&gt;
NUM = int(input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = input(&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(0, NUM):&lt;br /&gt;
    subprocess.call([&amp;quot;touch&amp;quot;, BASENAME + str(CURNUM) + &amp;quot;.&amp;quot; + EXTENSION])&lt;br /&gt;
print(&amp;quot;Created &amp;quot; + str(NUM) + &amp;quot; file(s).&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;input()&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;input()&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
* Try running the script and see if you were correct about what it does and how it works.&lt;br /&gt;
&amp;lt;li&amp;gt; The script as provided does not actually produce the correct number of files requested by the user. See if you can fix the script to produce the correct number of files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9461</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9461"/>
		<updated>2021-02-16T00:20:58Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Using Variables and Conditionals in Python Scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;##!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;sudo&amp;quot;, &amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&lt;br /&gt;
* After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&lt;br /&gt;
&amp;lt;ul&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME=&amp;quot;sample-file&amp;quot;&lt;br /&gt;
print &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
print &amp;quot;Files will be created using the filename format &amp;quot;+BASENAME+&amp;quot;X.extension&amp;quot;&lt;br /&gt;
NUM = int(raw_input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = raw_input (&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(1,NUM):&lt;br /&gt;
        subprocess.call([&amp;quot;touch&amp;quot;, BASENAME+str(CURNUM)+&amp;quot;.&amp;quot;+EXTENSION])&lt;br /&gt;
print &amp;quot;Created &amp;quot;+str(NUM)+&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;raw_input&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;raw_input&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The script as provided does not actually produce the correct number of files requested by the user. See if you can fix the script to produce the correct number of files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9460</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9460"/>
		<updated>2021-02-16T00:08:54Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Using Variables and Conditionals in Python Scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;##!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code. After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME=&amp;quot;sample-file&amp;quot;&lt;br /&gt;
print &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
print &amp;quot;Files will be created using the filename format &amp;quot;+BASENAME+&amp;quot;X.extension&amp;quot;&lt;br /&gt;
NUM = int(raw_input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = raw_input (&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(1,NUM):&lt;br /&gt;
        subprocess.call([&amp;quot;touch&amp;quot;, BASENAME+str(CURNUM)+&amp;quot;.&amp;quot;+EXTENSION])&lt;br /&gt;
print &amp;quot;Created &amp;quot;+str(NUM)+&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;raw_input&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;raw_input&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The script as provided does not actually produce the correct number of files requested by the user. See if you can fix the script to produce the correct number of files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9459</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9459"/>
		<updated>2021-02-16T00:07:44Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Using Variables and Conditionals in Python Scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code. After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME=&amp;quot;sample-file&amp;quot;&lt;br /&gt;
print &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
print &amp;quot;Files will be created using the filename format &amp;quot;+BASENAME+&amp;quot;X.extension&amp;quot;&lt;br /&gt;
NUM = int(raw_input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = raw_input (&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(1,NUM):&lt;br /&gt;
        subprocess.call([&amp;quot;touch&amp;quot;, BASENAME+str(CURNUM)+&amp;quot;.&amp;quot;+EXTENSION])&lt;br /&gt;
print &amp;quot;Created &amp;quot;+str(NUM)+&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;raw_input&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;raw_input&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The script as provided does not actually produce the correct number of files requested by the user. See if you can fix the script to produce the correct number of files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9458</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9458"/>
		<updated>2021-02-16T00:07:36Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Creating Simple Python Scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env python3&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code. After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME=&amp;quot;sample-file&amp;quot;&lt;br /&gt;
print &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
print &amp;quot;Files will be created using the filename format &amp;quot;+BASENAME+&amp;quot;X.extension&amp;quot;&lt;br /&gt;
NUM = int(raw_input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = raw_input (&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(1,NUM):&lt;br /&gt;
        subprocess.call([&amp;quot;touch&amp;quot;, BASENAME+str(CURNUM)+&amp;quot;.&amp;quot;+EXTENSION])&lt;br /&gt;
print &amp;quot;Created &amp;quot;+str(NUM)+&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;raw_input&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;raw_input&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The script as provided does not actually produce the correct number of files requested by the user. See if you can fix the script to produce the correct number of files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9450</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9450"/>
		<updated>2021-02-15T07:46:52Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Using Variables and Conditionals in Python Scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code. After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME=&amp;quot;sample-file&amp;quot;&lt;br /&gt;
print &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
print &amp;quot;Files will be created using the filename format &amp;quot;+BASENAME+&amp;quot;X.extension&amp;quot;&lt;br /&gt;
NUM = int(raw_input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = raw_input (&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(1,NUM):&lt;br /&gt;
        subprocess.call([&amp;quot;touch&amp;quot;, BASENAME+str(CURNUM)+&amp;quot;.&amp;quot;+EXTENSION])&lt;br /&gt;
print &amp;quot;Created &amp;quot;+str(NUM)+&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;raw_input&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;raw_input&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The script as provided does not actually produce the correct number of files requested by the user. See if you can fix the script to produce the correct number of files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9449</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9449"/>
		<updated>2021-02-15T07:46:17Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Using Variables and Conditionals in Python Scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a scrip:.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
USER = &amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY = subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY = str(TODAY.rstrip())&lt;br /&gt;
BACKUPFILE = &amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print(&amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY)&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print(&amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code. After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME=&amp;quot;sample-file&amp;quot;&lt;br /&gt;
print &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
print &amp;quot;Files will be created using the filename format &amp;quot;+BASENAME+&amp;quot;X.extension&amp;quot;&lt;br /&gt;
NUM = int(raw_input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = raw_input (&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(1,NUM):&lt;br /&gt;
        subprocess.call([&amp;quot;touch&amp;quot;, BASENAME+str(CURNUM)+&amp;quot;.&amp;quot;+EXTENSION])&lt;br /&gt;
print &amp;quot;Created &amp;quot;+str(NUM)+&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;raw_input&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;raw_input&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The script as provided does not actually produce the correct number of files requested by the user. See if you can fix the script to produce the correct number of files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9448</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9448"/>
		<updated>2021-02-15T07:39:48Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Using Variables and Conditionals in Python Scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
print(&amp;quot;The script you are running is: &amp;quot; + sys.argv[0])&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
&amp;lt;ul&amp;gt;Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
    name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
    name = &amp;quot;World&amp;quot;&lt;br /&gt;
    print(&amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;)&lt;br /&gt;
print(&amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a scrip:.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY=TODAY.rstrip()&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code. After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME=&amp;quot;sample-file&amp;quot;&lt;br /&gt;
print &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
print &amp;quot;Files will be created using the filename format &amp;quot;+BASENAME+&amp;quot;X.extension&amp;quot;&lt;br /&gt;
NUM = int(raw_input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = raw_input (&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(1,NUM):&lt;br /&gt;
        subprocess.call([&amp;quot;touch&amp;quot;, BASENAME+str(CURNUM)+&amp;quot;.&amp;quot;+EXTENSION])&lt;br /&gt;
print &amp;quot;Created &amp;quot;+str(NUM)+&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;raw_input&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;raw_input&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The script as provided does not actually produce the correct number of files requested by the user. See if you can fix the script to produce the correct number of files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9447</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9447"/>
		<updated>2021-02-15T07:11:19Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Creating Simple Python Scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. We will be learning how to write Python3 as its the newest version. You can research the main difference between them but just know that we are using Python3 because its the version that is being supported.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.py&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&#039;&#039;NOTE: that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: You are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print(&amp;quot;Hello World!&amp;quot;)&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Try modifying your hello.py file like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/python&lt;br /&gt;
import os&lt;br /&gt;
print(&amp;quot;Hello World from Python!&amp;quot;)&lt;br /&gt;
os.system(&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;&amp;quot;echo Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). Try running this new script and see how it works.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case. Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
print &amp;quot;The script you are running is: &amp;quot; + sys.argv[0]&lt;br /&gt;
print &amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not. Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
        name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
        name = &amp;quot;World&amp;quot;&lt;br /&gt;
        print &amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;&lt;br /&gt;
print &amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated. Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY=TODAY.rstrip()&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code. After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME=&amp;quot;sample-file&amp;quot;&lt;br /&gt;
print &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
print &amp;quot;Files will be created using the filename format &amp;quot;+BASENAME+&amp;quot;X.extension&amp;quot;&lt;br /&gt;
NUM = int(raw_input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = raw_input (&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(1,NUM):&lt;br /&gt;
        subprocess.call([&amp;quot;touch&amp;quot;, BASENAME+str(CURNUM)+&amp;quot;.&amp;quot;+EXTENSION])&lt;br /&gt;
print &amp;quot;Created &amp;quot;+str(NUM)+&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;raw_input&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;raw_input&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The script as provided does not actually produce the correct number of files requested by the user. See if you can fix the script to produce the correct number of files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9446</id>
		<title>Lab 14 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_14_mnjk&amp;diff=9446"/>
		<updated>2021-02-15T06:44:25Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic python shell scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# &#039;&#039;&#039;Have completed the reading on BASH and python scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&#039;&#039;&#039;&lt;br /&gt;
# Have completed the BASH scripting lab, this lab will take you through several similar tasks at a much faster rate&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple Python Scripts ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just like with BASH scripts we want to specify the interpreter at the beginning of our script with a sha-bang. Create a new text file named &#039;&#039;hello.py&#039;&#039; (note that we are now using the &#039;&#039;.py&#039;&#039; extension so we can remember this is a Python instead of a BASH script) with the following text:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
print &amp;quot;Hello World from Python!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Set the &#039;&#039;hello.py&#039;&#039; file to be executable by all users on the system so that we will be able to run it and then try running the script.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Something to note is that you are now printing text to the screen using the Python print command and not the BASH echo command. If you try running the command &#039;&#039;&#039;print &amp;quot;Hello World!&amp;quot;&#039;&#039;&#039; from your command line you will get an error. This is what will make scripting in Python a bit different than BASH scripting. When scripting in BASH every line in your script file could be entered directly on the command line, in Python the commands need to be run through the Python interpreter to be executed.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; That said, it&#039;s still possible to run system commands from inside of a Python script as well (that&#039;s what ultimately makes them useful for shell scripting purposes after all. To do this we will need to import a special library of functions that Python can use to interact with the underlying system. Try modifying your hello.py file like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import os&lt;br /&gt;
print &amp;quot;Hello World from Python!&amp;quot;&lt;br /&gt;
os.system(&#039;echo &amp;quot;Hello World from BASH inside of Python!&amp;quot;&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In this example we have imported the os library and then run a special function named &#039;&#039;os.system&#039;&#039; to execute a command on the system (in this case the &#039;&#039;echo &amp;quot;Hello World from BASH inside of Python!&amp;quot;&#039;&#039; command). This gets a little tricky because of the double and single quotations which are needed because we need to specify the command we want to run through &#039;&#039;os.system&#039;&#039; inside of quotation marks but we also want to pass some quote marks through to the echo command itself. There are a few ways to accomplish this but the one used in this case is to use single quotes for Python to know what command to run and then double quotes inside of those for the echo command to get it&#039;s argument. Try running this new script and see how it works. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.py&#039;&#039; which runs the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in Python Scripts ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Argument parsing in Python is not quite as simple as it is in BASH  but with practice it actually allows for much more complex scripts to be developed. Arguments are accessed as entries in an array through the &#039;&#039;sys&#039;&#039; library. First, we need to import the &#039;&#039;sys&#039;&#039; library and then arguments will be accessed through the variables &#039;&#039;sys.argv[0]&#039;&#039; (for the script name) &#039;&#039;sys.argv[1]&#039;&#039; (for the first argument) and so on. These variables with square brackets after them are together called an array which is just a single variable that stores multiple values in different &amp;quot;slots&amp;quot; which are identified by numbers starting with zero in this case. Try adjusting your &#039;&#039;hello.py&#039;&#039; script to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
print &amp;quot;The script you are running is: &amp;quot; + sys.argv[0]&lt;br /&gt;
print &amp;quot;Hello &amp;quot; + sys.argv[1] + &amp;quot; from Python!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What do you think will happen if you run the script like this &#039;&#039;&#039;./hello.py yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try running &#039;&#039;&#039;./hello.py&#039;&#039;&#039; and see what happens. Unlike BASH Python is a little more particular about things and if you try to access a variable that doesn&#039;t exist it will give you an error. This isn&#039;t very user friendly so let&#039;s add a conditional to check and see if an argument was supplied or not. Try updating your &#039;&#039;hello.py&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import sys&lt;br /&gt;
if len(sys.argv) &amp;gt; 1:&lt;br /&gt;
        name = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
        name = &amp;quot;World&amp;quot;&lt;br /&gt;
        print &amp;quot;Try running &amp;quot; + sys.argv[0] + &amp;quot; yourfirstnamehere to get a personal greeting!&amp;quot;&lt;br /&gt;
print &amp;quot;Hello &amp;quot; + name + &amp;quot; from Python!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what these changes will do and then try it out to see if you are correct. Because python stores all of the arguments into a special type of variable which can hold multiple pieces of data, called an array, we can use the &#039;&#039;len()&#039;&#039; function to check the length of the &#039;&#039;sys.argv&#039;&#039; array. If it&#039;s more than one (because &#039;&#039;sys.argv[0]&#039;&#039; always holds the script name so there is always at least one) we know arguments have been added. If not we know they have not been added. You&#039;ll also notice that indenting properly is important in Python scripts this is how python knows if a line is part of the if/else statement or something that comes after it.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It&#039;s also possible to capture the standard output of a command and put that into a variable for use just as we did with BASH. For example try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. You&#039;ll also see that in order to capture the output we need to use the &#039;&#039;subprocess&#039;&#039; library instead of the &#039;&#039;os&#039;&#039; library we were using before. It&#039;s suggested that you switch to using the &#039;&#039;subprocess&#039;&#039; library anyway as the &#039;&#039;os.system&#039;&#039; function has been deprecated. Save this script as &#039;&#039;better-backup.py&#039;&#039; with the appropriate permissions to run it as a script.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=subprocess.check_output(&amp;quot;date +%Y%m%d&amp;quot;, shell=True)&lt;br /&gt;
TODAY=TODAY.rstrip()&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the above example and see if it works as you expect. This script used the output from the date command to get date information to be used as part of the filename but if you were actually writing the script in python you would probably use some of the python built in date functions instead. The advantages of doing it with the built-in functionality are that you will no longer be depending on the &#039;&#039;&#039;date&#039;&#039;&#039; program being installed on the system and you won&#039;t have to remove the newline from the end of the &#039;&#039;&#039;date&#039;&#039;&#039; output with the &#039;&#039;.rstrip()&#039;&#039; function, and you will just generally have cleaner code. After testing the above script and seeing how it works try modifying it like this to use built in date functionality:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
import datetime&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=datetime.date.today().strftime(&amp;quot;%Y%m%d&amp;quot;)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;+USER+&amp;quot;-backup-&amp;quot;+TODAY+&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
print &amp;quot;Beginning backup for &amp;quot;+USER+&amp;quot; on &amp;quot;+TODAY&lt;br /&gt;
subprocess.call([&amp;quot;tar&amp;quot;, &amp;quot;-czf&amp;quot;, BACKUPFILE, &amp;quot;/home/&amp;quot;+USER])&lt;br /&gt;
print &amp;quot;Backup completed for &amp;quot;+USER+&amp;quot; saved to &amp;quot;+BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It is important to note that while these scripts work, they are just simple examples and not well written because they are easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. Better scripts could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.py&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import subprocess&lt;br /&gt;
BASENAME=&amp;quot;sample-file&amp;quot;&lt;br /&gt;
print &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
print &amp;quot;Files will be created using the filename format &amp;quot;+BASENAME+&amp;quot;X.extension&amp;quot;&lt;br /&gt;
NUM = int(raw_input(&amp;quot;Enter the number of files you wish to create, then press Enter: &amp;quot;))&lt;br /&gt;
EXTENSION = raw_input (&amp;quot;Enter the extension (without the leading period) to put on the files: &amp;quot;)&lt;br /&gt;
for CURNUM in range(1,NUM):&lt;br /&gt;
        subprocess.call([&amp;quot;touch&amp;quot;, BASENAME+str(CURNUM)+&amp;quot;.&amp;quot;+EXTENSION])&lt;br /&gt;
print &amp;quot;Created &amp;quot;+str(NUM)+&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a couple of differences to note when comparing this with the similar BASH script we created. First, instead of using a separate program, like the BASH &#039;&#039;&#039;read&#039;&#039;&#039; program, we are obtaining user input with the &#039;&#039;raw_input&#039;&#039; function. This program is then storing the user&#039;s input into a certain variable. By default the &#039;&#039;raw_input&#039;&#039; function saves information as a STRING which is a type of variable which can hold letters and numbers but can&#039;t be used for numeric operations like adding, subtracting, looping, etc. Because of this we use the &#039;&#039;int()&#039;&#039; and &#039;&#039;str()&#039;&#039; funtions to switch the data back and forth from the string type to the integer numeric type as needed in various parts of the script. Second, the for statement is using the built-in &#039;&#039;range()&#039;&#039; function instead of the &#039;&#039;&#039;seq&#039;&#039;&#039; command as we did in BASH to generate the number of loops needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; The script as provided does not actually produce the correct number of files requested by the user. See if you can fix the script to produce the correct number of files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script mostly works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters N then do not create the files. Hint, you will need to do a little research on using python IF statements to check user input.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Just as in BASH we can create functions in python as well. Try entering this simple sample as &#039;&#039;hello-func.py&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def helloname():&lt;br /&gt;
        name = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+name+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname()&lt;br /&gt;
print &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This should work pretty much the same way that the BASH equivalent script did. See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. One difference with functions in Python is how you pass information in and out of functions. Instead of using arguments you include the information in the function call itself and you can return information from the function which can be used immediately or can be stored into a variable. Try modifying &#039;&#039;hello-func.py&#039;&#039; like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
def askname():&lt;br /&gt;
        yourname = raw_input(&amp;quot;Enter your name, followed by enter: &amp;quot;)&lt;br /&gt;
        return yourname&lt;br /&gt;
def helloname(thename):&lt;br /&gt;
        print &amp;quot;Hello &amp;quot;+thename+&amp;quot;!&amp;quot;&lt;br /&gt;
print &amp;quot;There are lots of ways to make use of the two functions in this script. We can pass a pre-specified string to a function:&amp;quot;&lt;br /&gt;
helloname(&amp;quot;world&amp;quot;)&lt;br /&gt;
print &amp;quot;We can ask for your name and use it immediately as input into the hello function:&amp;quot;&lt;br /&gt;
helloname(askname())&lt;br /&gt;
print &amp;quot;We can take a string already stored in a variable and pass the variable to a function:&amp;quot;&lt;br /&gt;
somevariable=&amp;quot;Linux Lover&amp;quot;&lt;br /&gt;
helloname(somevariable)&lt;br /&gt;
print &amp;quot;Or we can ask you your name again and store your name in a variable once and then use it a few times:&amp;quot;&lt;br /&gt;
userentry = askname()&lt;br /&gt;
helloname(userentry)&lt;br /&gt;
print &amp;quot;Thanks for playing &amp;quot;+userentry+&amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what this script will do and how it works before running it, then try it out and see if you were correct.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of python scripting for system administration see if you can write a python script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to python shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_13_mnjk&amp;diff=9445</id>
		<title>Lab 13 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_13_mnjk&amp;diff=9445"/>
		<updated>2021-02-15T06:36:57Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Functions and Experimenting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic BASH scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Have completed the reading on BASH scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple BASH Scripts ==&lt;br /&gt;
At their core BASH scripts are really just lists of commands which could have been entered directly into the command line but have been pre-entered into a file to be run later instead. We can see how this works by creating a couple of very simple BASH scripts which each just run a single command. Your ability to write BASH scripts that do something useful is really only limited by how well you know Linux commands and utilities which could be included in the script. The &#039;&#039;&#039;echo&#039;&#039;&#039; command can be used on your system to print information out to the standard output.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Lets try running a command echo on your computer:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;echo Hello World!&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You should see the text &amp;quot;Hello World!&amp;quot; printed out on the screen below your command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.sh&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
* In order to turn that command into a script we just need to put the command into a text file and add one more line, called a &#039;&#039;sha-bang&#039;&#039; because it is made up of a hash (pound) sign and a bang (exclamation) sign. This line tells the system what program to use to interpret the commands in the script. In this case we&#039;re going to be writing BASH scripts so we&#039;ll set it for the BASH program.&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
echo Hello World!&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.sh&#039;&#039; file to be executable by all users on the system so that we will be able to run it.&lt;br /&gt;
* &#039;&#039;NOTE: As a safety precaution against mistakenly executing something you don&#039;t really want to the shell will not allow you to run a file by just typing the filename, even if you are in the correct directory. The location of the file must either be included in your system&#039;s PATH, you must specify the full path to the file (such as &#039;&#039;&#039;/home/jsmith/hello.sh&#039;&#039;&#039;), or if you are in the correct directory already you can put in a relative path like &#039;&#039;&#039;./hello.sh&#039;&#039;&#039;. Remember, a single period is a shortcut which means the current directory so ./ means a file in the current working directory. Try running your &#039;&#039;hello.sh&#039;&#039; script now. If your system outputs &#039;&#039;Hello World!&#039;&#039; just like when you ran the &#039;&#039;&#039;echo&#039;&#039;&#039; command from the command line directly you have successfully written your first BASH script!&#039;&#039;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.sh&#039;&#039; which executes the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039; when the script is run.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in BASH Scripts ==&lt;br /&gt;
Variables are a key part of turning a simple list of instructions you could type into a command line into something much more powerful by allowing you to reuse code and do something very similar (remember programmers are lazy!) but with a little tweak each time without re-writing the whole thing. Variables can be defined in the script itself but there are also special variables which are part of the BASH environment we can use. Variables can be identified in bash scripts as starting with a &#039;&#039;$&#039;&#039;. One type of these variables allows us to access arguments which have been supplied as part of the command line calling the script. Sometimes we only want to run certain sections of the script or we want to modify the script depending on the outcome of some test, called a conditional. This is often used in combination with variables as we&#039;ll see in the example below. In BASH the script filename is assigned to the &#039;&#039;$0&#039;&#039; variable, the first argument to &#039;&#039;$1&#039;&#039; and so on. Let&#039;s see how we can modify our &#039;&#039;hello.sh&#039;&#039; script to make it a bit more personable by including a name.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.sh&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
echo Hello $1!&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
* Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try just running &#039;&#039;&#039;./hello.sh&#039;&#039;&#039; again and see what happens.&lt;br /&gt;
&amp;lt;ul&amp;gt; It might be the case that we want to go back to the simple &#039;&#039;Hello World!&#039;&#039; and maybe add some instructions if they don&#039;t specify an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.sh&#039;&#039; script again and adding a conditional like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can predict what these changes will do when the script is run and then try it out to see if you are correct.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
    echo Hello $1!&lt;br /&gt;
else&lt;br /&gt;
    echo Hello World!&lt;br /&gt;
    echo Try running $0 yourfirstnamehere to get a personal greeting!&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
* It&#039;s also possible to capture the standard output of a command executed by the script and put that into a variable for later use. For example, try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer.&lt;br /&gt;
&amp;lt;li&amp;gt;  Save this script as &#039;&#039;better-backup.sh&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=$(date +%Y%m%d)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;$USER&amp;quot;-backup-&amp;quot;$TODAY&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
echo Beginning backup for $USER on $TODAY&lt;br /&gt;
tar -czf $BACKUPFILE /home/$USER/&lt;br /&gt;
echo Backup completed for $USER saved to $BACKUPFILE&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable. Can you do this with a change to only one line?&lt;br /&gt;
* After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&lt;br /&gt;
&amp;lt;ul&amp;gt; It is important to note that while this script works, it&#039;s just a simple example and not well written because it is easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
Sometimes you want a program to do something over and over again several times. This is typically done using a loop. Let&#039;s say you wanted to create a bunch of sample files to do some further practice with in the current directory named &#039;&#039;sample-fileX.extension&#039;&#039; where &#039;&#039;X&#039;&#039; was a number that would keep incrementing by 1 each time and you could specify any extension you wanted. We could certainly use arguments to capture that user input but it is also possible to accept input from the user directly while the script is running. This would create what we call an &amp;quot;interactive&amp;quot; script because the user is interacting with it while it runs.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.sh&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
BASENAME=sample-file&lt;br /&gt;
echo &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
echo &amp;quot;Files will be created using the filename format &amp;quot;$BASENAME&amp;quot;X.extension&amp;quot;&lt;br /&gt;
echo &amp;quot;Enter the number of files you wish to create, then press Enter:&amp;quot;&lt;br /&gt;
read NUM&lt;br /&gt;
echo &amp;quot;Enter the extension (without the leading period) to put on the files&amp;quot;&lt;br /&gt;
read EXTENSION&lt;br /&gt;
for CURNUM in `seq 1 $NUM`; do&lt;br /&gt;
    touch $BASENAME$CURNUM.$EXTENSION&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Created &amp;quot;$NUM&amp;quot; file(s).&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a few things to note about this script. First, we have used one type of loop, a FOR loop, but there are others and other ways to make this work. Second you can see several more examples of calling another program inside your script. In this case we have used the &#039;&#039;&#039;read&#039;&#039;&#039;, &#039;&#039;&#039;seq&#039;&#039;&#039;, and &#039;&#039;&#039;touch&#039;&#039;&#039; programs to accomplish our goal. The &#039;&#039;&#039;seq&#039;&#039;&#039; program is especially useful while writing scripts. It can be used to generate a series of numbers from a starting number (1 in this case) to a stopping number (&#039;&#039;$NUM&#039;&#039; in this case). There are many other helpful programs you can use while writing scripts including some you know about already such as &#039;&#039;&#039;grep&#039;&#039;&#039; and &#039;&#039;&#039;find&#039;&#039;&#039;, and others you don&#039;t such as &#039;&#039;&#039;sed&#039;&#039;&#039; and &#039;&#039;&#039;awk&#039;&#039;&#039;. You can even use programs like &#039;&#039;&#039;wget&#039;&#039;&#039; to get information from the Internet and process it for use in a script instead of using it for just downloading a file. For example, if you know of a web site that lists the sunrise and sunset times you can use a combination of &#039;&#039;&#039;wget&#039;&#039;&#039; and &#039;&#039;&#039;grep&#039;&#039;&#039;/&#039;&#039;&#039;awk&#039;&#039;&#039;/&#039;&#039;&#039;sed&#039;&#039;&#039; to pull that time out of the webpage and use it as part of a script. The possibilities are almost endless, time spent learning about the ins and outs of these little utilities is time well spent if you will be writing shell scripts!&amp;lt;/li&amp;gt;&lt;br /&gt;
* Try running the script and see if you were correct about what it does and how it works.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: Also, it is important to note that while this script works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
* See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&lt;br /&gt;
* See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters &#039;&#039;N&#039;&#039; then do not create the files.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
One final programming structure we should discuss is the function. In shell scripting you can think of a function like something you could have put into a separate script so that you could call it to do something multiple times from inside of your script but instead of making it a completely separate file you decided to include it in a single script.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;  Here is a sample script using a function:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
function helloname {&lt;br /&gt;
    echo &amp;quot;Type your name, followed by enter:&amp;quot;&lt;br /&gt;
    read NAME&lt;br /&gt;
    echo &amp;quot;Hello &amp;quot;$NAME&amp;quot;!&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
echo &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname&lt;br /&gt;
echo &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname&lt;br /&gt;
echo &amp;quot;Thanks for playing!&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. Also, it&#039;s possible to pass information to a function using arguments just like you would with a separate script.&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of BASH scripting see if you can write a script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again. Also, loops can be used to operate on a list of things such as a list of filenames.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_13_mnjk&amp;diff=9444</id>
		<title>Lab 13 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_13_mnjk&amp;diff=9444"/>
		<updated>2021-02-15T06:33:33Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Using Loops and Reading User Input */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic BASH scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Have completed the reading on BASH scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple BASH Scripts ==&lt;br /&gt;
At their core BASH scripts are really just lists of commands which could have been entered directly into the command line but have been pre-entered into a file to be run later instead. We can see how this works by creating a couple of very simple BASH scripts which each just run a single command. Your ability to write BASH scripts that do something useful is really only limited by how well you know Linux commands and utilities which could be included in the script. The &#039;&#039;&#039;echo&#039;&#039;&#039; command can be used on your system to print information out to the standard output.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Lets try running a command echo on your computer:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;echo Hello World!&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You should see the text &amp;quot;Hello World!&amp;quot; printed out on the screen below your command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.sh&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
* In order to turn that command into a script we just need to put the command into a text file and add one more line, called a &#039;&#039;sha-bang&#039;&#039; because it is made up of a hash (pound) sign and a bang (exclamation) sign. This line tells the system what program to use to interpret the commands in the script. In this case we&#039;re going to be writing BASH scripts so we&#039;ll set it for the BASH program.&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
echo Hello World!&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.sh&#039;&#039; file to be executable by all users on the system so that we will be able to run it.&lt;br /&gt;
* &#039;&#039;NOTE: As a safety precaution against mistakenly executing something you don&#039;t really want to the shell will not allow you to run a file by just typing the filename, even if you are in the correct directory. The location of the file must either be included in your system&#039;s PATH, you must specify the full path to the file (such as &#039;&#039;&#039;/home/jsmith/hello.sh&#039;&#039;&#039;), or if you are in the correct directory already you can put in a relative path like &#039;&#039;&#039;./hello.sh&#039;&#039;&#039;. Remember, a single period is a shortcut which means the current directory so ./ means a file in the current working directory. Try running your &#039;&#039;hello.sh&#039;&#039; script now. If your system outputs &#039;&#039;Hello World!&#039;&#039; just like when you ran the &#039;&#039;&#039;echo&#039;&#039;&#039; command from the command line directly you have successfully written your first BASH script!&#039;&#039;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.sh&#039;&#039; which executes the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039; when the script is run.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in BASH Scripts ==&lt;br /&gt;
Variables are a key part of turning a simple list of instructions you could type into a command line into something much more powerful by allowing you to reuse code and do something very similar (remember programmers are lazy!) but with a little tweak each time without re-writing the whole thing. Variables can be defined in the script itself but there are also special variables which are part of the BASH environment we can use. Variables can be identified in bash scripts as starting with a &#039;&#039;$&#039;&#039;. One type of these variables allows us to access arguments which have been supplied as part of the command line calling the script. Sometimes we only want to run certain sections of the script or we want to modify the script depending on the outcome of some test, called a conditional. This is often used in combination with variables as we&#039;ll see in the example below. In BASH the script filename is assigned to the &#039;&#039;$0&#039;&#039; variable, the first argument to &#039;&#039;$1&#039;&#039; and so on. Let&#039;s see how we can modify our &#039;&#039;hello.sh&#039;&#039; script to make it a bit more personable by including a name.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.sh&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
echo Hello $1!&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
* Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try just running &#039;&#039;&#039;./hello.sh&#039;&#039;&#039; again and see what happens.&lt;br /&gt;
&amp;lt;ul&amp;gt; It might be the case that we want to go back to the simple &#039;&#039;Hello World!&#039;&#039; and maybe add some instructions if they don&#039;t specify an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.sh&#039;&#039; script again and adding a conditional like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can predict what these changes will do when the script is run and then try it out to see if you are correct.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
    echo Hello $1!&lt;br /&gt;
else&lt;br /&gt;
    echo Hello World!&lt;br /&gt;
    echo Try running $0 yourfirstnamehere to get a personal greeting!&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
* It&#039;s also possible to capture the standard output of a command executed by the script and put that into a variable for later use. For example, try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer.&lt;br /&gt;
&amp;lt;li&amp;gt;  Save this script as &#039;&#039;better-backup.sh&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=$(date +%Y%m%d)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;$USER&amp;quot;-backup-&amp;quot;$TODAY&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
echo Beginning backup for $USER on $TODAY&lt;br /&gt;
tar -czf $BACKUPFILE /home/$USER/&lt;br /&gt;
echo Backup completed for $USER saved to $BACKUPFILE&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable. Can you do this with a change to only one line?&lt;br /&gt;
* After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&lt;br /&gt;
&amp;lt;ul&amp;gt; It is important to note that while this script works, it&#039;s just a simple example and not well written because it is easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
Sometimes you want a program to do something over and over again several times. This is typically done using a loop. Let&#039;s say you wanted to create a bunch of sample files to do some further practice with in the current directory named &#039;&#039;sample-fileX.extension&#039;&#039; where &#039;&#039;X&#039;&#039; was a number that would keep incrementing by 1 each time and you could specify any extension you wanted. We could certainly use arguments to capture that user input but it is also possible to accept input from the user directly while the script is running. This would create what we call an &amp;quot;interactive&amp;quot; script because the user is interacting with it while it runs.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.sh&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
BASENAME=sample-file&lt;br /&gt;
echo &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
echo &amp;quot;Files will be created using the filename format &amp;quot;$BASENAME&amp;quot;X.extension&amp;quot;&lt;br /&gt;
echo &amp;quot;Enter the number of files you wish to create, then press Enter:&amp;quot;&lt;br /&gt;
read NUM&lt;br /&gt;
echo &amp;quot;Enter the extension (without the leading period) to put on the files&amp;quot;&lt;br /&gt;
read EXTENSION&lt;br /&gt;
for CURNUM in `seq 1 $NUM`; do&lt;br /&gt;
    touch $BASENAME$CURNUM.$EXTENSION&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Created &amp;quot;$NUM&amp;quot; file(s).&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a few things to note about this script. First, we have used one type of loop, a FOR loop, but there are others and other ways to make this work. Second you can see several more examples of calling another program inside your script. In this case we have used the &#039;&#039;&#039;read&#039;&#039;&#039;, &#039;&#039;&#039;seq&#039;&#039;&#039;, and &#039;&#039;&#039;touch&#039;&#039;&#039; programs to accomplish our goal. The &#039;&#039;&#039;seq&#039;&#039;&#039; program is especially useful while writing scripts. It can be used to generate a series of numbers from a starting number (1 in this case) to a stopping number (&#039;&#039;$NUM&#039;&#039; in this case). There are many other helpful programs you can use while writing scripts including some you know about already such as &#039;&#039;&#039;grep&#039;&#039;&#039; and &#039;&#039;&#039;find&#039;&#039;&#039;, and others you don&#039;t such as &#039;&#039;&#039;sed&#039;&#039;&#039; and &#039;&#039;&#039;awk&#039;&#039;&#039;. You can even use programs like &#039;&#039;&#039;wget&#039;&#039;&#039; to get information from the Internet and process it for use in a script instead of using it for just downloading a file. For example, if you know of a web site that lists the sunrise and sunset times you can use a combination of &#039;&#039;&#039;wget&#039;&#039;&#039; and &#039;&#039;&#039;grep&#039;&#039;&#039;/&#039;&#039;&#039;awk&#039;&#039;&#039;/&#039;&#039;&#039;sed&#039;&#039;&#039; to pull that time out of the webpage and use it as part of a script. The possibilities are almost endless, time spent learning about the ins and outs of these little utilities is time well spent if you will be writing shell scripts!&amp;lt;/li&amp;gt;&lt;br /&gt;
* Try running the script and see if you were correct about what it does and how it works.&lt;br /&gt;
&amp;lt;ul&amp;gt; &#039;&#039;NOTE: Also, it is important to note that while this script works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
* See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&lt;br /&gt;
* See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters &#039;&#039;N&#039;&#039; then do not create the files.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; One final programming structure we should discuss is the function. In shell scripting you can think of a function like something you could have put into a separate script so that you could call it to do something multiple times from inside of your script but instead of making it a completely separate file you decided to include it in a single script. Here is a simple sample:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
function helloname {&lt;br /&gt;
    echo &amp;quot;Type your name, followed by enter:&amp;quot;&lt;br /&gt;
    read NAME&lt;br /&gt;
    echo &amp;quot;Hello &amp;quot;$NAME&amp;quot;!&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
echo &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname&lt;br /&gt;
echo &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname&lt;br /&gt;
echo &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. Also, it&#039;s possible to pass information to a function using arguments just like you would with a separate script.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of BASH scripting see if you can write a script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again. Also, loops can be used to operate on a list of things such as a list of filenames.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_13_mnjk&amp;diff=9443</id>
		<title>Lab 13 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_13_mnjk&amp;diff=9443"/>
		<updated>2021-02-15T06:29:46Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Using Variables and Conditionals in BASH Scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic BASH scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Have completed the reading on BASH scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple BASH Scripts ==&lt;br /&gt;
At their core BASH scripts are really just lists of commands which could have been entered directly into the command line but have been pre-entered into a file to be run later instead. We can see how this works by creating a couple of very simple BASH scripts which each just run a single command. Your ability to write BASH scripts that do something useful is really only limited by how well you know Linux commands and utilities which could be included in the script. The &#039;&#039;&#039;echo&#039;&#039;&#039; command can be used on your system to print information out to the standard output.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Lets try running a command echo on your computer:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;echo Hello World!&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You should see the text &amp;quot;Hello World!&amp;quot; printed out on the screen below your command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.sh&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
* In order to turn that command into a script we just need to put the command into a text file and add one more line, called a &#039;&#039;sha-bang&#039;&#039; because it is made up of a hash (pound) sign and a bang (exclamation) sign. This line tells the system what program to use to interpret the commands in the script. In this case we&#039;re going to be writing BASH scripts so we&#039;ll set it for the BASH program.&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
echo Hello World!&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.sh&#039;&#039; file to be executable by all users on the system so that we will be able to run it.&lt;br /&gt;
* &#039;&#039;NOTE: As a safety precaution against mistakenly executing something you don&#039;t really want to the shell will not allow you to run a file by just typing the filename, even if you are in the correct directory. The location of the file must either be included in your system&#039;s PATH, you must specify the full path to the file (such as &#039;&#039;&#039;/home/jsmith/hello.sh&#039;&#039;&#039;), or if you are in the correct directory already you can put in a relative path like &#039;&#039;&#039;./hello.sh&#039;&#039;&#039;. Remember, a single period is a shortcut which means the current directory so ./ means a file in the current working directory. Try running your &#039;&#039;hello.sh&#039;&#039; script now. If your system outputs &#039;&#039;Hello World!&#039;&#039; just like when you ran the &#039;&#039;&#039;echo&#039;&#039;&#039; command from the command line directly you have successfully written your first BASH script!&#039;&#039;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.sh&#039;&#039; which executes the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039; when the script is run.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in BASH Scripts ==&lt;br /&gt;
Variables are a key part of turning a simple list of instructions you could type into a command line into something much more powerful by allowing you to reuse code and do something very similar (remember programmers are lazy!) but with a little tweak each time without re-writing the whole thing. Variables can be defined in the script itself but there are also special variables which are part of the BASH environment we can use. Variables can be identified in bash scripts as starting with a &#039;&#039;$&#039;&#039;. One type of these variables allows us to access arguments which have been supplied as part of the command line calling the script. Sometimes we only want to run certain sections of the script or we want to modify the script depending on the outcome of some test, called a conditional. This is often used in combination with variables as we&#039;ll see in the example below. In BASH the script filename is assigned to the &#039;&#039;$0&#039;&#039; variable, the first argument to &#039;&#039;$1&#039;&#039; and so on. Let&#039;s see how we can modify our &#039;&#039;hello.sh&#039;&#039; script to make it a bit more personable by including a name.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try adjusting your &#039;&#039;hello.sh&#039;&#039; script to look like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
echo Hello $1!&amp;lt;/pre&amp;gt;&lt;br /&gt;
* What do you think will happen if you run the script like this &#039;&#039;&#039;./hello yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&lt;br /&gt;
* Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try just running &#039;&#039;&#039;./hello.sh&#039;&#039;&#039; again and see what happens.&lt;br /&gt;
&amp;lt;ul&amp;gt; It might be the case that we want to go back to the simple &#039;&#039;Hello World!&#039;&#039; and maybe add some instructions if they don&#039;t specify an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try updating your &#039;&#039;hello.sh&#039;&#039; script again and adding a conditional like this:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can predict what these changes will do when the script is run and then try it out to see if you are correct.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
    echo Hello $1!&lt;br /&gt;
else&lt;br /&gt;
    echo Hello World!&lt;br /&gt;
    echo Try running $0 yourfirstnamehere to get a personal greeting!&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
* It&#039;s also possible to capture the standard output of a command executed by the script and put that into a variable for later use. For example, try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer.&lt;br /&gt;
&amp;lt;li&amp;gt;  Save this script as &#039;&#039;better-backup.sh&#039;&#039; with the appropriate permissions to run it as a script:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=$(date +%Y%m%d)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;$USER&amp;quot;-backup-&amp;quot;$TODAY&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
echo Beginning backup for $USER on $TODAY&lt;br /&gt;
tar -czf $BACKUPFILE /home/$USER/&lt;br /&gt;
echo Backup completed for $USER saved to $BACKUPFILE&amp;lt;/pre&amp;gt;&lt;br /&gt;
* See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable. Can you do this with a change to only one line?&lt;br /&gt;
* After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&lt;br /&gt;
&amp;lt;ul&amp;gt; It is important to note that while this script works, it&#039;s just a simple example and not well written because it is easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Sometimes you want a program to do something over and over again several times. This is typically done using a loop. Let&#039;s say you wanted to create a bunch of sample files to do some further practice with in the current directory named &#039;&#039;sample-fileX.extension&#039;&#039; where &#039;&#039;X&#039;&#039; was a number that would keep incrementing by 1 each time and you could specify any extension you wanted. We could certainly use arguments to capture that user input but it is also possible to accept input from the user directly while the script is running. This would create what we call an &amp;quot;interactive&amp;quot; script because the user is interacting with it while it runs.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.sh&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
BASENAME=sample-file&lt;br /&gt;
echo &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
echo &amp;quot;Files will be created using the filename format &amp;quot;$BASENAME&amp;quot;X.extension&amp;quot;&lt;br /&gt;
echo &amp;quot;Enter the number of files you wish to create, then press Enter:&amp;quot;&lt;br /&gt;
read NUM&lt;br /&gt;
echo &amp;quot;Enter the extension (without the leading period) to put on the files&amp;quot;&lt;br /&gt;
read EXTENSION&lt;br /&gt;
for CURNUM in `seq 1 $NUM`; do&lt;br /&gt;
    touch $BASENAME$CURNUM.$EXTENSION&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Created &amp;quot;$NUM&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a few things to note about this script. First, we have used one type of loop, a FOR loop, but there are others and other ways to make this work. Second you can see several more examples of calling another program inside your script. In this case we have used the &#039;&#039;&#039;read&#039;&#039;&#039;, &#039;&#039;&#039;seq&#039;&#039;&#039;, and &#039;&#039;&#039;touch&#039;&#039;&#039; programs to accomplish our goal. The &#039;&#039;&#039;seq&#039;&#039;&#039; program is especially useful while writing scripts. It can be used to generate a series of numbers from a starting number (1 in this case) to a stopping number (&#039;&#039;$NUM&#039;&#039; in this case). There are many other helpful programs you can use while writing scripts including some you know about already such as &#039;&#039;&#039;grep&#039;&#039;&#039; and &#039;&#039;&#039;find&#039;&#039;&#039;, and others you don&#039;t such as &#039;&#039;&#039;sed&#039;&#039;&#039; and &#039;&#039;&#039;awk&#039;&#039;&#039;. You can even use programs like &#039;&#039;&#039;wget&#039;&#039;&#039; to get information from the Internet and process it for use in a script instead of using it for just downloading a file. For example, if you know of a web site that lists the sunrise and sunset times you can use a combination of &#039;&#039;&#039;wget&#039;&#039;&#039; and &#039;&#039;&#039;grep&#039;&#039;&#039;/&#039;&#039;&#039;awk&#039;&#039;&#039;/&#039;&#039;&#039;sed&#039;&#039;&#039; to pull that time out of the webpage and use it as part of a script. The possibilities are almost endless, time spent learning about the ins and outs of these little utilities is time well spent if you will be writing shell scripts!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters &#039;&#039;N&#039;&#039; then do not create the files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; One final programming structure we should discuss is the function. In shell scripting you can think of a function like something you could have put into a separate script so that you could call it to do something multiple times from inside of your script but instead of making it a completely separate file you decided to include it in a single script. Here is a simple sample:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
function helloname {&lt;br /&gt;
    echo &amp;quot;Type your name, followed by enter:&amp;quot;&lt;br /&gt;
    read NAME&lt;br /&gt;
    echo &amp;quot;Hello &amp;quot;$NAME&amp;quot;!&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
echo &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname&lt;br /&gt;
echo &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname&lt;br /&gt;
echo &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. Also, it&#039;s possible to pass information to a function using arguments just like you would with a separate script.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of BASH scripting see if you can write a script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again. Also, loops can be used to operate on a list of things such as a list of filenames.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_13_mnjk&amp;diff=9442</id>
		<title>Lab 13 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_13_mnjk&amp;diff=9442"/>
		<updated>2021-02-15T06:05:23Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Creating Simple BASH Scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will create and modify some basic BASH scripts.&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Have completed the reading on BASH scripting. If you haven&#039;t done this you will almost certainly have difficulty completing the lab!&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
== Creating Simple BASH Scripts ==&lt;br /&gt;
At their core BASH scripts are really just lists of commands which could have been entered directly into the command line but have been pre-entered into a file to be run later instead. We can see how this works by creating a couple of very simple BASH scripts which each just run a single command. Your ability to write BASH scripts that do something useful is really only limited by how well you know Linux commands and utilities which could be included in the script. The &#039;&#039;&#039;echo&#039;&#039;&#039; command can be used on your system to print information out to the standard output.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Lets try running a command echo on your computer:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;echo Hello World!&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You should see the text &amp;quot;Hello World!&amp;quot; printed out on the screen below your command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a new text file named &#039;&#039;hello.sh&#039;&#039; with the following text:&amp;lt;/li&amp;gt;&lt;br /&gt;
* In order to turn that command into a script we just need to put the command into a text file and add one more line, called a &#039;&#039;sha-bang&#039;&#039; because it is made up of a hash (pound) sign and a bang (exclamation) sign. This line tells the system what program to use to interpret the commands in the script. In this case we&#039;re going to be writing BASH scripts so we&#039;ll set it for the BASH program.&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
echo Hello World!&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Set the &#039;&#039;hello.sh&#039;&#039; file to be executable by all users on the system so that we will be able to run it.&lt;br /&gt;
* &#039;&#039;NOTE: As a safety precaution against mistakenly executing something you don&#039;t really want to the shell will not allow you to run a file by just typing the filename, even if you are in the correct directory. The location of the file must either be included in your system&#039;s PATH, you must specify the full path to the file (such as &#039;&#039;&#039;/home/jsmith/hello.sh&#039;&#039;&#039;), or if you are in the correct directory already you can put in a relative path like &#039;&#039;&#039;./hello.sh&#039;&#039;&#039;. Remember, a single period is a shortcut which means the current directory so ./ means a file in the current working directory. Try running your &#039;&#039;hello.sh&#039;&#039; script now. If your system outputs &#039;&#039;Hello World!&#039;&#039; just like when you ran the &#039;&#039;&#039;echo&#039;&#039;&#039; command from the command line directly you have successfully written your first BASH script!&#039;&#039;&lt;br /&gt;
&amp;lt;li&amp;gt; Now try using what you have learned to create and test another script named &#039;&#039;simple-backup.sh&#039;&#039; which executes the command &#039;&#039;&#039;tar -czf /var/jsmith-backup.tar.gz /home/jsmith/&#039;&#039;&#039; when the script is run.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Variables and Conditionals in BASH Scripts ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Variables are a key part of turning a simple list of instructions you could type into a command line into something much more powerful by allowing you to reuse code and do something very similar (remember programmers are lazy!) but with a little tweak each time without re-writing the whole thing. Variables can be defined in the script itself but there are also special variables which are part of the BASH environment we can use. Variables can be identified in bash scripts as starting with a &#039;&#039;$&#039;&#039;. One type of these variables allows us to access arguments which have been supplied as part of the command line calling the script. Sometimes we only want to run certain sections of the script or we want to modify the script depending on the outcome of some test, called a conditional. This is often used in combination with variables as we&#039;ll see in the example below.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In BASH the script filename is assigned to the &#039;&#039;$0&#039;&#039; variable, the first argument to &#039;&#039;$1&#039;&#039; and so on. Let&#039;s see how we can modify our &#039;&#039;hello.sh&#039;&#039; script to make it a bit more personable by including a name. Try adjusting your &#039;&#039;hello.sh&#039;&#039; script to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
echo Hello $1!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What do you think will happen if you run the script like this &#039;&#039;&#039;./hello yourfirstname&#039;&#039;&#039;? Try it and find out if you were correct in your hypothesis!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Wait, what if someone doesn&#039;t know they are supposed to include their name as an argument though? Try just running &#039;&#039;&#039;./hello.sh&#039;&#039;&#039; again and see what happens. It might be the case that we want to go back to the simple &#039;&#039;Hello World!&#039;&#039; and maybe add some instructions if they don&#039;t specify an argument. Try updating your &#039;&#039;hello.sh&#039;&#039; script again and adding a conditional like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
    echo Hello $1!&lt;br /&gt;
else&lt;br /&gt;
    echo Hello World!&lt;br /&gt;
    echo Try running $0 yourfirstnamehere to get a personal greeting!&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what these changes will do when the script is run and then try it out to see if you are correct.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It&#039;s also possible to capture the standard output of a command executed by the script and put that into a variable for later use. For example, try running the &#039;&#039;&#039;date +%Y%m%d&#039;&#039;&#039; command.  We can use the output of this command in a variable to make our backup script a little bit nicer. Save this script as &#039;&#039;better-backup.sh&#039;&#039; with the appropriate permissions to run it as a script.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
USER=&amp;quot;jsmith&amp;quot;&lt;br /&gt;
TODAY=$(date +%Y%m%d)&lt;br /&gt;
BACKUPFILE=&amp;quot;/var/&amp;quot;$USER&amp;quot;-backup-&amp;quot;$TODAY&amp;quot;.tar.gz&amp;quot;&lt;br /&gt;
echo Beginning backup for $USER on $TODAY&lt;br /&gt;
tar -czf $BACKUPFILE /home/$USER/&lt;br /&gt;
echo Backup completed for $USER saved to $BACKUPFILE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can predict what this script will do and then try it out to see if you are correct. Once you have figured out how this script works see if you can modify it so you can specify a username as an argument instead of as a fixed variable. Can you do this with a change to only one line?&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; After successfully doing that try modifying the script so that it gives instructions about how to use the script if you forget to give a username as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; It is important to note that while this script works, it&#039;s just a simple example and not well written because it is easily broken by giving a username which doesn&#039;t actually exist on the system, or trying to backup files you don&#039;t have permission to access, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input such as an argument.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Loops and Reading User Input ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Sometimes you want a program to do something over and over again several times. This is typically done using a loop. Let&#039;s say you wanted to create a bunch of sample files to do some further practice with in the current directory named &#039;&#039;sample-fileX.extension&#039;&#039; where &#039;&#039;X&#039;&#039; was a number that would keep incrementing by 1 each time and you could specify any extension you wanted. We could certainly use arguments to capture that user input but it is also possible to accept input from the user directly while the script is running. This would create what we call an &amp;quot;interactive&amp;quot; script because the user is interacting with it while it runs.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a &#039;&#039;file-generator.sh&#039;&#039; script on your system like the one below and see if you can figure out how it works before testing it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
BASENAME=sample-file&lt;br /&gt;
echo &amp;quot;Welcome to the sample file generation utility!&amp;quot;&lt;br /&gt;
echo &amp;quot;Files will be created using the filename format &amp;quot;$BASENAME&amp;quot;X.extension&amp;quot;&lt;br /&gt;
echo &amp;quot;Enter the number of files you wish to create, then press Enter:&amp;quot;&lt;br /&gt;
read NUM&lt;br /&gt;
echo &amp;quot;Enter the extension (without the leading period) to put on the files&amp;quot;&lt;br /&gt;
read EXTENSION&lt;br /&gt;
for CURNUM in `seq 1 $NUM`; do&lt;br /&gt;
    touch $BASENAME$CURNUM.$EXTENSION&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Created &amp;quot;$NUM&amp;quot; file(s).&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are a few things to note about this script. First, we have used one type of loop, a FOR loop, but there are others and other ways to make this work. Second you can see several more examples of calling another program inside your script. In this case we have used the &#039;&#039;&#039;read&#039;&#039;&#039;, &#039;&#039;&#039;seq&#039;&#039;&#039;, and &#039;&#039;&#039;touch&#039;&#039;&#039; programs to accomplish our goal. The &#039;&#039;&#039;seq&#039;&#039;&#039; program is especially useful while writing scripts. It can be used to generate a series of numbers from a starting number (1 in this case) to a stopping number (&#039;&#039;$NUM&#039;&#039; in this case). There are many other helpful programs you can use while writing scripts including some you know about already such as &#039;&#039;&#039;grep&#039;&#039;&#039; and &#039;&#039;&#039;find&#039;&#039;&#039;, and others you don&#039;t such as &#039;&#039;&#039;sed&#039;&#039;&#039; and &#039;&#039;&#039;awk&#039;&#039;&#039;. You can even use programs like &#039;&#039;&#039;wget&#039;&#039;&#039; to get information from the Internet and process it for use in a script instead of using it for just downloading a file. For example, if you know of a web site that lists the sunrise and sunset times you can use a combination of &#039;&#039;&#039;wget&#039;&#039;&#039; and &#039;&#039;&#039;grep&#039;&#039;&#039;/&#039;&#039;&#039;awk&#039;&#039;&#039;/&#039;&#039;&#039;sed&#039;&#039;&#039; to pull that time out of the webpage and use it as part of a script. The possibilities are almost endless, time spent learning about the ins and outs of these little utilities is time well spent if you will be writing shell scripts!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Try running the script and see if you were correct about what it does and how it works.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Also, it is important to note that while this script works, it&#039;s just a simple example and not well written because it is easily broken by the user entering something other than a number for the number of files to be created, etc. A better script could be written to check for all of these things as well as other errors. If the script is to be used by more people than the original author (and in the best cases, even then) it is important for usability and security purposes to do these sorts of checks, particularly if the script accepts user input! This is how security bugs are born.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can modify the script so you can specify a starting and an ending number for the files rather than just a number of files to be created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See if you can add a check to the script which will display an example of a filename that will be created and asking the user if that looks correct before actually creating all the files. If the user enters &#039;&#039;N&#039;&#039; then do not create the files.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions and Experimenting ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; One final programming structure we should discuss is the function. In shell scripting you can think of a function like something you could have put into a separate script so that you could call it to do something multiple times from inside of your script but instead of making it a completely separate file you decided to include it in a single script. Here is a simple sample:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
function helloname {&lt;br /&gt;
    echo &amp;quot;Type your name, followed by enter:&amp;quot;&lt;br /&gt;
    read NAME&lt;br /&gt;
    echo &amp;quot;Hello &amp;quot;$NAME&amp;quot;!&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
echo &amp;quot;This program will welcome you twice to be extra nice!&amp;quot;&lt;br /&gt;
helloname&lt;br /&gt;
echo &amp;quot;At this point we could be doing lots of other stuff in our script or be in a loop, etc.&amp;quot;&lt;br /&gt;
helloname&lt;br /&gt;
echo &amp;quot;Thanks for playing!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can figure out what will happen when you run it, then try it out and see if you were correct. Note that functions need to be declared (listed) before you use them in your script so it would be common to see them at the beginning of the file as in this example. Also, it&#039;s possible to pass information to a function using arguments just like you would with a separate script.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Now that you have a grasp on the fundamentals of BASH scripting see if you can write a script which can be used to modify the name of all files in the current directory which share the same extension such as those created by &#039;&#039;file-generator.sh&#039;&#039;. The goals for your script should be:&lt;br /&gt;
* The user has a choice to enter the original and the new extension for the files either using command line arguments or interactively by answering questions your script asks.&lt;br /&gt;
* The script should display each old file name and then the new file name next to it so you can see what is going on&lt;br /&gt;
* You will want to use conditionals to figure out if the user entered arguments to use as the old and new extensions or should be prompted for them interactively.&lt;br /&gt;
* You should use functions and loops in order to make the most efficient script possible. Hints: The actual renaming of the files and displaying old and new names would be a good thing to put in a function because you will be calling it over and over again. Also, loops can be used to operate on a list of things such as a list of filenames.&lt;br /&gt;
Don&#039;t be afraid to try using search engines for help with this. The goal of this lab is not to make you into a professional programmer but to introduce you enough to shell scripting so that you can create useful scripts with resources such as search engines available to you.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=File:Bind_named_conf.png&amp;diff=9408</id>
		<title>File:Bind named conf.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=File:Bind_named_conf.png&amp;diff=9408"/>
		<updated>2021-02-13T03:08:45Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: KreidKolo uploaded a new version of File:Bind named conf.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9407</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9407"/>
		<updated>2021-02-13T03:06:21Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Install BIND &amp;amp; Enable Caching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
* You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
: [[File:Bind_named_conf.png | 500px]]&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
* Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
: [[File:Nslookup_inverhillsedu.png | 500px]]&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial - Adding an AAAA Record]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial - Adding a Delegated Domain]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial - Manually Editing a Zone File]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9402</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9402"/>
		<updated>2021-02-12T22:03:32Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Install BIND &amp;amp; Enable Caching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
: [[File:Bind_named_conf.png | 500px]]&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
: [[File:Nslookup_inverhillsedu.png | 500px]]&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial - Adding an AAAA Record]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial - Adding a Delegated Domain]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial - Manually Editing a Zone File]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9401</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9401"/>
		<updated>2021-02-12T22:03:20Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Install BIND &amp;amp; Enable Caching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
: [[File:Bind_named_conf.png | 500px]]&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
: [[File:Nslookup_inverhillsedu.png | 500px]]&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
Non-authoritative answer:&lt;br /&gt;
Name:	inverhills.edu&lt;br /&gt;
Address: 134.29.182.42&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial - Adding an AAAA Record]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial - Adding a Delegated Domain]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial - Manually Editing a Zone File]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9400</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9400"/>
		<updated>2021-02-12T22:02:57Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Install BIND &amp;amp; Enable Caching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
: [[File:Bind_named_conf.png | 500px]]&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
: [[Nslookup_inverhillsedu.png | 500px]]&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
Non-authoritative answer:&lt;br /&gt;
Name:	inverhills.edu&lt;br /&gt;
Address: 134.29.182.42&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial - Adding an AAAA Record]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial - Adding a Delegated Domain]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial - Manually Editing a Zone File]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=File:Nslookup_inverhillsedu.png&amp;diff=9399</id>
		<title>File:Nslookup inverhillsedu.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=File:Nslookup_inverhillsedu.png&amp;diff=9399"/>
		<updated>2021-02-12T22:02:31Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9398</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9398"/>
		<updated>2021-02-12T22:00:55Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Install BIND &amp;amp; Enable Caching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
: [[File:Bind_named_conf.png | 500px]]&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
Non-authoritative answer:&lt;br /&gt;
Name:	inverhills.edu&lt;br /&gt;
Address: 134.29.182.42&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial - Adding an AAAA Record]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial - Adding a Delegated Domain]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial - Manually Editing a Zone File]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9397</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9397"/>
		<updated>2021-02-12T22:00:03Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Install BIND &amp;amp; Enable Caching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
: [[File:Bind_named_conf.png | 500px]]&lt;br /&gt;
&amp;lt;pre&amp;gt;// forwarders {&lt;br /&gt;
//     0.0.0.0;&lt;br /&gt;
// };&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
Non-authoritative answer:&lt;br /&gt;
Name:	inverhills.edu&lt;br /&gt;
Address: 134.29.182.42&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial - Adding an AAAA Record]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial - Adding a Delegated Domain]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial - Manually Editing a Zone File]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=File:Bind_named_conf.png&amp;diff=9396</id>
		<title>File:Bind named conf.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=File:Bind_named_conf.png&amp;diff=9396"/>
		<updated>2021-02-12T21:50:13Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9395</id>
		<title>Lab 4 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9395"/>
		<updated>2021-02-12T21:44:52Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Working With Filesystem Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Linux is a very text file-oriented operating system. As we&#039;ve learned most of the settings for the operating system are held in text files in the /etc directory and most of the commands that are used to manipulate the system take text input or give text output. Beause of this it&#039;s very important to be able to edit and manipulate text on the system which will be a key focus of this lab. In addition, we&#039;ll practice creating compressed files, which is useful for backing up files, and creating links between locations on the system.&lt;br /&gt;
&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
* Edit text files using nano and vi&lt;br /&gt;
* Learn how to manipulate command output&lt;br /&gt;
* Search for files&lt;br /&gt;
* Archive and Compress files using tar&lt;br /&gt;
* Create links between directories&lt;br /&gt;
&lt;br /&gt;
You will use the following commands:&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/vi Vi]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nano Nano]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/cd cd]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ls ls]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/cat Cat]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/less Less]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/find Find]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/locate Locate]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/updatedb Updatedb]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/8/apt apt]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/1/tar tar]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ln Ln]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/pwd Pwd]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
==Prerequisites==&lt;br /&gt;
Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
==Text File Editing==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=LnVsTA8_mQo Video Tutorial - Text File Editing]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change to the &#039;&#039;/var/www/html&#039;&#039; directory which is where the Apache webserver stores it&#039;s site files by default.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Verify you can see an &#039;&#039;index.html&#039;&#039; file inside of this directory by listing the contents of the directory. Note who the &#039;&#039;owner&#039;&#039; and &#039;&#039;group owner&#039;&#039; of the file are.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Open up a web browser on your host computer and verify that you can browse to the IP address of your Linux system and still see the &amp;quot;It works&amp;quot; page that you saw in [[Franske ITC-2480 Lab 2#Install the Apache 2 Webserver|lab 2]] after installing Apache.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Before we start making any changes it&#039;s a good idea to save an unmodified copy of the file you&#039;ll be working on so make a copy of the &#039;&#039;index.html&#039;&#039; file and name the copy &#039;&#039;index.html.orig&#039;&#039; so that you can always copy it back if you make a mistake.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are many different text editors available for Linux but systems almost always include some version of &#039;&#039;&#039;vi&#039;&#039;&#039; or &#039;&#039;&#039;nano&#039;&#039;&#039; so those are the two we&#039;ll focus on.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; In your ssh window open the &#039;&#039;index.html&#039;&#039; file in nano.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;NOTE: Because your user does not own this file you may need to edit the file as the superuser.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nano index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:nano_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/d/d3/Nano_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:nano_index_html.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try navigating around the file with your arrow keys and changing the &amp;quot;Apache2 Debian Default Page&amp;quot; text at the top of the page to &amp;quot;Welcome to My Linux Webserver&amp;quot;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Basic instructions for using nano abound on the Internet. You can get a basic introduction [http://staffwww.fullcoll.edu/sedwards/Nano/IntroToNano.html here] but it basically comes down to the menu lines at the bottom of the screen showing what your options are. The ^ character is commonly used to indicate the CTRL key so to exit the program (you will be prompted to save changes if you have made any) press CTRL-X or to save without exiting press CTRL-O and follow the prompts at the bottom of the screen.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Save your file with the changed text and then reload the page in your browser on your host system to see if the changes have taken effect.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Experiment with some of the nano menu options such as cutting and &amp;quot;un-cutting&amp;quot; lines of text and searching/replacing text. Once you are comfortable with the nano editor save your changes and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Make a note of which user and group owns your &#039;&#039;index.html&#039;&#039; file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete your &#039;&#039;index.html&#039;&#039; file and copy your &#039;&#039;index.html.orig&#039;&#039; file back to &#039;&#039;index.html&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Try loading the website again and see if it&#039;s back to the original text. If you encounter an error it&#039;s possible that your &#039;&#039;index.html&#039;&#039; file is not readable by the webserver account so you should use the appropriate command to set the &#039;&#039;index.html&#039;&#039; file back to the owner and group of the original file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now open the &#039;&#039;index.html&#039;&#039; file in vi&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; vi index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[File:vi_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/f/fd/Vi_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[Media:vi_index_html.png| Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; The vi editor is probably considered more powerful than nano but is less user friendly without the menu at the bottom and a COMMAND mode as well as an INSERT mode. In the COMMAND mode you cannot directly change the text of the file by typing which can be frustrating to new users. Read through the vi tutorial [http://www.washington.edu/computing/unix/vi.html here] and try making some edits to your webpage. Once you are familiar with how the vi editor works save your file and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Command Output Manipulation==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dgC1r0rXTpA Video Tutorial - Command Output Manipulation]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change back to your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cd ~&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Print out the files in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run &#039;&#039;&#039;ls -al&#039;&#039;&#039; but redirect the output to a file using &#039;&#039;&amp;gt; filename&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al &amp;gt; listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how there is no command output. This is normal as you redirected the command output to the file &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; verify the contents of &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cat listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:cat_listfiles_txt.png|link=https://wiki.ihitc.net/mediawiki/images/e/e1/Cat_listfiles_txt.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:cat_listfiles_txt.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how it contains the exact same output as running &#039;&#039;&#039;ls -al&#039;&#039;&#039; on the command line.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ls -al /var/log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how many files there are in the &#039;&#039;/var/log&#039;&#039; directory. Lets say we wanted to just know the information of the &#039;&#039;debug&#039;&#039; log files. For this, we would use a pipe and the grep command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So, now run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep debug&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:var_log_grep_debug.png|link=https://wiki.ihitc.net/mediawiki/images/7/74/Var_log_grep_debug.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:var_log_grep_debug.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how the output is limited to all files that contain the string &#039;&#039;debug&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; TIP: Grep is very powerful. Here we&#039;re just using it to search for a string but you can use it to search regular expressions as well. We mentioned these in a previous lab too. You can learn more about regular expressions at [https://regexone.com RegexOne] and [https://www.regular-expressions.info Regular-Expressions.info] among many other places. These are frequently used in system administration and programming so it&#039;s worth your while to get at least a basic understanding of them.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Whats nice about pipes and redirects is that they can be used back to back on a command line creating a chain of programs which accept data as standard input and output it to the next program as standard output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So lets say we have a scenario where we want to get a file that contains all of the information from all &#039;&#039;.gz&#039;&#039; files in &#039;&#039;/var/log&#039;&#039;. To do this, we would run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep .gz &amp;gt; gzlogfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now pipe the file into &#039;&#039;&#039;less&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;cat gzlogfiles.txt | less&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; NOTE: Remember that you are now viewing the file in the less program and will need to quite the program to return to a command line. Type the letter &amp;quot;q&amp;quot; to quit the less program.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; In this case the piped &#039;&#039;&#039;cat&#039;&#039;&#039; command is the exact same as running &#039;&#039;&#039;less gzlogfiles.txt&#039;&#039;&#039; however there are many times where you need to connect two programs together with pipes in order to accomplish something which is otherwise not possible. Also, standard output can be non-text data as well. For example, it&#039;s possible to use pipes to pass audio data between programs such as one that scans a WAV file and adjusts the volume before piping it to an MP3 compression utility which saves the result as an MP3 file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; See if you can figure out how to view the output of &#039;&#039;&#039;ls -al /var/log | grep .gz&#039;&#039;&#039; one page at a time without dumping it to a text file first.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now remove the files &#039;&#039;gzlogfiles.txt&#039;&#039; and &#039;&#039;listfiles.txt&#039;&#039; that were created from this part of the lab.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for Files in Linux==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=WSd6fq-jDyE Video Tutorial - Searching for Files in Linux]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
There are several ways to search for files on a Linux system. The simplest is to use the &#039;&#039;&#039;find&#039;&#039;&#039; command which searches through the system directory by directory for files which match your search string. You can specify many options for the find command which do things such as restrict to searching in one particular directory and it&#039;s sub-directories, etc.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try searching your entire drive for files with syslog in the name. &lt;br /&gt;
    &amp;lt;code&amp;gt; find / -name syslog 2&amp;gt; /dev/null&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:find_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/9/96/Find_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:find_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice the &#039;&#039;2&amp;gt; /dev/null&#039;&#039; on the end of the command. This redirects error messages ( &#039;&#039;2&amp;gt;&#039;&#039; redirected stderr, &#039;&#039;&amp;gt;&#039;&#039; redirects stdout as discussed above) to the location &#039;&#039;/dev/null&#039;&#039; which is non-existing location/file where bits are just dropped from the system. The reason we&#039;re redirecting the error messages is that there are a number of files or directories which you may not have permission to access. Each attempt to access these by the &#039;&#039;&#039;find&#039;&#039;&#039; program would create an error message (so lots of errors). We&#039;re basically telling the system to hide these error messages from us.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see some files identified which contain the name &#039;&#039;syslog&#039;&#039;. The problem is that the find command is very slow at moving through all the files on the system, in fact it may even appear to be frozen while searching slowly though the drive. If you have waited a while and are still not getting back to a command prompt you can press CTRL-C to force the find program to quit and return to a command prompt. This means the find program works just fine for searching through a few directories/files (such as your home directory might contain) but is not the best choice for searching the entire system. If you want to learn more about advanced uses of the find command take a look at [http://content.hccfl.edu/pollock/unix/findcmd.htm this tutorial].&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; A faster way to search the entire system is to use the &#039;&#039;locate&#039;&#039; command. Install the &#039;&#039;&#039;locate&#039;&#039;&#039; program&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;This command searches a pre-built database of all files on the system which means it operates much faster than searching though files one at a time. There are two downsides to locate. First, it may not be pre-installed on many Linux systems so you may have to install it. Second, you need to build or update the database before you can search for files. New files are not automatically updated to the database so this only really works if you periodically remember to update the database. We&#039;ll explain how you can schedule that automatically in the future (hint, see the &#039;&#039;&#039;cron&#039;&#039;&#039; program).&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; sudo apt-get install locate&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create an updated database of files on your system&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;sudo updatedb&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Note, it will take a while for this program to find and index all the files on your system so give it a while to run. The advantage is after you do this you can search the database for many different files very quickly instead of waiting for each search as with the find command. We need to run the &#039;&#039;&#039;updatedb&#039;&#039;&#039; program as an administrator so that it can search though all locations on the system, including ones your user does not normally have access to.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note: Programs that may need to run for a long time and do not require user input (like &#039;&#039;&#039;updatedb&#039;&#039;&#039;) can be run in the background by placing an ampersand at the end of the command line like &#039;&#039;&#039;sudo updatedb&amp;amp;&#039;&#039;&#039;. This will immediately return you to a command prompt so you can continue to work on other things while the command finishes running.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Search for files with &#039;&#039;syslog&#039;&#039; in the name again but now using the command &#039;&#039;locate&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; locate syslog&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:locate_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/1/17/Locate_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:locate_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see many files found with this name and it should happen quickly, much faster than with the find command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating Archived/Compressed Files==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=iBsHKvNP88E Video Tutorial - Creating Archived Compressed Files]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding why &#039;&#039;&#039;tar&#039;&#039;&#039; is functioning in a certain way you can find a number of introductory tutorials [http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ like this one] about using &#039;&#039;&#039;tar&#039;&#039;&#039; on the Internet by [https://www.google.com/#q=tar+tutorial searching for them]&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a new directory &#039;&#039;experiments&#039;&#039; in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup1.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory by first changing your working directory to &#039;&#039;/var/log&#039;&#039; and then using the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup1.tar.gz *&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the asterisk (*) which is used to select all files in the current directory for inclusion in the TAR file. This is a type of wildcard character.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change your working directory to the &#039;&#039;experiments&#039;&#039; directory in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory. What happened? What kind of mess could this make when you extract a TAR file when it was created this way?&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try again to create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup2.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory. By running the command from inside the &#039;&#039;experiments&#039;&#039; directory.&lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf logbackup2.tar.gz /var/log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the lack of a slash at the end of the directory we are putting into the TAR file. In some older versions of TAR putting a slash on the end meant to put the files from that directory into the file but not the directory itself (just like when we created logbackup1.tar.gz with the asterisk wildcard). By leaving the slash off the end we are telling TAR to put the log directory,as well as it&#039;s contents, into the TAR file so that when we extract it we will get a log directory made with the files going into it. Even though new versions of TAR automatically prevent you from creating TAR files without a directory path it is still best practice to make sure that you are including a directory as part of the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; What happened? If you extracted a tar file made this way you could potentially end up with several more levels of directories than you really want. In this case we got an extra var directory inside of experiments but if we were archiving something with a deeper path we would have even more extra subdirectories. You can actually see this during the tar file creation if you have verbose output enabled you saw that all the files being added to the tar had var/log/ in front of the filename. There are at least two ways to handle this which we will look at.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If we are creating the TAR file manually we can avoid these extra parts to the path by paying attention to what directory we are in when we create the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; This time change your working directory to &#039;&#039;/var&#039;&#039; first and then run the command. &lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf ~/experiments/logbackup3.tar.gz log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the different output from the tar command. This time the filenames are prefixed only by &#039;&#039;log/&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup3.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should see that there is just one new subdirectory called log and all of the files are neatly placed inside of it. This is the type of extraction people normally want and expect from a tar file that is distributed.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Empty your &#039;&#039;experiments&#039;&#039; directory&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; If you want to have the same effect without changing your working directory that is possible too. Try running the command below.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup4.tar.gz -C /var log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;This time it doesn&#039;t make any difference which directory on the system because we have again specified a full path for where to save the tar file and we have also told tar to change to the &#039;&#039;/var&#039;&#039; directory before adding the log directory to the file using the -C argument. This automates the process of manually changing directories like we did above.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup4.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should again see that there is just one new subdirectory called &#039;&#039;log&#039;&#039; and all of the files are neatly placed inside of it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are a number of other things you can do with &#039;&#039;&#039;tar&#039;&#039;&#039; such as creating slower but more highly compressed .bz2 bzip files, extracting single files (or directories or groups of files) from an archive, listing the contents of an archive without extracting (which can show you if a new subdirectory will be created), adding files to an existing archive, and preserving file ownership (only by extracting on the same system though) and permissions. You should read the manual page for tar and then try practicing some of these and be familiar with the many ways that &#039;&#039;&#039;tar&#039;&#039;&#039; can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Working With Filesystem Links==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=vBorZKMmvIk Video Tutorial - Working With Filesystem Links]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding how links are functioning in a certain way you can find a number of introductory tutorials [http://www.nixtutor.com/freebsd/understanding-symbolic-links/ like this one] or [http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/ more advanced tutorials] on the Internet by searching for them.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Use root privileges to create a new directory inside the &#039;&#039;var&#039;&#039; directory called &#039;&#039;system-documentation&#039;&#039; and change the ownership permissions so that your standard user has permission to read, write, and execute as a member of a group which owns the documentation directory. You will also need to make sure that all system users have execute permission for the parent directory (&#039;&#039;/var&#039;&#039;) in order to access anything in it including the &#039;&#039;system-documentation&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Instead of needing to go into the &#039;&#039;/var/-system-documentation&#039;&#039; directory all the time it would be more convenient if your user was able to reach that directory through a link in their own home directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Run the command below inside your regular user&#039;s home directory&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ln -s /var/system-documentation documentation&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:ln_documentation.png|link=https://wiki.ihitc.net/mediawiki/images/9/97/Ln_documentation.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:ln_documentation.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Or if you&#039;re in a different working directory you can run the command as &#039;&#039;&#039;ln -s /var/system-documentation ~/documentation&#039;&#039;&#039; Do you understand why?&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should now see a soft link (also called symlink) in your home directory called documentation which points to the &#039;&#039;/var/system-documentation&#039;&#039; folder.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &#039;&#039;&#039;cd&#039;&#039;&#039; into the link just like it was a real directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you use the &#039;&#039;&#039;pwd&#039;&#039;&#039; command to print your working directory while inside the link it will look like it&#039;s a directory. Almost all software on the system will interact with the link just as if it&#039;s a real directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try creating some files and subdirectories inside of the link and then verify they are showing up in the real &#039;&#039;/var/system-documentation&#039;&#039; location as well. This should work correctly if your permissions are all set correctly.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Remove the link&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;rm ~/documentation&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see that all of the files you created are still in &#039;&#039;/var/system-documentation&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you re-create the link you should be able to go back into &#039;&#039;~/documentation&#039;&#039; and remove files and directories and see they are removed from the actual &#039;&#039;/var/system-documentation&#039;&#039; directory as well&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You can also practice creating links to specific files as well as directories. Links do not override permissions so you need to have permission to read, write or execute the file or directory you are linking to just like if you actually changed to the real location of the item. Go ahead and practice creating and removing links until you have a good understanding of how links can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Note: If you are using &#039;&#039;&#039;tar&#039;&#039;&#039; to back up data, depending on exactly what you want to do you may want to use the &#039;&#039;-h&#039;&#039; or &#039;&#039;--dereference&#039;&#039; option which will follow the symlink and backup the data it contains. Normal behavior for tar would just be to back up the link itslef, not the file(s) pointed to by the link. You should try creating some tar files of directories which contain symlinks, deleting the data the symlink points to and the extracting the tar file to some new location to see this in action if you are not confident that you understand this.&lt;br /&gt;
&lt;br /&gt;
=Checking your Work=&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Testing your work goes here&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; Commands to use&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Description of what you should see&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9394</id>
		<title>Lab 4 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9394"/>
		<updated>2021-02-12T21:44:41Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Creating Archived/Compressed Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Linux is a very text file-oriented operating system. As we&#039;ve learned most of the settings for the operating system are held in text files in the /etc directory and most of the commands that are used to manipulate the system take text input or give text output. Beause of this it&#039;s very important to be able to edit and manipulate text on the system which will be a key focus of this lab. In addition, we&#039;ll practice creating compressed files, which is useful for backing up files, and creating links between locations on the system.&lt;br /&gt;
&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
* Edit text files using nano and vi&lt;br /&gt;
* Learn how to manipulate command output&lt;br /&gt;
* Search for files&lt;br /&gt;
* Archive and Compress files using tar&lt;br /&gt;
* Create links between directories&lt;br /&gt;
&lt;br /&gt;
You will use the following commands:&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/vi Vi]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nano Nano]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/cd cd]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ls ls]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/cat Cat]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/less Less]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/find Find]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/locate Locate]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/updatedb Updatedb]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/8/apt apt]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/1/tar tar]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ln Ln]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/pwd Pwd]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
==Prerequisites==&lt;br /&gt;
Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
==Text File Editing==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=LnVsTA8_mQo Video Tutorial - Text File Editing]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change to the &#039;&#039;/var/www/html&#039;&#039; directory which is where the Apache webserver stores it&#039;s site files by default.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Verify you can see an &#039;&#039;index.html&#039;&#039; file inside of this directory by listing the contents of the directory. Note who the &#039;&#039;owner&#039;&#039; and &#039;&#039;group owner&#039;&#039; of the file are.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Open up a web browser on your host computer and verify that you can browse to the IP address of your Linux system and still see the &amp;quot;It works&amp;quot; page that you saw in [[Franske ITC-2480 Lab 2#Install the Apache 2 Webserver|lab 2]] after installing Apache.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Before we start making any changes it&#039;s a good idea to save an unmodified copy of the file you&#039;ll be working on so make a copy of the &#039;&#039;index.html&#039;&#039; file and name the copy &#039;&#039;index.html.orig&#039;&#039; so that you can always copy it back if you make a mistake.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are many different text editors available for Linux but systems almost always include some version of &#039;&#039;&#039;vi&#039;&#039;&#039; or &#039;&#039;&#039;nano&#039;&#039;&#039; so those are the two we&#039;ll focus on.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; In your ssh window open the &#039;&#039;index.html&#039;&#039; file in nano.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;NOTE: Because your user does not own this file you may need to edit the file as the superuser.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nano index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:nano_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/d/d3/Nano_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:nano_index_html.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try navigating around the file with your arrow keys and changing the &amp;quot;Apache2 Debian Default Page&amp;quot; text at the top of the page to &amp;quot;Welcome to My Linux Webserver&amp;quot;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Basic instructions for using nano abound on the Internet. You can get a basic introduction [http://staffwww.fullcoll.edu/sedwards/Nano/IntroToNano.html here] but it basically comes down to the menu lines at the bottom of the screen showing what your options are. The ^ character is commonly used to indicate the CTRL key so to exit the program (you will be prompted to save changes if you have made any) press CTRL-X or to save without exiting press CTRL-O and follow the prompts at the bottom of the screen.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Save your file with the changed text and then reload the page in your browser on your host system to see if the changes have taken effect.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Experiment with some of the nano menu options such as cutting and &amp;quot;un-cutting&amp;quot; lines of text and searching/replacing text. Once you are comfortable with the nano editor save your changes and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Make a note of which user and group owns your &#039;&#039;index.html&#039;&#039; file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete your &#039;&#039;index.html&#039;&#039; file and copy your &#039;&#039;index.html.orig&#039;&#039; file back to &#039;&#039;index.html&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Try loading the website again and see if it&#039;s back to the original text. If you encounter an error it&#039;s possible that your &#039;&#039;index.html&#039;&#039; file is not readable by the webserver account so you should use the appropriate command to set the &#039;&#039;index.html&#039;&#039; file back to the owner and group of the original file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now open the &#039;&#039;index.html&#039;&#039; file in vi&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; vi index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[File:vi_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/f/fd/Vi_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[Media:vi_index_html.png| Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; The vi editor is probably considered more powerful than nano but is less user friendly without the menu at the bottom and a COMMAND mode as well as an INSERT mode. In the COMMAND mode you cannot directly change the text of the file by typing which can be frustrating to new users. Read through the vi tutorial [http://www.washington.edu/computing/unix/vi.html here] and try making some edits to your webpage. Once you are familiar with how the vi editor works save your file and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Command Output Manipulation==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dgC1r0rXTpA Video Tutorial - Command Output Manipulation]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change back to your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cd ~&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Print out the files in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run &#039;&#039;&#039;ls -al&#039;&#039;&#039; but redirect the output to a file using &#039;&#039;&amp;gt; filename&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al &amp;gt; listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how there is no command output. This is normal as you redirected the command output to the file &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; verify the contents of &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cat listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:cat_listfiles_txt.png|link=https://wiki.ihitc.net/mediawiki/images/e/e1/Cat_listfiles_txt.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:cat_listfiles_txt.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how it contains the exact same output as running &#039;&#039;&#039;ls -al&#039;&#039;&#039; on the command line.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ls -al /var/log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how many files there are in the &#039;&#039;/var/log&#039;&#039; directory. Lets say we wanted to just know the information of the &#039;&#039;debug&#039;&#039; log files. For this, we would use a pipe and the grep command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So, now run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep debug&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:var_log_grep_debug.png|link=https://wiki.ihitc.net/mediawiki/images/7/74/Var_log_grep_debug.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:var_log_grep_debug.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how the output is limited to all files that contain the string &#039;&#039;debug&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; TIP: Grep is very powerful. Here we&#039;re just using it to search for a string but you can use it to search regular expressions as well. We mentioned these in a previous lab too. You can learn more about regular expressions at [https://regexone.com RegexOne] and [https://www.regular-expressions.info Regular-Expressions.info] among many other places. These are frequently used in system administration and programming so it&#039;s worth your while to get at least a basic understanding of them.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Whats nice about pipes and redirects is that they can be used back to back on a command line creating a chain of programs which accept data as standard input and output it to the next program as standard output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So lets say we have a scenario where we want to get a file that contains all of the information from all &#039;&#039;.gz&#039;&#039; files in &#039;&#039;/var/log&#039;&#039;. To do this, we would run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep .gz &amp;gt; gzlogfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now pipe the file into &#039;&#039;&#039;less&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;cat gzlogfiles.txt | less&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; NOTE: Remember that you are now viewing the file in the less program and will need to quite the program to return to a command line. Type the letter &amp;quot;q&amp;quot; to quit the less program.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; In this case the piped &#039;&#039;&#039;cat&#039;&#039;&#039; command is the exact same as running &#039;&#039;&#039;less gzlogfiles.txt&#039;&#039;&#039; however there are many times where you need to connect two programs together with pipes in order to accomplish something which is otherwise not possible. Also, standard output can be non-text data as well. For example, it&#039;s possible to use pipes to pass audio data between programs such as one that scans a WAV file and adjusts the volume before piping it to an MP3 compression utility which saves the result as an MP3 file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; See if you can figure out how to view the output of &#039;&#039;&#039;ls -al /var/log | grep .gz&#039;&#039;&#039; one page at a time without dumping it to a text file first.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now remove the files &#039;&#039;gzlogfiles.txt&#039;&#039; and &#039;&#039;listfiles.txt&#039;&#039; that were created from this part of the lab.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for Files in Linux==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=WSd6fq-jDyE Video Tutorial - Searching for Files in Linux]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
There are several ways to search for files on a Linux system. The simplest is to use the &#039;&#039;&#039;find&#039;&#039;&#039; command which searches through the system directory by directory for files which match your search string. You can specify many options for the find command which do things such as restrict to searching in one particular directory and it&#039;s sub-directories, etc.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try searching your entire drive for files with syslog in the name. &lt;br /&gt;
    &amp;lt;code&amp;gt; find / -name syslog 2&amp;gt; /dev/null&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:find_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/9/96/Find_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:find_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice the &#039;&#039;2&amp;gt; /dev/null&#039;&#039; on the end of the command. This redirects error messages ( &#039;&#039;2&amp;gt;&#039;&#039; redirected stderr, &#039;&#039;&amp;gt;&#039;&#039; redirects stdout as discussed above) to the location &#039;&#039;/dev/null&#039;&#039; which is non-existing location/file where bits are just dropped from the system. The reason we&#039;re redirecting the error messages is that there are a number of files or directories which you may not have permission to access. Each attempt to access these by the &#039;&#039;&#039;find&#039;&#039;&#039; program would create an error message (so lots of errors). We&#039;re basically telling the system to hide these error messages from us.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see some files identified which contain the name &#039;&#039;syslog&#039;&#039;. The problem is that the find command is very slow at moving through all the files on the system, in fact it may even appear to be frozen while searching slowly though the drive. If you have waited a while and are still not getting back to a command prompt you can press CTRL-C to force the find program to quit and return to a command prompt. This means the find program works just fine for searching through a few directories/files (such as your home directory might contain) but is not the best choice for searching the entire system. If you want to learn more about advanced uses of the find command take a look at [http://content.hccfl.edu/pollock/unix/findcmd.htm this tutorial].&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; A faster way to search the entire system is to use the &#039;&#039;locate&#039;&#039; command. Install the &#039;&#039;&#039;locate&#039;&#039;&#039; program&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;This command searches a pre-built database of all files on the system which means it operates much faster than searching though files one at a time. There are two downsides to locate. First, it may not be pre-installed on many Linux systems so you may have to install it. Second, you need to build or update the database before you can search for files. New files are not automatically updated to the database so this only really works if you periodically remember to update the database. We&#039;ll explain how you can schedule that automatically in the future (hint, see the &#039;&#039;&#039;cron&#039;&#039;&#039; program).&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; sudo apt-get install locate&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create an updated database of files on your system&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;sudo updatedb&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Note, it will take a while for this program to find and index all the files on your system so give it a while to run. The advantage is after you do this you can search the database for many different files very quickly instead of waiting for each search as with the find command. We need to run the &#039;&#039;&#039;updatedb&#039;&#039;&#039; program as an administrator so that it can search though all locations on the system, including ones your user does not normally have access to.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note: Programs that may need to run for a long time and do not require user input (like &#039;&#039;&#039;updatedb&#039;&#039;&#039;) can be run in the background by placing an ampersand at the end of the command line like &#039;&#039;&#039;sudo updatedb&amp;amp;&#039;&#039;&#039;. This will immediately return you to a command prompt so you can continue to work on other things while the command finishes running.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Search for files with &#039;&#039;syslog&#039;&#039; in the name again but now using the command &#039;&#039;locate&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; locate syslog&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:locate_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/1/17/Locate_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:locate_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see many files found with this name and it should happen quickly, much faster than with the find command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating Archived/Compressed Files==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=iBsHKvNP88E Video Tutorial - Creating Archived Compressed Files]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding why &#039;&#039;&#039;tar&#039;&#039;&#039; is functioning in a certain way you can find a number of introductory tutorials [http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ like this one] about using &#039;&#039;&#039;tar&#039;&#039;&#039; on the Internet by [https://www.google.com/#q=tar+tutorial searching for them]&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a new directory &#039;&#039;experiments&#039;&#039; in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup1.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory by first changing your working directory to &#039;&#039;/var/log&#039;&#039; and then using the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup1.tar.gz *&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the asterisk (*) which is used to select all files in the current directory for inclusion in the TAR file. This is a type of wildcard character.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change your working directory to the &#039;&#039;experiments&#039;&#039; directory in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory. What happened? What kind of mess could this make when you extract a TAR file when it was created this way?&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try again to create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup2.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory. By running the command from inside the &#039;&#039;experiments&#039;&#039; directory.&lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf logbackup2.tar.gz /var/log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the lack of a slash at the end of the directory we are putting into the TAR file. In some older versions of TAR putting a slash on the end meant to put the files from that directory into the file but not the directory itself (just like when we created logbackup1.tar.gz with the asterisk wildcard). By leaving the slash off the end we are telling TAR to put the log directory,as well as it&#039;s contents, into the TAR file so that when we extract it we will get a log directory made with the files going into it. Even though new versions of TAR automatically prevent you from creating TAR files without a directory path it is still best practice to make sure that you are including a directory as part of the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; What happened? If you extracted a tar file made this way you could potentially end up with several more levels of directories than you really want. In this case we got an extra var directory inside of experiments but if we were archiving something with a deeper path we would have even more extra subdirectories. You can actually see this during the tar file creation if you have verbose output enabled you saw that all the files being added to the tar had var/log/ in front of the filename. There are at least two ways to handle this which we will look at.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If we are creating the TAR file manually we can avoid these extra parts to the path by paying attention to what directory we are in when we create the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; This time change your working directory to &#039;&#039;/var&#039;&#039; first and then run the command. &lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf ~/experiments/logbackup3.tar.gz log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the different output from the tar command. This time the filenames are prefixed only by &#039;&#039;log/&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup3.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should see that there is just one new subdirectory called log and all of the files are neatly placed inside of it. This is the type of extraction people normally want and expect from a tar file that is distributed.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Empty your &#039;&#039;experiments&#039;&#039; directory&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; If you want to have the same effect without changing your working directory that is possible too. Try running the command below.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup4.tar.gz -C /var log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;This time it doesn&#039;t make any difference which directory on the system because we have again specified a full path for where to save the tar file and we have also told tar to change to the &#039;&#039;/var&#039;&#039; directory before adding the log directory to the file using the -C argument. This automates the process of manually changing directories like we did above.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup4.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should again see that there is just one new subdirectory called &#039;&#039;log&#039;&#039; and all of the files are neatly placed inside of it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are a number of other things you can do with &#039;&#039;&#039;tar&#039;&#039;&#039; such as creating slower but more highly compressed .bz2 bzip files, extracting single files (or directories or groups of files) from an archive, listing the contents of an archive without extracting (which can show you if a new subdirectory will be created), adding files to an existing archive, and preserving file ownership (only by extracting on the same system though) and permissions. You should read the manual page for tar and then try practicing some of these and be familiar with the many ways that &#039;&#039;&#039;tar&#039;&#039;&#039; can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Working With Filesystem Links==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=vBorZKMmvIk Video Tutorial: Working With Filesystem Links]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding how links are functioning in a certain way you can find a number of introductory tutorials [http://www.nixtutor.com/freebsd/understanding-symbolic-links/ like this one] or [http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/ more advanced tutorials] on the Internet by searching for them.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Use root privileges to create a new directory inside the &#039;&#039;var&#039;&#039; directory called &#039;&#039;system-documentation&#039;&#039; and change the ownership permissions so that your standard user has permission to read, write, and execute as a member of a group which owns the documentation directory. You will also need to make sure that all system users have execute permission for the parent directory (&#039;&#039;/var&#039;&#039;) in order to access anything in it including the &#039;&#039;system-documentation&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Instead of needing to go into the &#039;&#039;/var/-system-documentation&#039;&#039; directory all the time it would be more convenient if your user was able to reach that directory through a link in their own home directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Run the command below inside your regular user&#039;s home directory&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ln -s /var/system-documentation documentation&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:ln_documentation.png|link=https://wiki.ihitc.net/mediawiki/images/9/97/Ln_documentation.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:ln_documentation.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Or if you&#039;re in a different working directory you can run the command as &#039;&#039;&#039;ln -s /var/system-documentation ~/documentation&#039;&#039;&#039; Do you understand why?&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should now see a soft link (also called symlink) in your home directory called documentation which points to the &#039;&#039;/var/system-documentation&#039;&#039; folder.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &#039;&#039;&#039;cd&#039;&#039;&#039; into the link just like it was a real directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you use the &#039;&#039;&#039;pwd&#039;&#039;&#039; command to print your working directory while inside the link it will look like it&#039;s a directory. Almost all software on the system will interact with the link just as if it&#039;s a real directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try creating some files and subdirectories inside of the link and then verify they are showing up in the real &#039;&#039;/var/system-documentation&#039;&#039; location as well. This should work correctly if your permissions are all set correctly.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Remove the link&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;rm ~/documentation&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see that all of the files you created are still in &#039;&#039;/var/system-documentation&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you re-create the link you should be able to go back into &#039;&#039;~/documentation&#039;&#039; and remove files and directories and see they are removed from the actual &#039;&#039;/var/system-documentation&#039;&#039; directory as well&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You can also practice creating links to specific files as well as directories. Links do not override permissions so you need to have permission to read, write or execute the file or directory you are linking to just like if you actually changed to the real location of the item. Go ahead and practice creating and removing links until you have a good understanding of how links can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Note: If you are using &#039;&#039;&#039;tar&#039;&#039;&#039; to back up data, depending on exactly what you want to do you may want to use the &#039;&#039;-h&#039;&#039; or &#039;&#039;--dereference&#039;&#039; option which will follow the symlink and backup the data it contains. Normal behavior for tar would just be to back up the link itslef, not the file(s) pointed to by the link. You should try creating some tar files of directories which contain symlinks, deleting the data the symlink points to and the extracting the tar file to some new location to see this in action if you are not confident that you understand this.&lt;br /&gt;
&lt;br /&gt;
=Checking your Work=&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Testing your work goes here&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; Commands to use&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Description of what you should see&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9393</id>
		<title>Lab 4 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9393"/>
		<updated>2021-02-12T21:44:29Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Searching for Files in Linux */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Linux is a very text file-oriented operating system. As we&#039;ve learned most of the settings for the operating system are held in text files in the /etc directory and most of the commands that are used to manipulate the system take text input or give text output. Beause of this it&#039;s very important to be able to edit and manipulate text on the system which will be a key focus of this lab. In addition, we&#039;ll practice creating compressed files, which is useful for backing up files, and creating links between locations on the system.&lt;br /&gt;
&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
* Edit text files using nano and vi&lt;br /&gt;
* Learn how to manipulate command output&lt;br /&gt;
* Search for files&lt;br /&gt;
* Archive and Compress files using tar&lt;br /&gt;
* Create links between directories&lt;br /&gt;
&lt;br /&gt;
You will use the following commands:&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/vi Vi]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nano Nano]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/cd cd]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ls ls]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/cat Cat]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/less Less]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/find Find]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/locate Locate]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/updatedb Updatedb]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/8/apt apt]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/1/tar tar]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ln Ln]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/pwd Pwd]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
==Prerequisites==&lt;br /&gt;
Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
==Text File Editing==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=LnVsTA8_mQo Video Tutorial - Text File Editing]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change to the &#039;&#039;/var/www/html&#039;&#039; directory which is where the Apache webserver stores it&#039;s site files by default.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Verify you can see an &#039;&#039;index.html&#039;&#039; file inside of this directory by listing the contents of the directory. Note who the &#039;&#039;owner&#039;&#039; and &#039;&#039;group owner&#039;&#039; of the file are.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Open up a web browser on your host computer and verify that you can browse to the IP address of your Linux system and still see the &amp;quot;It works&amp;quot; page that you saw in [[Franske ITC-2480 Lab 2#Install the Apache 2 Webserver|lab 2]] after installing Apache.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Before we start making any changes it&#039;s a good idea to save an unmodified copy of the file you&#039;ll be working on so make a copy of the &#039;&#039;index.html&#039;&#039; file and name the copy &#039;&#039;index.html.orig&#039;&#039; so that you can always copy it back if you make a mistake.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are many different text editors available for Linux but systems almost always include some version of &#039;&#039;&#039;vi&#039;&#039;&#039; or &#039;&#039;&#039;nano&#039;&#039;&#039; so those are the two we&#039;ll focus on.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; In your ssh window open the &#039;&#039;index.html&#039;&#039; file in nano.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;NOTE: Because your user does not own this file you may need to edit the file as the superuser.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nano index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:nano_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/d/d3/Nano_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:nano_index_html.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try navigating around the file with your arrow keys and changing the &amp;quot;Apache2 Debian Default Page&amp;quot; text at the top of the page to &amp;quot;Welcome to My Linux Webserver&amp;quot;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Basic instructions for using nano abound on the Internet. You can get a basic introduction [http://staffwww.fullcoll.edu/sedwards/Nano/IntroToNano.html here] but it basically comes down to the menu lines at the bottom of the screen showing what your options are. The ^ character is commonly used to indicate the CTRL key so to exit the program (you will be prompted to save changes if you have made any) press CTRL-X or to save without exiting press CTRL-O and follow the prompts at the bottom of the screen.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Save your file with the changed text and then reload the page in your browser on your host system to see if the changes have taken effect.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Experiment with some of the nano menu options such as cutting and &amp;quot;un-cutting&amp;quot; lines of text and searching/replacing text. Once you are comfortable with the nano editor save your changes and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Make a note of which user and group owns your &#039;&#039;index.html&#039;&#039; file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete your &#039;&#039;index.html&#039;&#039; file and copy your &#039;&#039;index.html.orig&#039;&#039; file back to &#039;&#039;index.html&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Try loading the website again and see if it&#039;s back to the original text. If you encounter an error it&#039;s possible that your &#039;&#039;index.html&#039;&#039; file is not readable by the webserver account so you should use the appropriate command to set the &#039;&#039;index.html&#039;&#039; file back to the owner and group of the original file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now open the &#039;&#039;index.html&#039;&#039; file in vi&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; vi index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[File:vi_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/f/fd/Vi_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[Media:vi_index_html.png| Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; The vi editor is probably considered more powerful than nano but is less user friendly without the menu at the bottom and a COMMAND mode as well as an INSERT mode. In the COMMAND mode you cannot directly change the text of the file by typing which can be frustrating to new users. Read through the vi tutorial [http://www.washington.edu/computing/unix/vi.html here] and try making some edits to your webpage. Once you are familiar with how the vi editor works save your file and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Command Output Manipulation==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dgC1r0rXTpA Video Tutorial - Command Output Manipulation]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change back to your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cd ~&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Print out the files in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run &#039;&#039;&#039;ls -al&#039;&#039;&#039; but redirect the output to a file using &#039;&#039;&amp;gt; filename&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al &amp;gt; listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how there is no command output. This is normal as you redirected the command output to the file &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; verify the contents of &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cat listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:cat_listfiles_txt.png|link=https://wiki.ihitc.net/mediawiki/images/e/e1/Cat_listfiles_txt.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:cat_listfiles_txt.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how it contains the exact same output as running &#039;&#039;&#039;ls -al&#039;&#039;&#039; on the command line.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ls -al /var/log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how many files there are in the &#039;&#039;/var/log&#039;&#039; directory. Lets say we wanted to just know the information of the &#039;&#039;debug&#039;&#039; log files. For this, we would use a pipe and the grep command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So, now run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep debug&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:var_log_grep_debug.png|link=https://wiki.ihitc.net/mediawiki/images/7/74/Var_log_grep_debug.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:var_log_grep_debug.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how the output is limited to all files that contain the string &#039;&#039;debug&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; TIP: Grep is very powerful. Here we&#039;re just using it to search for a string but you can use it to search regular expressions as well. We mentioned these in a previous lab too. You can learn more about regular expressions at [https://regexone.com RegexOne] and [https://www.regular-expressions.info Regular-Expressions.info] among many other places. These are frequently used in system administration and programming so it&#039;s worth your while to get at least a basic understanding of them.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Whats nice about pipes and redirects is that they can be used back to back on a command line creating a chain of programs which accept data as standard input and output it to the next program as standard output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So lets say we have a scenario where we want to get a file that contains all of the information from all &#039;&#039;.gz&#039;&#039; files in &#039;&#039;/var/log&#039;&#039;. To do this, we would run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep .gz &amp;gt; gzlogfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now pipe the file into &#039;&#039;&#039;less&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;cat gzlogfiles.txt | less&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; NOTE: Remember that you are now viewing the file in the less program and will need to quite the program to return to a command line. Type the letter &amp;quot;q&amp;quot; to quit the less program.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; In this case the piped &#039;&#039;&#039;cat&#039;&#039;&#039; command is the exact same as running &#039;&#039;&#039;less gzlogfiles.txt&#039;&#039;&#039; however there are many times where you need to connect two programs together with pipes in order to accomplish something which is otherwise not possible. Also, standard output can be non-text data as well. For example, it&#039;s possible to use pipes to pass audio data between programs such as one that scans a WAV file and adjusts the volume before piping it to an MP3 compression utility which saves the result as an MP3 file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; See if you can figure out how to view the output of &#039;&#039;&#039;ls -al /var/log | grep .gz&#039;&#039;&#039; one page at a time without dumping it to a text file first.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now remove the files &#039;&#039;gzlogfiles.txt&#039;&#039; and &#039;&#039;listfiles.txt&#039;&#039; that were created from this part of the lab.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for Files in Linux==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=WSd6fq-jDyE Video Tutorial - Searching for Files in Linux]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
There are several ways to search for files on a Linux system. The simplest is to use the &#039;&#039;&#039;find&#039;&#039;&#039; command which searches through the system directory by directory for files which match your search string. You can specify many options for the find command which do things such as restrict to searching in one particular directory and it&#039;s sub-directories, etc.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try searching your entire drive for files with syslog in the name. &lt;br /&gt;
    &amp;lt;code&amp;gt; find / -name syslog 2&amp;gt; /dev/null&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:find_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/9/96/Find_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:find_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice the &#039;&#039;2&amp;gt; /dev/null&#039;&#039; on the end of the command. This redirects error messages ( &#039;&#039;2&amp;gt;&#039;&#039; redirected stderr, &#039;&#039;&amp;gt;&#039;&#039; redirects stdout as discussed above) to the location &#039;&#039;/dev/null&#039;&#039; which is non-existing location/file where bits are just dropped from the system. The reason we&#039;re redirecting the error messages is that there are a number of files or directories which you may not have permission to access. Each attempt to access these by the &#039;&#039;&#039;find&#039;&#039;&#039; program would create an error message (so lots of errors). We&#039;re basically telling the system to hide these error messages from us.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see some files identified which contain the name &#039;&#039;syslog&#039;&#039;. The problem is that the find command is very slow at moving through all the files on the system, in fact it may even appear to be frozen while searching slowly though the drive. If you have waited a while and are still not getting back to a command prompt you can press CTRL-C to force the find program to quit and return to a command prompt. This means the find program works just fine for searching through a few directories/files (such as your home directory might contain) but is not the best choice for searching the entire system. If you want to learn more about advanced uses of the find command take a look at [http://content.hccfl.edu/pollock/unix/findcmd.htm this tutorial].&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; A faster way to search the entire system is to use the &#039;&#039;locate&#039;&#039; command. Install the &#039;&#039;&#039;locate&#039;&#039;&#039; program&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;This command searches a pre-built database of all files on the system which means it operates much faster than searching though files one at a time. There are two downsides to locate. First, it may not be pre-installed on many Linux systems so you may have to install it. Second, you need to build or update the database before you can search for files. New files are not automatically updated to the database so this only really works if you periodically remember to update the database. We&#039;ll explain how you can schedule that automatically in the future (hint, see the &#039;&#039;&#039;cron&#039;&#039;&#039; program).&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; sudo apt-get install locate&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create an updated database of files on your system&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;sudo updatedb&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Note, it will take a while for this program to find and index all the files on your system so give it a while to run. The advantage is after you do this you can search the database for many different files very quickly instead of waiting for each search as with the find command. We need to run the &#039;&#039;&#039;updatedb&#039;&#039;&#039; program as an administrator so that it can search though all locations on the system, including ones your user does not normally have access to.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note: Programs that may need to run for a long time and do not require user input (like &#039;&#039;&#039;updatedb&#039;&#039;&#039;) can be run in the background by placing an ampersand at the end of the command line like &#039;&#039;&#039;sudo updatedb&amp;amp;&#039;&#039;&#039;. This will immediately return you to a command prompt so you can continue to work on other things while the command finishes running.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Search for files with &#039;&#039;syslog&#039;&#039; in the name again but now using the command &#039;&#039;locate&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; locate syslog&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:locate_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/1/17/Locate_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:locate_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see many files found with this name and it should happen quickly, much faster than with the find command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating Archived/Compressed Files==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=iBsHKvNP88E Video Tutorial: Creating Archived Compressed Files]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding why &#039;&#039;&#039;tar&#039;&#039;&#039; is functioning in a certain way you can find a number of introductory tutorials [http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ like this one] about using &#039;&#039;&#039;tar&#039;&#039;&#039; on the Internet by [https://www.google.com/#q=tar+tutorial searching for them]&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a new directory &#039;&#039;experiments&#039;&#039; in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup1.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory by first changing your working directory to &#039;&#039;/var/log&#039;&#039; and then using the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup1.tar.gz *&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the asterisk (*) which is used to select all files in the current directory for inclusion in the TAR file. This is a type of wildcard character.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change your working directory to the &#039;&#039;experiments&#039;&#039; directory in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory. What happened? What kind of mess could this make when you extract a TAR file when it was created this way?&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try again to create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup2.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory. By running the command from inside the &#039;&#039;experiments&#039;&#039; directory.&lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf logbackup2.tar.gz /var/log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the lack of a slash at the end of the directory we are putting into the TAR file. In some older versions of TAR putting a slash on the end meant to put the files from that directory into the file but not the directory itself (just like when we created logbackup1.tar.gz with the asterisk wildcard). By leaving the slash off the end we are telling TAR to put the log directory,as well as it&#039;s contents, into the TAR file so that when we extract it we will get a log directory made with the files going into it. Even though new versions of TAR automatically prevent you from creating TAR files without a directory path it is still best practice to make sure that you are including a directory as part of the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; What happened? If you extracted a tar file made this way you could potentially end up with several more levels of directories than you really want. In this case we got an extra var directory inside of experiments but if we were archiving something with a deeper path we would have even more extra subdirectories. You can actually see this during the tar file creation if you have verbose output enabled you saw that all the files being added to the tar had var/log/ in front of the filename. There are at least two ways to handle this which we will look at.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If we are creating the TAR file manually we can avoid these extra parts to the path by paying attention to what directory we are in when we create the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; This time change your working directory to &#039;&#039;/var&#039;&#039; first and then run the command. &lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf ~/experiments/logbackup3.tar.gz log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the different output from the tar command. This time the filenames are prefixed only by &#039;&#039;log/&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup3.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should see that there is just one new subdirectory called log and all of the files are neatly placed inside of it. This is the type of extraction people normally want and expect from a tar file that is distributed.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Empty your &#039;&#039;experiments&#039;&#039; directory&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; If you want to have the same effect without changing your working directory that is possible too. Try running the command below.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup4.tar.gz -C /var log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;This time it doesn&#039;t make any difference which directory on the system because we have again specified a full path for where to save the tar file and we have also told tar to change to the &#039;&#039;/var&#039;&#039; directory before adding the log directory to the file using the -C argument. This automates the process of manually changing directories like we did above.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup4.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should again see that there is just one new subdirectory called &#039;&#039;log&#039;&#039; and all of the files are neatly placed inside of it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are a number of other things you can do with &#039;&#039;&#039;tar&#039;&#039;&#039; such as creating slower but more highly compressed .bz2 bzip files, extracting single files (or directories or groups of files) from an archive, listing the contents of an archive without extracting (which can show you if a new subdirectory will be created), adding files to an existing archive, and preserving file ownership (only by extracting on the same system though) and permissions. You should read the manual page for tar and then try practicing some of these and be familiar with the many ways that &#039;&#039;&#039;tar&#039;&#039;&#039; can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Working With Filesystem Links==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=vBorZKMmvIk Video Tutorial: Working With Filesystem Links]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding how links are functioning in a certain way you can find a number of introductory tutorials [http://www.nixtutor.com/freebsd/understanding-symbolic-links/ like this one] or [http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/ more advanced tutorials] on the Internet by searching for them.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Use root privileges to create a new directory inside the &#039;&#039;var&#039;&#039; directory called &#039;&#039;system-documentation&#039;&#039; and change the ownership permissions so that your standard user has permission to read, write, and execute as a member of a group which owns the documentation directory. You will also need to make sure that all system users have execute permission for the parent directory (&#039;&#039;/var&#039;&#039;) in order to access anything in it including the &#039;&#039;system-documentation&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Instead of needing to go into the &#039;&#039;/var/-system-documentation&#039;&#039; directory all the time it would be more convenient if your user was able to reach that directory through a link in their own home directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Run the command below inside your regular user&#039;s home directory&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ln -s /var/system-documentation documentation&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:ln_documentation.png|link=https://wiki.ihitc.net/mediawiki/images/9/97/Ln_documentation.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:ln_documentation.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Or if you&#039;re in a different working directory you can run the command as &#039;&#039;&#039;ln -s /var/system-documentation ~/documentation&#039;&#039;&#039; Do you understand why?&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should now see a soft link (also called symlink) in your home directory called documentation which points to the &#039;&#039;/var/system-documentation&#039;&#039; folder.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &#039;&#039;&#039;cd&#039;&#039;&#039; into the link just like it was a real directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you use the &#039;&#039;&#039;pwd&#039;&#039;&#039; command to print your working directory while inside the link it will look like it&#039;s a directory. Almost all software on the system will interact with the link just as if it&#039;s a real directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try creating some files and subdirectories inside of the link and then verify they are showing up in the real &#039;&#039;/var/system-documentation&#039;&#039; location as well. This should work correctly if your permissions are all set correctly.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Remove the link&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;rm ~/documentation&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see that all of the files you created are still in &#039;&#039;/var/system-documentation&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you re-create the link you should be able to go back into &#039;&#039;~/documentation&#039;&#039; and remove files and directories and see they are removed from the actual &#039;&#039;/var/system-documentation&#039;&#039; directory as well&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You can also practice creating links to specific files as well as directories. Links do not override permissions so you need to have permission to read, write or execute the file or directory you are linking to just like if you actually changed to the real location of the item. Go ahead and practice creating and removing links until you have a good understanding of how links can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Note: If you are using &#039;&#039;&#039;tar&#039;&#039;&#039; to back up data, depending on exactly what you want to do you may want to use the &#039;&#039;-h&#039;&#039; or &#039;&#039;--dereference&#039;&#039; option which will follow the symlink and backup the data it contains. Normal behavior for tar would just be to back up the link itslef, not the file(s) pointed to by the link. You should try creating some tar files of directories which contain symlinks, deleting the data the symlink points to and the extracting the tar file to some new location to see this in action if you are not confident that you understand this.&lt;br /&gt;
&lt;br /&gt;
=Checking your Work=&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Testing your work goes here&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; Commands to use&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Description of what you should see&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9392</id>
		<title>Lab 4 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9392"/>
		<updated>2021-02-12T21:44:17Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Command Output Manipulation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Linux is a very text file-oriented operating system. As we&#039;ve learned most of the settings for the operating system are held in text files in the /etc directory and most of the commands that are used to manipulate the system take text input or give text output. Beause of this it&#039;s very important to be able to edit and manipulate text on the system which will be a key focus of this lab. In addition, we&#039;ll practice creating compressed files, which is useful for backing up files, and creating links between locations on the system.&lt;br /&gt;
&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
* Edit text files using nano and vi&lt;br /&gt;
* Learn how to manipulate command output&lt;br /&gt;
* Search for files&lt;br /&gt;
* Archive and Compress files using tar&lt;br /&gt;
* Create links between directories&lt;br /&gt;
&lt;br /&gt;
You will use the following commands:&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/vi Vi]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nano Nano]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/cd cd]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ls ls]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/cat Cat]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/less Less]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/find Find]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/locate Locate]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/updatedb Updatedb]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/8/apt apt]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/1/tar tar]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ln Ln]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/pwd Pwd]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
==Prerequisites==&lt;br /&gt;
Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
==Text File Editing==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=LnVsTA8_mQo Video Tutorial - Text File Editing]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change to the &#039;&#039;/var/www/html&#039;&#039; directory which is where the Apache webserver stores it&#039;s site files by default.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Verify you can see an &#039;&#039;index.html&#039;&#039; file inside of this directory by listing the contents of the directory. Note who the &#039;&#039;owner&#039;&#039; and &#039;&#039;group owner&#039;&#039; of the file are.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Open up a web browser on your host computer and verify that you can browse to the IP address of your Linux system and still see the &amp;quot;It works&amp;quot; page that you saw in [[Franske ITC-2480 Lab 2#Install the Apache 2 Webserver|lab 2]] after installing Apache.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Before we start making any changes it&#039;s a good idea to save an unmodified copy of the file you&#039;ll be working on so make a copy of the &#039;&#039;index.html&#039;&#039; file and name the copy &#039;&#039;index.html.orig&#039;&#039; so that you can always copy it back if you make a mistake.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are many different text editors available for Linux but systems almost always include some version of &#039;&#039;&#039;vi&#039;&#039;&#039; or &#039;&#039;&#039;nano&#039;&#039;&#039; so those are the two we&#039;ll focus on.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; In your ssh window open the &#039;&#039;index.html&#039;&#039; file in nano.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;NOTE: Because your user does not own this file you may need to edit the file as the superuser.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nano index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:nano_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/d/d3/Nano_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:nano_index_html.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try navigating around the file with your arrow keys and changing the &amp;quot;Apache2 Debian Default Page&amp;quot; text at the top of the page to &amp;quot;Welcome to My Linux Webserver&amp;quot;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Basic instructions for using nano abound on the Internet. You can get a basic introduction [http://staffwww.fullcoll.edu/sedwards/Nano/IntroToNano.html here] but it basically comes down to the menu lines at the bottom of the screen showing what your options are. The ^ character is commonly used to indicate the CTRL key so to exit the program (you will be prompted to save changes if you have made any) press CTRL-X or to save without exiting press CTRL-O and follow the prompts at the bottom of the screen.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Save your file with the changed text and then reload the page in your browser on your host system to see if the changes have taken effect.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Experiment with some of the nano menu options such as cutting and &amp;quot;un-cutting&amp;quot; lines of text and searching/replacing text. Once you are comfortable with the nano editor save your changes and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Make a note of which user and group owns your &#039;&#039;index.html&#039;&#039; file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete your &#039;&#039;index.html&#039;&#039; file and copy your &#039;&#039;index.html.orig&#039;&#039; file back to &#039;&#039;index.html&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Try loading the website again and see if it&#039;s back to the original text. If you encounter an error it&#039;s possible that your &#039;&#039;index.html&#039;&#039; file is not readable by the webserver account so you should use the appropriate command to set the &#039;&#039;index.html&#039;&#039; file back to the owner and group of the original file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now open the &#039;&#039;index.html&#039;&#039; file in vi&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; vi index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[File:vi_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/f/fd/Vi_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[Media:vi_index_html.png| Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; The vi editor is probably considered more powerful than nano but is less user friendly without the menu at the bottom and a COMMAND mode as well as an INSERT mode. In the COMMAND mode you cannot directly change the text of the file by typing which can be frustrating to new users. Read through the vi tutorial [http://www.washington.edu/computing/unix/vi.html here] and try making some edits to your webpage. Once you are familiar with how the vi editor works save your file and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Command Output Manipulation==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dgC1r0rXTpA Video Tutorial - Command Output Manipulation]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change back to your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cd ~&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Print out the files in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run &#039;&#039;&#039;ls -al&#039;&#039;&#039; but redirect the output to a file using &#039;&#039;&amp;gt; filename&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al &amp;gt; listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how there is no command output. This is normal as you redirected the command output to the file &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; verify the contents of &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cat listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:cat_listfiles_txt.png|link=https://wiki.ihitc.net/mediawiki/images/e/e1/Cat_listfiles_txt.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:cat_listfiles_txt.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how it contains the exact same output as running &#039;&#039;&#039;ls -al&#039;&#039;&#039; on the command line.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ls -al /var/log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how many files there are in the &#039;&#039;/var/log&#039;&#039; directory. Lets say we wanted to just know the information of the &#039;&#039;debug&#039;&#039; log files. For this, we would use a pipe and the grep command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So, now run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep debug&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:var_log_grep_debug.png|link=https://wiki.ihitc.net/mediawiki/images/7/74/Var_log_grep_debug.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:var_log_grep_debug.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how the output is limited to all files that contain the string &#039;&#039;debug&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; TIP: Grep is very powerful. Here we&#039;re just using it to search for a string but you can use it to search regular expressions as well. We mentioned these in a previous lab too. You can learn more about regular expressions at [https://regexone.com RegexOne] and [https://www.regular-expressions.info Regular-Expressions.info] among many other places. These are frequently used in system administration and programming so it&#039;s worth your while to get at least a basic understanding of them.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Whats nice about pipes and redirects is that they can be used back to back on a command line creating a chain of programs which accept data as standard input and output it to the next program as standard output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So lets say we have a scenario where we want to get a file that contains all of the information from all &#039;&#039;.gz&#039;&#039; files in &#039;&#039;/var/log&#039;&#039;. To do this, we would run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep .gz &amp;gt; gzlogfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now pipe the file into &#039;&#039;&#039;less&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;cat gzlogfiles.txt | less&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; NOTE: Remember that you are now viewing the file in the less program and will need to quite the program to return to a command line. Type the letter &amp;quot;q&amp;quot; to quit the less program.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; In this case the piped &#039;&#039;&#039;cat&#039;&#039;&#039; command is the exact same as running &#039;&#039;&#039;less gzlogfiles.txt&#039;&#039;&#039; however there are many times where you need to connect two programs together with pipes in order to accomplish something which is otherwise not possible. Also, standard output can be non-text data as well. For example, it&#039;s possible to use pipes to pass audio data between programs such as one that scans a WAV file and adjusts the volume before piping it to an MP3 compression utility which saves the result as an MP3 file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; See if you can figure out how to view the output of &#039;&#039;&#039;ls -al /var/log | grep .gz&#039;&#039;&#039; one page at a time without dumping it to a text file first.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now remove the files &#039;&#039;gzlogfiles.txt&#039;&#039; and &#039;&#039;listfiles.txt&#039;&#039; that were created from this part of the lab.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for Files in Linux==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=WSd6fq-jDyE Video Tutorial: Searching for Files in Linux]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
There are several ways to search for files on a Linux system. The simplest is to use the &#039;&#039;&#039;find&#039;&#039;&#039; command which searches through the system directory by directory for files which match your search string. You can specify many options for the find command which do things such as restrict to searching in one particular directory and it&#039;s sub-directories, etc.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try searching your entire drive for files with syslog in the name. &lt;br /&gt;
    &amp;lt;code&amp;gt; find / -name syslog 2&amp;gt; /dev/null&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:find_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/9/96/Find_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:find_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice the &#039;&#039;2&amp;gt; /dev/null&#039;&#039; on the end of the command. This redirects error messages ( &#039;&#039;2&amp;gt;&#039;&#039; redirected stderr, &#039;&#039;&amp;gt;&#039;&#039; redirects stdout as discussed above) to the location &#039;&#039;/dev/null&#039;&#039; which is non-existing location/file where bits are just dropped from the system. The reason we&#039;re redirecting the error messages is that there are a number of files or directories which you may not have permission to access. Each attempt to access these by the &#039;&#039;&#039;find&#039;&#039;&#039; program would create an error message (so lots of errors). We&#039;re basically telling the system to hide these error messages from us.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see some files identified which contain the name &#039;&#039;syslog&#039;&#039;. The problem is that the find command is very slow at moving through all the files on the system, in fact it may even appear to be frozen while searching slowly though the drive. If you have waited a while and are still not getting back to a command prompt you can press CTRL-C to force the find program to quit and return to a command prompt. This means the find program works just fine for searching through a few directories/files (such as your home directory might contain) but is not the best choice for searching the entire system. If you want to learn more about advanced uses of the find command take a look at [http://content.hccfl.edu/pollock/unix/findcmd.htm this tutorial].&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; A faster way to search the entire system is to use the &#039;&#039;locate&#039;&#039; command. Install the &#039;&#039;&#039;locate&#039;&#039;&#039; program&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;This command searches a pre-built database of all files on the system which means it operates much faster than searching though files one at a time. There are two downsides to locate. First, it may not be pre-installed on many Linux systems so you may have to install it. Second, you need to build or update the database before you can search for files. New files are not automatically updated to the database so this only really works if you periodically remember to update the database. We&#039;ll explain how you can schedule that automatically in the future (hint, see the &#039;&#039;&#039;cron&#039;&#039;&#039; program).&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; sudo apt-get install locate&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create an updated database of files on your system&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;sudo updatedb&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Note, it will take a while for this program to find and index all the files on your system so give it a while to run. The advantage is after you do this you can search the database for many different files very quickly instead of waiting for each search as with the find command. We need to run the &#039;&#039;&#039;updatedb&#039;&#039;&#039; program as an administrator so that it can search though all locations on the system, including ones your user does not normally have access to.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note: Programs that may need to run for a long time and do not require user input (like &#039;&#039;&#039;updatedb&#039;&#039;&#039;) can be run in the background by placing an ampersand at the end of the command line like &#039;&#039;&#039;sudo updatedb&amp;amp;&#039;&#039;&#039;. This will immediately return you to a command prompt so you can continue to work on other things while the command finishes running.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Search for files with &#039;&#039;syslog&#039;&#039; in the name again but now using the command &#039;&#039;locate&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; locate syslog&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:locate_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/1/17/Locate_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:locate_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see many files found with this name and it should happen quickly, much faster than with the find command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating Archived/Compressed Files==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=iBsHKvNP88E Video Tutorial: Creating Archived Compressed Files]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding why &#039;&#039;&#039;tar&#039;&#039;&#039; is functioning in a certain way you can find a number of introductory tutorials [http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ like this one] about using &#039;&#039;&#039;tar&#039;&#039;&#039; on the Internet by [https://www.google.com/#q=tar+tutorial searching for them]&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a new directory &#039;&#039;experiments&#039;&#039; in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup1.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory by first changing your working directory to &#039;&#039;/var/log&#039;&#039; and then using the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup1.tar.gz *&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the asterisk (*) which is used to select all files in the current directory for inclusion in the TAR file. This is a type of wildcard character.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change your working directory to the &#039;&#039;experiments&#039;&#039; directory in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory. What happened? What kind of mess could this make when you extract a TAR file when it was created this way?&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try again to create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup2.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory. By running the command from inside the &#039;&#039;experiments&#039;&#039; directory.&lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf logbackup2.tar.gz /var/log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the lack of a slash at the end of the directory we are putting into the TAR file. In some older versions of TAR putting a slash on the end meant to put the files from that directory into the file but not the directory itself (just like when we created logbackup1.tar.gz with the asterisk wildcard). By leaving the slash off the end we are telling TAR to put the log directory,as well as it&#039;s contents, into the TAR file so that when we extract it we will get a log directory made with the files going into it. Even though new versions of TAR automatically prevent you from creating TAR files without a directory path it is still best practice to make sure that you are including a directory as part of the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; What happened? If you extracted a tar file made this way you could potentially end up with several more levels of directories than you really want. In this case we got an extra var directory inside of experiments but if we were archiving something with a deeper path we would have even more extra subdirectories. You can actually see this during the tar file creation if you have verbose output enabled you saw that all the files being added to the tar had var/log/ in front of the filename. There are at least two ways to handle this which we will look at.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If we are creating the TAR file manually we can avoid these extra parts to the path by paying attention to what directory we are in when we create the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; This time change your working directory to &#039;&#039;/var&#039;&#039; first and then run the command. &lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf ~/experiments/logbackup3.tar.gz log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the different output from the tar command. This time the filenames are prefixed only by &#039;&#039;log/&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup3.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should see that there is just one new subdirectory called log and all of the files are neatly placed inside of it. This is the type of extraction people normally want and expect from a tar file that is distributed.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Empty your &#039;&#039;experiments&#039;&#039; directory&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; If you want to have the same effect without changing your working directory that is possible too. Try running the command below.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup4.tar.gz -C /var log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;This time it doesn&#039;t make any difference which directory on the system because we have again specified a full path for where to save the tar file and we have also told tar to change to the &#039;&#039;/var&#039;&#039; directory before adding the log directory to the file using the -C argument. This automates the process of manually changing directories like we did above.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup4.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should again see that there is just one new subdirectory called &#039;&#039;log&#039;&#039; and all of the files are neatly placed inside of it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are a number of other things you can do with &#039;&#039;&#039;tar&#039;&#039;&#039; such as creating slower but more highly compressed .bz2 bzip files, extracting single files (or directories or groups of files) from an archive, listing the contents of an archive without extracting (which can show you if a new subdirectory will be created), adding files to an existing archive, and preserving file ownership (only by extracting on the same system though) and permissions. You should read the manual page for tar and then try practicing some of these and be familiar with the many ways that &#039;&#039;&#039;tar&#039;&#039;&#039; can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Working With Filesystem Links==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=vBorZKMmvIk Video Tutorial: Working With Filesystem Links]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding how links are functioning in a certain way you can find a number of introductory tutorials [http://www.nixtutor.com/freebsd/understanding-symbolic-links/ like this one] or [http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/ more advanced tutorials] on the Internet by searching for them.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Use root privileges to create a new directory inside the &#039;&#039;var&#039;&#039; directory called &#039;&#039;system-documentation&#039;&#039; and change the ownership permissions so that your standard user has permission to read, write, and execute as a member of a group which owns the documentation directory. You will also need to make sure that all system users have execute permission for the parent directory (&#039;&#039;/var&#039;&#039;) in order to access anything in it including the &#039;&#039;system-documentation&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Instead of needing to go into the &#039;&#039;/var/-system-documentation&#039;&#039; directory all the time it would be more convenient if your user was able to reach that directory through a link in their own home directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Run the command below inside your regular user&#039;s home directory&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ln -s /var/system-documentation documentation&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:ln_documentation.png|link=https://wiki.ihitc.net/mediawiki/images/9/97/Ln_documentation.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:ln_documentation.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Or if you&#039;re in a different working directory you can run the command as &#039;&#039;&#039;ln -s /var/system-documentation ~/documentation&#039;&#039;&#039; Do you understand why?&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should now see a soft link (also called symlink) in your home directory called documentation which points to the &#039;&#039;/var/system-documentation&#039;&#039; folder.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &#039;&#039;&#039;cd&#039;&#039;&#039; into the link just like it was a real directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you use the &#039;&#039;&#039;pwd&#039;&#039;&#039; command to print your working directory while inside the link it will look like it&#039;s a directory. Almost all software on the system will interact with the link just as if it&#039;s a real directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try creating some files and subdirectories inside of the link and then verify they are showing up in the real &#039;&#039;/var/system-documentation&#039;&#039; location as well. This should work correctly if your permissions are all set correctly.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Remove the link&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;rm ~/documentation&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see that all of the files you created are still in &#039;&#039;/var/system-documentation&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you re-create the link you should be able to go back into &#039;&#039;~/documentation&#039;&#039; and remove files and directories and see they are removed from the actual &#039;&#039;/var/system-documentation&#039;&#039; directory as well&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You can also practice creating links to specific files as well as directories. Links do not override permissions so you need to have permission to read, write or execute the file or directory you are linking to just like if you actually changed to the real location of the item. Go ahead and practice creating and removing links until you have a good understanding of how links can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Note: If you are using &#039;&#039;&#039;tar&#039;&#039;&#039; to back up data, depending on exactly what you want to do you may want to use the &#039;&#039;-h&#039;&#039; or &#039;&#039;--dereference&#039;&#039; option which will follow the symlink and backup the data it contains. Normal behavior for tar would just be to back up the link itslef, not the file(s) pointed to by the link. You should try creating some tar files of directories which contain symlinks, deleting the data the symlink points to and the extracting the tar file to some new location to see this in action if you are not confident that you understand this.&lt;br /&gt;
&lt;br /&gt;
=Checking your Work=&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Testing your work goes here&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; Commands to use&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Description of what you should see&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9391</id>
		<title>Lab 4 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_4_mnjk&amp;diff=9391"/>
		<updated>2021-02-12T21:44:02Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Text File Editing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Linux is a very text file-oriented operating system. As we&#039;ve learned most of the settings for the operating system are held in text files in the /etc directory and most of the commands that are used to manipulate the system take text input or give text output. Beause of this it&#039;s very important to be able to edit and manipulate text on the system which will be a key focus of this lab. In addition, we&#039;ll practice creating compressed files, which is useful for backing up files, and creating links between locations on the system.&lt;br /&gt;
&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
* Edit text files using nano and vi&lt;br /&gt;
* Learn how to manipulate command output&lt;br /&gt;
* Search for files&lt;br /&gt;
* Archive and Compress files using tar&lt;br /&gt;
* Create links between directories&lt;br /&gt;
&lt;br /&gt;
You will use the following commands:&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/vi Vi]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nano Nano]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/cd cd]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ls ls]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/cat Cat]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/less Less]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/find Find]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/locate Locate]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/updatedb Updatedb]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/8/apt apt]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[http://linux.die.net/man/1/tar tar]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ln Ln]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/pwd Pwd]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
==Prerequisites==&lt;br /&gt;
Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
&lt;br /&gt;
==Text File Editing==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=LnVsTA8_mQo Video Tutorial - Text File Editing]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change to the &#039;&#039;/var/www/html&#039;&#039; directory which is where the Apache webserver stores it&#039;s site files by default.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Verify you can see an &#039;&#039;index.html&#039;&#039; file inside of this directory by listing the contents of the directory. Note who the &#039;&#039;owner&#039;&#039; and &#039;&#039;group owner&#039;&#039; of the file are.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Open up a web browser on your host computer and verify that you can browse to the IP address of your Linux system and still see the &amp;quot;It works&amp;quot; page that you saw in [[Franske ITC-2480 Lab 2#Install the Apache 2 Webserver|lab 2]] after installing Apache.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Before we start making any changes it&#039;s a good idea to save an unmodified copy of the file you&#039;ll be working on so make a copy of the &#039;&#039;index.html&#039;&#039; file and name the copy &#039;&#039;index.html.orig&#039;&#039; so that you can always copy it back if you make a mistake.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are many different text editors available for Linux but systems almost always include some version of &#039;&#039;&#039;vi&#039;&#039;&#039; or &#039;&#039;&#039;nano&#039;&#039;&#039; so those are the two we&#039;ll focus on.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; In your ssh window open the &#039;&#039;index.html&#039;&#039; file in nano.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;NOTE: Because your user does not own this file you may need to edit the file as the superuser.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nano index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:nano_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/d/d3/Nano_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:nano_index_html.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try navigating around the file with your arrow keys and changing the &amp;quot;Apache2 Debian Default Page&amp;quot; text at the top of the page to &amp;quot;Welcome to My Linux Webserver&amp;quot;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Basic instructions for using nano abound on the Internet. You can get a basic introduction [http://staffwww.fullcoll.edu/sedwards/Nano/IntroToNano.html here] but it basically comes down to the menu lines at the bottom of the screen showing what your options are. The ^ character is commonly used to indicate the CTRL key so to exit the program (you will be prompted to save changes if you have made any) press CTRL-X or to save without exiting press CTRL-O and follow the prompts at the bottom of the screen.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Save your file with the changed text and then reload the page in your browser on your host system to see if the changes have taken effect.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Experiment with some of the nano menu options such as cutting and &amp;quot;un-cutting&amp;quot; lines of text and searching/replacing text. Once you are comfortable with the nano editor save your changes and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Make a note of which user and group owns your &#039;&#039;index.html&#039;&#039; file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete your &#039;&#039;index.html&#039;&#039; file and copy your &#039;&#039;index.html.orig&#039;&#039; file back to &#039;&#039;index.html&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Try loading the website again and see if it&#039;s back to the original text. If you encounter an error it&#039;s possible that your &#039;&#039;index.html&#039;&#039; file is not readable by the webserver account so you should use the appropriate command to set the &#039;&#039;index.html&#039;&#039; file back to the owner and group of the original file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now open the &#039;&#039;index.html&#039;&#039; file in vi&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; vi index.html&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[File:vi_index_html.png|link=https://wiki.ihitc.net/mediawiki/images/f/fd/Vi_index_html.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;[[Media:vi_index_html.png| Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; The vi editor is probably considered more powerful than nano but is less user friendly without the menu at the bottom and a COMMAND mode as well as an INSERT mode. In the COMMAND mode you cannot directly change the text of the file by typing which can be frustrating to new users. Read through the vi tutorial [http://www.washington.edu/computing/unix/vi.html here] and try making some edits to your webpage. Once you are familiar with how the vi editor works save your file and exit.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Command Output Manipulation==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=dgC1r0rXTpA Video Tutorial: Command Output Manipulation]]&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change back to your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cd ~&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Print out the files in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run &#039;&#039;&#039;ls -al&#039;&#039;&#039; but redirect the output to a file using &#039;&#039;&amp;gt; filename&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al &amp;gt; listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how there is no command output. This is normal as you redirected the command output to the file &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; verify the contents of &#039;&#039;listfiles.txt&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; cat listfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:cat_listfiles_txt.png|link=https://wiki.ihitc.net/mediawiki/images/e/e1/Cat_listfiles_txt.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:cat_listfiles_txt.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice how it contains the exact same output as running &#039;&#039;&#039;ls -al&#039;&#039;&#039; on the command line.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now, run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ls -al /var/log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how many files there are in the &#039;&#039;/var/log&#039;&#039; directory. Lets say we wanted to just know the information of the &#039;&#039;debug&#039;&#039; log files. For this, we would use a pipe and the grep command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So, now run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep debug&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:var_log_grep_debug.png|link=https://wiki.ihitc.net/mediawiki/images/7/74/Var_log_grep_debug.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:var_log_grep_debug.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Notice how the output is limited to all files that contain the string &#039;&#039;debug&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; TIP: Grep is very powerful. Here we&#039;re just using it to search for a string but you can use it to search regular expressions as well. We mentioned these in a previous lab too. You can learn more about regular expressions at [https://regexone.com RegexOne] and [https://www.regular-expressions.info Regular-Expressions.info] among many other places. These are frequently used in system administration and programming so it&#039;s worth your while to get at least a basic understanding of them.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Whats nice about pipes and redirects is that they can be used back to back on a command line creating a chain of programs which accept data as standard input and output it to the next program as standard output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; So lets say we have a scenario where we want to get a file that contains all of the information from all &#039;&#039;.gz&#039;&#039; files in &#039;&#039;/var/log&#039;&#039;. To do this, we would run:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; ls -al /var/log | grep .gz &amp;gt; gzlogfiles.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now pipe the file into &#039;&#039;&#039;less&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;cat gzlogfiles.txt | less&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; NOTE: Remember that you are now viewing the file in the less program and will need to quite the program to return to a command line. Type the letter &amp;quot;q&amp;quot; to quit the less program.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; In this case the piped &#039;&#039;&#039;cat&#039;&#039;&#039; command is the exact same as running &#039;&#039;&#039;less gzlogfiles.txt&#039;&#039;&#039; however there are many times where you need to connect two programs together with pipes in order to accomplish something which is otherwise not possible. Also, standard output can be non-text data as well. For example, it&#039;s possible to use pipes to pass audio data between programs such as one that scans a WAV file and adjusts the volume before piping it to an MP3 compression utility which saves the result as an MP3 file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; See if you can figure out how to view the output of &#039;&#039;&#039;ls -al /var/log | grep .gz&#039;&#039;&#039; one page at a time without dumping it to a text file first.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Now remove the files &#039;&#039;gzlogfiles.txt&#039;&#039; and &#039;&#039;listfiles.txt&#039;&#039; that were created from this part of the lab.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for Files in Linux==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=WSd6fq-jDyE Video Tutorial: Searching for Files in Linux]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
There are several ways to search for files on a Linux system. The simplest is to use the &#039;&#039;&#039;find&#039;&#039;&#039; command which searches through the system directory by directory for files which match your search string. You can specify many options for the find command which do things such as restrict to searching in one particular directory and it&#039;s sub-directories, etc.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try searching your entire drive for files with syslog in the name. &lt;br /&gt;
    &amp;lt;code&amp;gt; find / -name syslog 2&amp;gt; /dev/null&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:find_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/9/96/Find_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:find_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Notice the &#039;&#039;2&amp;gt; /dev/null&#039;&#039; on the end of the command. This redirects error messages ( &#039;&#039;2&amp;gt;&#039;&#039; redirected stderr, &#039;&#039;&amp;gt;&#039;&#039; redirects stdout as discussed above) to the location &#039;&#039;/dev/null&#039;&#039; which is non-existing location/file where bits are just dropped from the system. The reason we&#039;re redirecting the error messages is that there are a number of files or directories which you may not have permission to access. Each attempt to access these by the &#039;&#039;&#039;find&#039;&#039;&#039; program would create an error message (so lots of errors). We&#039;re basically telling the system to hide these error messages from us.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see some files identified which contain the name &#039;&#039;syslog&#039;&#039;. The problem is that the find command is very slow at moving through all the files on the system, in fact it may even appear to be frozen while searching slowly though the drive. If you have waited a while and are still not getting back to a command prompt you can press CTRL-C to force the find program to quit and return to a command prompt. This means the find program works just fine for searching through a few directories/files (such as your home directory might contain) but is not the best choice for searching the entire system. If you want to learn more about advanced uses of the find command take a look at [http://content.hccfl.edu/pollock/unix/findcmd.htm this tutorial].&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; A faster way to search the entire system is to use the &#039;&#039;locate&#039;&#039; command. Install the &#039;&#039;&#039;locate&#039;&#039;&#039; program&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;This command searches a pre-built database of all files on the system which means it operates much faster than searching though files one at a time. There are two downsides to locate. First, it may not be pre-installed on many Linux systems so you may have to install it. Second, you need to build or update the database before you can search for files. New files are not automatically updated to the database so this only really works if you periodically remember to update the database. We&#039;ll explain how you can schedule that automatically in the future (hint, see the &#039;&#039;&#039;cron&#039;&#039;&#039; program).&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; sudo apt-get install locate&amp;lt;/code&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create an updated database of files on your system&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;sudo updatedb&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Note, it will take a while for this program to find and index all the files on your system so give it a while to run. The advantage is after you do this you can search the database for many different files very quickly instead of waiting for each search as with the find command. We need to run the &#039;&#039;&#039;updatedb&#039;&#039;&#039; program as an administrator so that it can search though all locations on the system, including ones your user does not normally have access to.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note: Programs that may need to run for a long time and do not require user input (like &#039;&#039;&#039;updatedb&#039;&#039;&#039;) can be run in the background by placing an ampersand at the end of the command line like &#039;&#039;&#039;sudo updatedb&amp;amp;&#039;&#039;&#039;. This will immediately return you to a command prompt so you can continue to work on other things while the command finishes running.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Search for files with &#039;&#039;syslog&#039;&#039; in the name again but now using the command &#039;&#039;locate&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; locate syslog&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:locate_syslog.png|link=https://wiki.ihitc.net/mediawiki/images/1/17/Locate_syslog.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:locate_syslog.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see many files found with this name and it should happen quickly, much faster than with the find command.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating Archived/Compressed Files==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=iBsHKvNP88E Video Tutorial: Creating Archived Compressed Files]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding why &#039;&#039;&#039;tar&#039;&#039;&#039; is functioning in a certain way you can find a number of introductory tutorials [http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ like this one] about using &#039;&#039;&#039;tar&#039;&#039;&#039; on the Internet by [https://www.google.com/#q=tar+tutorial searching for them]&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a new directory &#039;&#039;experiments&#039;&#039; in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup1.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory by first changing your working directory to &#039;&#039;/var/log&#039;&#039; and then using the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup1.tar.gz *&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the asterisk (*) which is used to select all files in the current directory for inclusion in the TAR file. This is a type of wildcard character.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Change your working directory to the &#039;&#039;experiments&#039;&#039; directory in your home directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory. What happened? What kind of mess could this make when you extract a TAR file when it was created this way?&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try again to create a GZipped TAR file of everything in your system log directory called &#039;&#039;logbackup2.tar.tz&#039;&#039; and save it to the &#039;&#039;experiments&#039;&#039; directory in your home directory. By running the command from inside the &#039;&#039;experiments&#039;&#039; directory.&lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf logbackup2.tar.gz /var/log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note that you will need to use root privileges to create all of the log backups in this section of the lab because some log files can not be read by a standard user.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the lack of a slash at the end of the directory we are putting into the TAR file. In some older versions of TAR putting a slash on the end meant to put the files from that directory into the file but not the directory itself (just like when we created logbackup1.tar.gz with the asterisk wildcard). By leaving the slash off the end we are telling TAR to put the log directory,as well as it&#039;s contents, into the TAR file so that when we extract it we will get a log directory made with the files going into it. Even though new versions of TAR automatically prevent you from creating TAR files without a directory path it is still best practice to make sure that you are including a directory as part of the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try extracting the files into your &#039;&#039;experiments&#039;&#039; directory, show a list of files as they are extracted (&#039;&#039;verbose&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Check the contents of your &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; What happened? If you extracted a tar file made this way you could potentially end up with several more levels of directories than you really want. In this case we got an extra var directory inside of experiments but if we were archiving something with a deeper path we would have even more extra subdirectories. You can actually see this during the tar file creation if you have verbose output enabled you saw that all the files being added to the tar had var/log/ in front of the filename. There are at least two ways to handle this which we will look at.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Delete all files and subdirectories from inside the &#039;&#039;experiments&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If we are creating the TAR file manually we can avoid these extra parts to the path by paying attention to what directory we are in when we create the TAR file.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; This time change your working directory to &#039;&#039;/var&#039;&#039; first and then run the command. &lt;br /&gt;
    &amp;lt;code&amp;gt; tar -czvf ~/experiments/logbackup3.tar.gz log&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Note the different output from the tar command. This time the filenames are prefixed only by &#039;&#039;log/&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup3.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should see that there is just one new subdirectory called log and all of the files are neatly placed inside of it. This is the type of extraction people normally want and expect from a tar file that is distributed.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Empty your &#039;&#039;experiments&#039;&#039; directory&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; If you want to have the same effect without changing your working directory that is possible too. Try running the command below.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;tar -czvf ~/experiments/logbackup4.tar.gz -C /var log&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;This time it doesn&#039;t make any difference which directory on the system because we have again specified a full path for where to save the tar file and we have also told tar to change to the &#039;&#039;/var&#039;&#039; directory before adding the log directory to the file using the -C argument. This automates the process of manually changing directories like we did above.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Switch back to your &#039;&#039;experiments&#039;&#039; directory and then try extracting the files from &#039;&#039;logbackup4.tar.gz&#039;&#039; into your experiments directory, do not show a list of files as they are extracted this time.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Check the contents of your experiments directory. This time you should again see that there is just one new subdirectory called &#039;&#039;log&#039;&#039; and all of the files are neatly placed inside of it.&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; There are a number of other things you can do with &#039;&#039;&#039;tar&#039;&#039;&#039; such as creating slower but more highly compressed .bz2 bzip files, extracting single files (or directories or groups of files) from an archive, listing the contents of an archive without extracting (which can show you if a new subdirectory will be created), adding files to an existing archive, and preserving file ownership (only by extracting on the same system though) and permissions. You should read the manual page for tar and then try practicing some of these and be familiar with the many ways that &#039;&#039;&#039;tar&#039;&#039;&#039; can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Working With Filesystem Links==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=vBorZKMmvIk Video Tutorial: Working With Filesystem Links]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you get stuck or have any problems understanding how links are functioning in a certain way you can find a number of introductory tutorials [http://www.nixtutor.com/freebsd/understanding-symbolic-links/ like this one] or [http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/ more advanced tutorials] on the Internet by searching for them.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Use root privileges to create a new directory inside the &#039;&#039;var&#039;&#039; directory called &#039;&#039;system-documentation&#039;&#039; and change the ownership permissions so that your standard user has permission to read, write, and execute as a member of a group which owns the documentation directory. You will also need to make sure that all system users have execute permission for the parent directory (&#039;&#039;/var&#039;&#039;) in order to access anything in it including the &#039;&#039;system-documentation&#039;&#039; directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Instead of needing to go into the &#039;&#039;/var/-system-documentation&#039;&#039; directory all the time it would be more convenient if your user was able to reach that directory through a link in their own home directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Run the command below inside your regular user&#039;s home directory&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;ln -s /var/system-documentation documentation&amp;lt;/code&amp;gt; &lt;br /&gt;
    &amp;lt;ul&amp;gt;[[File:ln_documentation.png|link=https://wiki.ihitc.net/mediawiki/images/9/97/Ln_documentation.png|250px]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;[[Media:ln_documentation.png|Click for Larger Image]]&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt;Or if you&#039;re in a different working directory you can run the command as &#039;&#039;&#039;ln -s /var/system-documentation ~/documentation&#039;&#039;&#039; Do you understand why?&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should now see a soft link (also called symlink) in your home directory called documentation which points to the &#039;&#039;/var/system-documentation&#039;&#039; folder.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; &#039;&#039;&#039;cd&#039;&#039;&#039; into the link just like it was a real directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you use the &#039;&#039;&#039;pwd&#039;&#039;&#039; command to print your working directory while inside the link it will look like it&#039;s a directory. Almost all software on the system will interact with the link just as if it&#039;s a real directory.&amp;lt;/ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Try creating some files and subdirectories inside of the link and then verify they are showing up in the real &#039;&#039;/var/system-documentation&#039;&#039; location as well. This should work correctly if your permissions are all set correctly.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Remove the link&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;rm ~/documentation&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You should see that all of the files you created are still in &#039;&#039;/var/system-documentation&#039;&#039;&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; If you re-create the link you should be able to go back into &#039;&#039;~/documentation&#039;&#039; and remove files and directories and see they are removed from the actual &#039;&#039;/var/system-documentation&#039;&#039; directory as well&amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; You can also practice creating links to specific files as well as directories. Links do not override permissions so you need to have permission to read, write or execute the file or directory you are linking to just like if you actually changed to the real location of the item. Go ahead and practice creating and removing links until you have a good understanding of how links can be used.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
Note: If you are using &#039;&#039;&#039;tar&#039;&#039;&#039; to back up data, depending on exactly what you want to do you may want to use the &#039;&#039;-h&#039;&#039; or &#039;&#039;--dereference&#039;&#039; option which will follow the symlink and backup the data it contains. Normal behavior for tar would just be to back up the link itslef, not the file(s) pointed to by the link. You should try creating some tar files of directories which contain symlinks, deleting the data the symlink points to and the extracting the tar file to some new location to see this in action if you are not confident that you understand this.&lt;br /&gt;
&lt;br /&gt;
=Checking your Work=&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt; Testing your work goes here&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt; Commands to use&amp;lt;/code&amp;gt;&lt;br /&gt;
    &amp;lt;ul&amp;gt; Description of what you should see&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9390</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9390"/>
		<updated>2021-02-12T21:43:30Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Manually editing a zone file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;// forwarders {&lt;br /&gt;
//     0.0.0.0;&lt;br /&gt;
// };&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
Non-authoritative answer:&lt;br /&gt;
Name:	inverhills.edu&lt;br /&gt;
Address: 134.29.182.42&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial - Adding an AAAA Record]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial - Adding a Delegated Domain]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial - Manually Editing a Zone File]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9389</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9389"/>
		<updated>2021-02-12T21:43:20Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Adding a Delegated Domain */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;// forwarders {&lt;br /&gt;
//     0.0.0.0;&lt;br /&gt;
// };&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
Non-authoritative answer:&lt;br /&gt;
Name:	inverhills.edu&lt;br /&gt;
Address: 134.29.182.42&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial - Adding an AAAA Record]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial - Adding a Delegated Domain]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial: Manually Editing a Zone File]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9388</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9388"/>
		<updated>2021-02-12T21:43:07Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Adding a AAAA record */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;// forwarders {&lt;br /&gt;
//     0.0.0.0;&lt;br /&gt;
// };&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
Non-authoritative answer:&lt;br /&gt;
Name:	inverhills.edu&lt;br /&gt;
Address: 134.29.182.42&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial - Adding an AAAA Record]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial: Adding a Delegated Domain]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial: Manually Editing a Zone File]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9387</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9387"/>
		<updated>2021-02-12T21:42:55Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Additional DNS Record Types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;// forwarders {&lt;br /&gt;
//     0.0.0.0;&lt;br /&gt;
// };&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
Non-authoritative answer:&lt;br /&gt;
Name:	inverhills.edu&lt;br /&gt;
Address: 134.29.182.42&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial - Additional DNS Record Types]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial: Adding an AAAA Record]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial: Adding a Delegated Domain]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial: Manually Editing a Zone File]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9386</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9386"/>
		<updated>2021-02-12T21:42:42Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Create a Domain using Webmin */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;// forwarders {&lt;br /&gt;
//     0.0.0.0;&lt;br /&gt;
// };&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
Non-authoritative answer:&lt;br /&gt;
Name:	inverhills.edu&lt;br /&gt;
Address: 134.29.182.42&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial - Create a Domain Using Webmin]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial: Additional DNS Record Types]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial: Adding an AAAA Record]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial: Adding a Delegated Domain]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial: Manually Editing a Zone File]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9385</id>
		<title>Lab 8 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_8_mnjk&amp;diff=9385"/>
		<updated>2021-02-12T21:41:57Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Install BIND &amp;amp; Enable Caching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
*Install BIND and configure as caching plus zones for a local domain&lt;br /&gt;
*Learn how to create domains using Webmin&lt;br /&gt;
*Learn how to manually edit using a zone file&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/dig dig]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nslookup nslookup]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/shutdown shutdown]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/sudo sudo]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account.&lt;br /&gt;
# Make sure that Webmin is installed on your system. &lt;br /&gt;
== Install BIND &amp;amp; Enable Caching ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=frZ7FrJyjME Video Tutorial - Installing BIND and Enabling Caching]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;First you will need to install BIND. to install it, use the package manager to install &#039;&#039;&#039;bind9&#039;&#039;&#039;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;BIND (Berkeley Internet Name Domain) is one of the available DNS server applications for Linux and the most well known and used nameserver on the Internet.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will also want to install the &#039;&#039;&#039;dnsutils&#039;&#039;&#039; package.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;In order to use the &#039;&#039;&#039;nslookup&#039;&#039;&#039; and &#039;&#039;&#039;dig&#039;&#039;&#039; programs for DNS testing and troubleshooting you&#039;ll need dnsutils&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up &#039;&#039;/etc/bind/named.conf.options&#039;&#039; with your favorite text editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Now we will need to enable DNS caching and forwarding on the BIND server. This will allow us to use it for DNS resolving locally, as well as speed up frequent DNS requests.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;You are now in the local options file for BIND. You will need to uncomment (remove the // from the front of) the following lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;// forwarders {&lt;br /&gt;
//     0.0.0.0;&lt;br /&gt;
// };&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; You will also need to replace 0.0.0.0 with 172.17.139.11 for outside DNS lookups to function correctly.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The reason we setup a forwarder address is so that domain requests that are not on our system are passed to another DNS server instead of being searched against the root nameservers. You may want to do this in domain or enterprise environments as most large networks have internal domain names setup that only redirect inside of a local LAN. By using a forwarder, as long as the DNS server you push requests to is able to access those internal records, you will be able to access local content from internal domain names instead of needing to rely on IP addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To apply these changes, you will need to restart the BIND server with administrative permissions.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service bind9 restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Next, open up your interfaces file (&#039;&#039;/etc/network/interfaces&#039;&#039;) with your favorite file editor.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Change the dns server for the primary network interface to &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;The change to &#039;&#039;/etc/network/interfaces&#039;&#039; will take effect if you restart your system. To avoid doing that right now you can edit the &#039;&#039;/etc/resolv.conf&#039;&#039; file so that it has only one nameserver line like &#039;&#039;nameserver 127.0.0.1&#039;&#039; Note that unless you reboot the system it will eventually get reset back to it&#039;s prior setting by a background system process so at some point you will want to reboot your system to make the change permanent.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run the command:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;If BIND is working, you should now see the following output:&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
Non-authoritative answer:&lt;br /&gt;
Name:	inverhills.edu&lt;br /&gt;
Address: 134.29.182.42&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Notice how it shows it is using 127.0.0.1 as the server. If you do not see this, then your interface file or resolv.conf file is not set to use the local machine for DNS lookups. Note also that the IP address returned for this domain may vary from the one shown in the output above.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig inverhills.edu&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;See if you can find where the IP address for the domain is reported in the output as well as where the server IP address is reported in the output.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now would be a good time to reboot your server to ensure the DNS server network interface configuration changes remain permanent.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo shutdown -r now&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Once the system reboots log back in and use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to verify the default nameserver being used is &#039;&#039;127.0.0.1&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create a Domain using Webmin ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=53aK9FeYz68 Video Tutorial: Create a Domain Using Webmin]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to use Webmin to create a few different type of domain records and have our system serve as a DNS server for a domain. We will utilize A (Host), AAAA (IPv6 host), MX (Mail Exchange), and CNAME (Canonical Name) records.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Open up your &#039;&#039;&#039;Webmin panel&#039;&#039;&#039; and sign in.&amp;lt;/li&amp;gt;  &lt;br /&gt;
&amp;lt;ul&amp;gt;Now that we have BIND installed, you will need to click the Refresh Modules option on the left sidebar to have Webmin recheck the system for installed packages and services so that it will show up as an option in the &#039;&#039;Servers&#039;&#039; tab.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Under the &#039;&#039;Servers&#039;&#039; tab, open up &#039;&#039;BIND DNS Server&#039;&#039;, under &#039;&#039;Existing DNS Zones&#039;&#039; click &#039;&#039;Create master zone&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;From here we will create a new domain name for our server to respond to DNS queries for.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the following options, &#039;&#039;&#039;where * is replaced by your System ID&#039;&#039;&#039; that was defined in [[Franske ITC-2480 Lab 5|Lab 5]] (just the letter of your system, for example the domain name would be &#039;&#039;debserv-A.test&#039;&#039; if you had System ID &amp;quot;A&amp;quot;).&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: debserv-*.test&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: Leave as your hostname&lt;br /&gt;
Email address: root@debserv-*.test&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;create&#039;&#039; button to add the domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; As this point you should now be on the &#039;&#039;Edit Master Zone&#039;&#039; page. From here you can add and edit domain records for this domain name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;To create our &#039;&#039;A record&#039;&#039; which points your domain to an IP address, click the &#039;&#039;Address&#039;&#039; button.&amp;lt;/li&amp;gt;&lt;br /&gt;
* For the &#039;&#039;Name&#039;&#039; enter &#039;&#039;@&#039;&#039;. Note: The &#039;&#039;@&#039;&#039; symbol in DNS Zones defines the parent domain (alternatively you could re-enter the parent domain &#039;&#039;debserv-*.test.&#039;&#039; with the period at the end).&lt;br /&gt;
* In the &#039;&#039;address&#039;&#039; field enter your VM&#039;s static IP set in [[Franske ITC-2480 Lab 5|Lab 5]] and click &#039;&#039;Create&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; Return to the main BIND DNS Server page. Click the &#039;&#039;Apply Configuration&#039;&#039; link (which looks like two arrows chasing each other) in the top right corner. You&#039;ll see the &amp;quot;Apply Configuration&amp;quot; text if you hover your mouse over the button.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test the record use &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to lookup the domain you just created (Replace the * with your letter.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
* If you have issues looking up the domain, make sure that the system is still using 127.0.0.1 as the DNS server. If not, check your &#039;&#039;/etc/resolv.conf&#039;&#039; file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional DNS Record Types ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=dC6RsYYMk4w Video Tutorial: Additional DNS Record Types]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add a few more record types to our Domain. This will include an &#039;&#039;MX&#039;&#039; (Mail Exchange) and &#039;&#039;CNAME&#039;&#039; (Canonical Name) record. We will start with the MX record. MX records are used by email servers to look up where to forward email for a specific domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In Webmin on the &#039;&#039;&#039;BIND DNS Server&#039;&#039;&#039; page, click the domain on the bottom named &#039;&#039;debserv-*.test&#039;&#039; and then click the &#039;&#039;&#039;Mail Server&#039;&#039;&#039; button. Under &#039;&#039;name&#039;&#039;, enter &#039;&#039;@&#039;&#039; again, and for &#039;&#039;mail server&#039;&#039; enter &#039;&#039;mail.debserv-*.test.&#039;&#039; (with the period at the end). For &#039;&#039;Priority&#039;&#039;, enter &#039;&#039;10&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
* This entry has said we want other servers trying to send mail to &#039;&#039;users@debserv-*.test&#039;&#039; to actually send it to the server at &#039;&#039;mail.debserv-*.test&#039;&#039; which allows us to use a different server for email than we use fore web serving, etc.&lt;br /&gt;
* The Priority entry allows people to define more than one MX record for a name, and the order which the sending service will try to use for contacting the various mail servers at your domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Go back to the domain zone overview page. Add an &#039;&#039;A&#039;&#039; record for &#039;&#039;mail.debserv-*.test&#039;&#039; which points to the IP of your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Because we don&#039;t currently have an &amp;quot;A&amp;quot; (address) record for &#039;&#039;mail.debserv-*.test&#039;&#039; the mail would currently go undelivered.&amp;lt;/ul&amp;gt;&lt;br /&gt;
* Reapply configuration settings like you did in the last section of this lab using the button with the two arrows in a circle.&lt;br /&gt;
&amp;lt;li&amp;gt; To test an &#039;&#039;MX&#039;&#039; record we need to make multiple queries and ask &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; to fist check for MX records for the domain like:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=MX debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;or&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test MX&amp;lt;/code&amp;gt;&lt;br /&gt;
which will return the names of the mail servers for that domain. We then need to do a regular &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; on those names to determine what IP addresses those are pointed to. Of course, for mail to actually work we&#039;d also need to insure mail server software is installed and configured on that server as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Again return to the domain zone overview page.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;We are now going to create a CNAME record. CNAME records are useful as they allow you to create virtual A records (aliases), but point them to another domain or host name instead of to a specific IP address. This allows you to have many hostnames all pointed to the same A record which contains the actual IP address so if the IP address changes you only need to change a single A record and all the hostnames will change. It can also be used to redirect a hostname at one domain to an entirely different domain.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the &#039;&#039;Edit Master Zone&#039;&#039; page for your domain, click the &#039;&#039;Name Alias&#039;&#039; button. For the &#039;&#039;Name&#039;&#039;, enter &#039;&#039;blog&#039;&#039; and for the &#039;&#039;Real Name&#039;&#039;, enter your domain &#039;&#039;debserv-*.test.&#039;&#039; but remember to put a period at the end of the domain as this is an &#039;&#039;absolute name&#039;&#039;. Press &#039;&#039;create&#039;&#039; to add the record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the &#039;&#039;Apply Configuration&#039;&#039; link at the top right of the page again. This will apply the records you have created. Now back in PuTTY, run:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup blog.debserv-*.test&amp;lt;/code&amp;gt;&lt;br /&gt;
or the equivalent &#039;&#039;&#039;dig&#039;&#039;&#039; command.&amp;lt;br&amp;gt; &lt;br /&gt;
You should get a response similar to:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Server:		127.0.0.1&lt;br /&gt;
Address:	127.0.0.1#53&lt;br /&gt;
&lt;br /&gt;
blog.debserv-*.test	canonical name = debserv-*.test.&lt;br /&gt;
Name:	debserv-*.test&lt;br /&gt;
Address: 172.17.50.XXX&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;One thing we can use CNAMEs for is to create virtual web hosts in Apache that listens for the domain blog.debserv-*.test, and then forwards you directly to your blog folder instead of to our main web page. &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039; under the &#039;&#039;Servers&#039;&#039; tab, select &#039;&#039;Apache Webserver&#039;&#039;. Then on the top, click the &#039;&#039;Create virtual host&#039;&#039; button and use the following configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;Handle Connections to Address: any address&lt;br /&gt;
Port: 80&lt;br /&gt;
Document Root: /var/www/html/blog/&lt;br /&gt;
Server Name: blog.debserv-*.test&lt;br /&gt;
Add virtual server to file: new file under virtual servers directory&lt;br /&gt;
Copy directives from: nowhere&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When done, press &#039;&#039;Create Now&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; When you are back at the &#039;&#039;Apache Webserver&#039;&#039; page, then click &#039;&#039;Apply Changes&#039;&#039; in the top right.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now in a SSH session, open up your favorite command line web browser like &#039;&#039;&#039;links&#039;&#039;&#039; and visit &#039;&#039;blog.debserv-*.test.&#039;&#039; make special note that when you enter the URL in Links you need to include the extra period at the end.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; This is because the .test domain is not a regular TLD like .com .org etc. and the Links browser doesn&#039;t know how to handle it unless we force it as a domain name by adding the period at the end. This is not related to it being a CNAME or our Apache configuration and with a regular domain name would not be required. Notice how you are now visiting the blog directly, instead of your modified index.html file. This is because we setup a virtual host in Apache that listens for requests to the CNAME we created and points to the document root where the Wordpress software is installed.&lt;br /&gt;
* Note that you will not be able to use this URL to access the blog from your local PC yet because your local PC isn&#039;t using your Linux server as it&#039;s DNS server and the .test domain isn&#039;t registered to your DNS server.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congrats, at this point you have a basic domain working with a MX, CNAME, and A record.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a AAAA record ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=sql0Wlo8F5g Video Tutorial: Adding an AAAA Record]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we are going to add an &#039;&#039;AAAA&#039;&#039; (IPv6 host) record to our domain. To do this, we will first need to make sure that IPv6 networking is setup in our virtual machine.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Use &amp;lt;code&amp;gt;ip address show&amp;lt;/code&amp;gt; to check the &#039;&#039;inet6&#039;&#039; address (IPv6 Address) on the primary network interface.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You should have an address starting with &#039;&#039;2607:f930:1c00:50:&#039;&#039;. If you do not please check with your instructor. You will need to write down or remember this full address as we will use it in Webmin to create our AAAA record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Back in &#039;&#039;&#039;Webmin&#039;&#039;&#039;, under the &#039;&#039;BIND DNS Server&#039;&#039; tab, select your &#039;&#039;debserv-*.test&#039;&#039; domain from the bottom and then click the &#039;&#039;IPv6 Address&#039;&#039; button. For the name, enter &#039;&#039;@&#039;&#039; and for the &#039;&#039;address&#039;&#039; enter your IPv6 address WITHOUT the subnet prefix (No /64 on the end).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; It should look similar to this: &#039;&#039;2607:f930:1c00:50:xxxx:xxxx:xxxx:xxxx&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When done click &#039;&#039;create&#039;&#039;. Remember to click the &#039;&#039;apply configuration&#039;&#039; link in the top right to apply the changes.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; In order to verify the AAAA record is working we need to modify the &#039;&#039;&#039;nslookup&#039;&#039;&#039; or &#039;&#039;&#039;dig&#039;&#039;&#039; command to check for AAAA records instead of the default of A records. Try:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nslookup -type=AAAA debserv-*.test&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
and&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dig debserv-*.test AAAA&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
to see the output from AAAA records.&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a dual-stack DNS records for your Debian server. This means your server is accessible from both IPv4 and IPv6 at the same name because both the A and AAAA records we created have the same host name).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding a Delegated Domain ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=Qn45Vv7vuZY Video Tutorial: Adding a Delegated Domain]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The problem with the name we have been using so far is that it only works on the DNS server itself. This is because we didn&#039;t purchase the name and so no other nameservers know to send requests for it to our server. Normally if you purchase a domain or someone else gives you control of a subdomain it is &#039;&#039;delegated&#039;&#039; to your server meaning that other DNS servers will query your server for addresses related to that name. In order to practice this we are going to add another domain to the system, but this domain will be a delegated domain which is a subdomain of &#039;&#039;itc2480.campus.ihitc.net&#039;&#039;. Luckily we can add this to BIND the same way we added our original domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In &#039;&#039;&#039;Webmin&#039;&#039;&#039;, go to &#039;&#039;Servers&#039;&#039;, then &#039;&#039;BIND DNS Server&#039;&#039;. Under &#039;&#039;Existing DNS Zones&#039;&#039; click on &#039;&#039;Create Master Zone&#039;&#039; and use the following settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;Zone type: Forward (Names to Addresses)&lt;br /&gt;
Domain name / Network: *.itc2480.campus.ihitc.net&lt;br /&gt;
Records file: Automatic&lt;br /&gt;
Master server: *.itc2480.campus.ihitc.net.&lt;br /&gt;
Email address: root@ *.itc2480.campus.ihitc.net&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;NOTE:&#039;&#039;&#039; the * stands for your System ID letter, the same as you used for the previous domain we created.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Using webmin, create an &#039;&#039;A&#039;&#039; record for &#039;&#039;@&#039;&#039; the same way as we did for the last domain.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; If you need help with this step, you can review the process we did earlier. Make sure to apply your changes after adding the record.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Test that the record and delegation are working correctly. This time you should be able to check from your host computer too!&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039; on &#039;&#039;*.itc2480.campus.ihitc.net&#039;&#039; (replace the * with your System ID). Does the correct address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Test your setup using a web browser on your local computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; can you access your webserver by going to http://*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create an &#039;&#039;MX&#039;&#039; record for the domain which directs mail for your delegated domain to your system as well just like we did with the test domain (this will involve creating another A record for &#039;&#039;mail.*.itc2480.campus.ihitc.net&#039;&#039; as well).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test that the MX record and associated A record are working correctly. This time you should be able to check from your host computer too! Windows does not include the &#039;&#039;&#039;dig&#039;&#039;&#039; command so you&#039;ll need to use &#039;&#039;&#039;nslookup&#039;&#039;&#039;. Does the correct mail server name and address come back?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a &#039;&#039;CNAME&#039;&#039; record for the blog just like in the previous example (&#039;&#039;blog.*.itc2480.campus.ihitc.net&#039;&#039;&#039; though) and create a new Apache virtual server just like in the previous example as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Test your setup using a web browser on your local computer, can you access your blog directly by going to http://blog.*.itc2480.campus.ihitc.net (where * is your hostname letter)?&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manually editing a zone file ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[[https://www.youtube.com/watch?v=3T7TkE9cRVE Video Tutorial: Manually Editing a Zone File]]&#039;&#039;&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Lastly we are going to look at the domain zone file. While Webmin provides a nice interface to add records, all it is doing is manually adding our records to our text based zone file. When you use BIND for DNS, every domain created gets its own record file which is called the zone file. In this file all subdomains and records are stored for said domain.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;By default, the location for these records on Debian will be in &#039;&#039;/var/lib/bind&#039;&#039;, so go to that directory and list the contents.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Now, with your favorite text editor, open up the file which corresponds to the &#039;&#039;debserv-*.test&#039;&#039; domain.&amp;lt;br&amp;gt;&lt;br /&gt;
It should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ttl 38400&lt;br /&gt;
debserv-Z.test. IN      SOA     2480-Z.itc2480.campus.ihitc.net. root.debserv-Z.test. (&lt;br /&gt;
                        1519434495&lt;br /&gt;
                        10800&lt;br /&gt;
                        3600&lt;br /&gt;
                        604800&lt;br /&gt;
                        38400 )&lt;br /&gt;
debserv-Z.test. IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
debserv-Z.test. IN      A       172.17.50.36&lt;br /&gt;
debserv-Z.test. IN      MX      10 mail.debserv-Z.test.&lt;br /&gt;
mail.debserv-Z.test.    IN      A       172.17.50.36&lt;br /&gt;
blog.debserv-Z.test.    IN      CNAME   debserv-z.test.&lt;br /&gt;
debserv-Z.test. IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
mail.debserv-Z.test.    IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice the formatting for domain records. Each record is defined by the domain or subdomain name, &#039;&#039;IN&#039;&#039;, then the record type (like A, AAAA, NS, or MX), followed by what the record is pointed to. For this example, we want to change the MX priority from 10 to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using your text editor change the MX record settings priority from 10 to 15.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;When you are done, &#039;&#039;&#039;restart&#039;&#039;&#039; the bind9 service to reload the changes.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo systemctl restart bind9&amp;lt;/code&amp;gt;&lt;br /&gt;
* Note: when restarting bind, if you have any errors restarting the service this normally means you have a typo in one of your zone files. If this is the case, go through the file again in a text editor to make sure you did not add anything extra or remove anything else.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the &#039;&#039;&#039;dig&#039;&#039;&#039; tool to check the MX record and see that the new priority is active. You should see something similar to the following response:&lt;br /&gt;
&amp;lt;pre&amp;gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.3-P4-Debian &amp;lt;&amp;lt;&amp;gt;&amp;gt; debserv-z.test MX&lt;br /&gt;
;; global options: +cmd&lt;br /&gt;
;; Got answer:&lt;br /&gt;
;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 40128&lt;br /&gt;
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 3&lt;br /&gt;
&lt;br /&gt;
;; OPT PSEUDOSECTION:&lt;br /&gt;
; EDNS: version: 0, flags:; udp: 4096&lt;br /&gt;
;; QUESTION SECTION:&lt;br /&gt;
;debserv-z.test.                        IN      MX&lt;br /&gt;
&lt;br /&gt;
;; ANSWER SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      MX      15 mail.debserv-Z.test.&lt;br /&gt;
&lt;br /&gt;
;; AUTHORITY SECTION:&lt;br /&gt;
debserv-Z.test.         38400   IN      NS      2480-Z.itc2480.campus.ihitc.net.&lt;br /&gt;
&lt;br /&gt;
;; ADDITIONAL SECTION:&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      A       172.17.50.36&lt;br /&gt;
mail.debserv-Z.test.    38400   IN      AAAA    2607:f930:1c00:50:250:56ff:feb1:8756&lt;br /&gt;
&lt;br /&gt;
;; Query time: 0 msec&lt;br /&gt;
;; SERVER: 127.0.0.1#53(127.0.0.1)&lt;br /&gt;
;; WHEN: Fri Feb 23 20:15:48 CST 2018&lt;br /&gt;
;; MSG SIZE  rcvd: 163&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;Notice how the Answer Section shows the MX record is pointed to the IP of the domain, and that the priority is set to 15.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Congratulations, you have now setup a functional DNS server.&amp;lt;/li&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=Lab_12_mnjk&amp;diff=9218</id>
		<title>Lab 12 mnjk</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=Lab_12_mnjk&amp;diff=9218"/>
		<updated>2021-02-12T01:17:02Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: /* Monitoring Services and Graphing System Statistics with Zabbix */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
In this lab you will learn about several Linux utilities which can be used for monitoring Linux and other systems for security and service uptime purposes.&lt;br /&gt;
&lt;br /&gt;
In this lab you will perform the following tasks:&lt;br /&gt;
* Monitor connections with [https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/netstat netstat]&lt;br /&gt;
* Scan for open ports using [https://nmap.org/ nmap]&lt;br /&gt;
* Monitor services with [https://www.zabbix.com/ zabbix]&lt;br /&gt;
&lt;br /&gt;
You will use the following commands: &lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/netstat netstat]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/ps ps]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/grep grep]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/1/nmap namp]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://linux.die.net/man/8/service service]&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[https://www.man7.org/linux/man-pages/man1/systemctl.1.html systemctl]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Lab Procedure=&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account&lt;br /&gt;
# The IP address of a partner&#039;s system which you have permission to portscan&lt;br /&gt;
&lt;br /&gt;
== Monitoring connections with netstat ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=51eo20xbSxs Video Tutorial - Monitoring Connections with Netstat]&#039;&#039;&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
One common activity you would want to do when evaluating the security of a system is to find out what ports the system is accepting connections on. For this reason most operating systems have some kind of utility to display active network connections and open ports, Linux is no exception. The netstat utility can show you currently active network connections as well as open ports on your local system. Take a look at the man page for the [https://linux.die.net/man/1/nmap &#039;&#039;&#039;netstat&#039;&#039;&#039;] command. Specifically, figure out what the &#039;&#039;-n -a -t -p&#039;&#039; and &#039;&#039;-u&#039;&#039; options do.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Run the &#039;&#039;&#039;netstat&#039;&#039;&#039; command on your system and observe the output.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo netstat -natup&amp;lt;/code&amp;gt;&lt;br /&gt;
* Try to identify what the purpose of each open port on your system is. There are many online guides to common uses for ports.&lt;br /&gt;
&amp;lt;li&amp;gt; Use the &#039;&#039;&#039;sudo ps aux&#039;&#039;&#039; command (along with &#039;&#039;&#039;grep&#039;&#039;&#039;) to match the PID (process ID) numbers of open ports shown in &#039;&#039;&#039;netstat -natup&#039;&#039;&#039; with specific processes on your system.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Connect to the IP address or domain name of your system through your web browser and re-run the &#039;&#039;&#039;netstat -natup&#039;&#039;&#039; command to see the TCP session established by your browser to download the website.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; You&#039;ll find that there are a number of ports open on your system. Some of these we have opened to provide a specific service such as SMTP, DNS, Webserver, etc. but some such as the sunrpc port are open simply by default on a fresh install. There are a number of different strategies you can use to secure your system including disabling a service, binding it to an internal-only IP address, or blocking access with a firewall rule. If your firewall is setup with an implicit (or explicit) reject any rule at the bottom of the input chain and you have not specifically opened a port it should not be accessible from other systems. How can we test that though? The &#039;&#039;&#039;netstat&#039;&#039;&#039; utility is useful at making a list of ports somehow open on the system but it does not show us how those ports react if someone outside actually tries to connect.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scanning ports using nmap ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=DzxpMPtGsGM Video Tutorial - Scanning Ports with nmap]&#039;&#039;&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
The nmap Network Mapper utility is a very powerful security scanning utility available on Linux. While netstat uses information from the Linux kernel about what ports and connections are in use by what processes nmap actively probes and tests ports on your system or another system to determine whether the port is open or not as well as additional information about the port in some cases. Unlike netstat, nmap is not part of the default Debian installation so you will need to install the nmap package before proceeding. nmap is complex and powerful. Entire [http://nmap.org/book/toc.html books] and [http://nmap.org/book/man.html extensive documentation] are available which you may want to reference but we&#039;ll only be exploring some of the more basic features in this introduction.&lt;br /&gt;
: &#039;&#039;NOTE: Before we begin this section of the lab it is important to remember that scanning a system is often seen as an attack against the system and should not be done unless you are the administrator of both the system that you are scanning from and the system you are scanning or have the explicit permission of the system administrator of those systems! In some areas people have been legally charged and prosecuted for scanning of systems which they are not authorized to do. You have been warned!&#039;&#039;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Make sure &#039;&#039;&#039;nmap&#039;&#039;&#039; is installed&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;sudo apt install nmap&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&#039;&#039;&#039;nmap&#039;&#039;&#039; provides a system on the Internet which they allow you to scan for testing purposes so let&#039;s try a verbose scan which gives additional diagnostic detail.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;nmap -v scanme.nmap.org&amp;lt;/code&amp;gt;&lt;br /&gt;
* Review the output and then run the same command without the &#039;&#039;-v&#039;&#039; verbose option and compare the output you receive.&lt;br /&gt;
&amp;lt;ul&amp;gt; When scanning your own system there are a few different ways to go about it. You could either scan the localhost address 127.0.0.1 or the actual outside IP address of your system. You could also setup a separate system or VM and do the scanning from that system. In each case you might see somewhat different results, can you guess why?&amp;lt;/ul&amp;gt;&lt;br /&gt;
* The answer is related to how you have firewall rules setup and what addresses you have services bound to. For example by default on Debian systems the mySQL/MariaDB server daemon only listens for connections on the localhost address (127.0.0.1) and not on outside interfaces. Try running the &#039;&#039;&#039;nmap 127.0.0.1&#039;&#039;&#039; command and then compare output with the &#039;&#039;&#039;nmap &amp;lt;your outside ip address here&amp;gt;&#039;&#039;&#039; command. Do you see some network services listening only on the localhost address. These services are not accessible from outside your computer even though the ports are open and you would see them as open with &#039;&#039;&#039;netstat&#039;&#039;&#039;. This shows us some of the additional value of using &#039;&#039;&#039;nmap&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;li&amp;gt; The most realistic use of &#039;&#039;&#039;nmap&#039;&#039;&#039; though is to scan like an attacker would using a system outside of the one you&#039;re testing. Use &#039;&#039;&#039;nmap&#039;&#039;&#039; to scan a partner&#039;s IP address in the class and take a look at some of the &#039;&#039;&#039;nmap&#039;&#039;&#039; documentation to try a few different types scans on that system. If you would like you can also try scanning the entire ITC-2480 subnet (172.17.50.0/24) if you want to try some subnet scanning capabilities.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt; Remember that in our case these systems are secure from the outside world because we have an upstream firewall which you have bypassed by connecting to our VPN and these systems are using unroutable private IPv4 addresses.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &#039;&#039;&#039;nmap&#039;&#039;&#039; also supports scanning IPv6 addresses. Note that a running service is not necessarily listening on both IPv4 and IPv6 addresses just because you have them both active on your machine. Figure out how to scan IPv6 addresses with &#039;&#039;&#039;nmap&#039;&#039;&#039; and try scanning both an IPv4 and IPv6 address of your machine and compare the results. Use the same type of address (i.e. both IPv4 and Ipv6 addresses should be the localhost addresses or should both be outside addresses) Are the same services open on both IPv4 and IPv6 on your system?&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Monitoring Services and Graphing System Statistics with Zabbix==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;[https://www.youtube.com/watch?v=fF5NNRJwLjg Video Tutorial - Monitoring with Zabbix]&#039;&#039;&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
In this section we will be following the instruction on how to install zabbix using [https://www.zabbix.com/download?zabbix=5.0&amp;amp;os_distribution=debian&amp;amp;os_version=10_buster&amp;amp;db=mysql&amp;amp;ws=apache these instructions on the Zabbix site].&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Go to the instructions link above and scroll down to &#039;&#039;&#039;part 2&#039;&#039;&#039;. Start by installing the zabbix repository.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;wget https://repo.zabbix.com/zabbix/5.0/debian/pool/main/z/zabbix-release/zabbix-release_5.0-1+buster_all.deb&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;dpkg -i zabbix-release_5.0-1+buster_all.deb&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;apt update&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install Zabbix server, frontend, agent&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Create a database, a user, and schema following the instructions on the same website.&lt;br /&gt;
: &#039;&#039;NOTE: These instructions use the MySQL/MariaDB command line, if you prefer you can create the same database, user, and schema using the Webmin software but you&#039;ll have to translate the command line instructions into the actions required in Webmin.&#039;&#039;&lt;br /&gt;
&amp;lt;code&amp;gt;mysql -uroot -p&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;create database zabbix character set utf8 collate utf8_bin;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;create user zabbix@localhost identified by &#039;password&#039;;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Replace password with a password you want to use. (Command needs the quotes so don&#039;t remove them).&lt;br /&gt;
&amp;lt;code&amp;gt;grant all privileges on zabbix.* to zabbix@localhost;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;quit;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On Zabbix server host import initial schema and data. You will be prompted to enter your newly created password used when setting up the mysql database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Edit the server configuration file ( &#039;&#039;/etc/zabbix/zabbix_server.conf&#039;&#039; ) to include the correct database password used when you setup the database above. ( &#039;&#039;DBPassword=&amp;lt;password&amp;gt;&#039;&#039; )&lt;br /&gt;
: [[File:DBPassword.png | 500px]]&lt;br /&gt;
&amp;lt;li&amp;gt;Edit the server configuration file ( &#039;&#039;/etc/zabbix/apache.conf&#039;&#039; ) to include the correct timezone. [https://www.php.net/manual/en/timezones.php A list of valid PHP timezones can be found here.] We will be using &#039;&#039;America/Chicago&#039;&#039;.&amp;lt;/li&amp;gt;&lt;br /&gt;
: [[File:Apache_timezone.png | 500px]]&lt;br /&gt;
&amp;lt;li&amp;gt;Restart the server. Then set it to auto start on startup:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;systemctl restart zabbix-server zabbix-agent apache2&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;systemctl enable zabbix-server zabbix-agent apache2&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Access the Zabbix web application at http://yourserver/zabbix/ and complete the setup wizard. [https://www.zabbix.com/documentation/5.0/manual/installation/frontend Detailed instructions for completing the setup wizard can be found here on the Zabbix site.]&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;ul&amp;gt; At the end of the setup wizard you may need to download a &#039;&#039;zabbix.conf.php&#039;&#039; and save it to &#039;&#039;/etc/zabbix/zabbix.conf.php&#039;&#039; on your system.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Login to http://yourserver/zabbix/ (where yourserver is the IP address or DNS name for your system) with the username and password found [https://www.zabbix.com/documentation/5.0/manual/quickstart/login on the Zabbix site login instructions].&amp;lt;/li&amp;gt;&lt;br /&gt;
: [[File:Enable_monitoring_zabbix.png | 500px]]&lt;br /&gt;
&amp;lt;ul&amp;gt;The default superuser credentials are user name &#039;&#039;&#039;Admin&#039;&#039;&#039; with password &#039;&#039;&#039;zabbix&#039;&#039;&#039;.&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Enable monitoring of your Zabbix server host (&#039;&#039;Configuration&#039;&#039; -&amp;gt; &#039;&#039;Hosts&#039;&#039;)&amp;lt;/li&amp;gt;&lt;br /&gt;
: [[File:Enable_monitoring_zabbix.png | 500px]]&lt;br /&gt;
: &#039;&#039;NOTE: [https://www.zabbix.com/documentation/5.0/manual The Zabbix manual] may be helpful in completing these monitoring setup tasks.&#039;&#039;&lt;br /&gt;
* Add the templates to the host appropriate for the services we are running on the server (HTTP, IMAP, MySQL, SMTP, SSH)&lt;br /&gt;
: [[File:Zabbix_templates.png | 500px]]&lt;br /&gt;
* Explore some of the data available through Zabbix such as various graphs (&#039;&#039;Monitoring&#039;&#039; -&amp;gt; &#039;&#039;Graphs&#039;&#039;), Latest Data (&#039;&#039;Monitoring&#039;&#039; -&amp;gt; &#039;&#039;Latest Data&#039;&#039;), Screens (&#039;&#039;Monitoring&#039;&#039; -&amp;gt; &#039;&#039;Screens&#039;&#039;), and Events (&#039;&#039;Monitoring&#039;&#039; -&amp;gt; &#039;&#039;Events&#039;&#039;)&lt;br /&gt;
* Try temporarily stopping some of the services on your system (to simulate a problem) such as the Postfix SMTP server, &#039;&#039;courier-imap&#039;&#039; server, etc. using the command line &#039;&#039;&#039;service&#039;&#039;&#039; command.&lt;br /&gt;
* Re-check the data in Zabbix with the services turned off, are you alerted of the problems? Make sure to turn the services back on when you&#039;re done.&lt;br /&gt;
: &#039;&#039;NOTE: Most services will not instantaneously show as down, the templates for the service probably check it once per minute or less so you may need to leave things down for a bit to see it in the Web UI.&#039;&#039;&lt;br /&gt;
* If you have additional time see if you can get email notifications of failed services working (see &#039;&#039;Administration&#039;&#039; -&amp;gt; &#039;&#039;Media Types&#039;&#039; -&amp;gt; &#039;&#039;Email and Configuration&#039;&#039; -&amp;gt; &#039;&#039;Actions&#039;&#039;)&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=File:Zabbix_templates.png&amp;diff=9217</id>
		<title>File:Zabbix templates.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=File:Zabbix_templates.png&amp;diff=9217"/>
		<updated>2021-02-12T01:16:54Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=File:Zabbix_wizard.png&amp;diff=9201</id>
		<title>File:Zabbix wizard.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=File:Zabbix_wizard.png&amp;diff=9201"/>
		<updated>2021-02-12T00:56:27Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=File:Enable_monitoring_zabbix.png&amp;diff=9200</id>
		<title>File:Enable monitoring zabbix.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=File:Enable_monitoring_zabbix.png&amp;diff=9200"/>
		<updated>2021-02-12T00:55:23Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=File:Apache_timezone.png&amp;diff=9195</id>
		<title>File:Apache timezone.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=File:Apache_timezone.png&amp;diff=9195"/>
		<updated>2021-02-12T00:52:56Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
	<entry>
		<id>https://wiki.ihitc.net/mediawiki/index.php?title=File:DBPassword.png&amp;diff=9192</id>
		<title>File:DBPassword.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.ihitc.net/mediawiki/index.php?title=File:DBPassword.png&amp;diff=9192"/>
		<updated>2021-02-12T00:51:27Z</updated>

		<summary type="html">&lt;p&gt;KreidKolo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KreidKolo</name></author>
	</entry>
</feed>