Você está na página 1de 16

Linux Lab Manual Networking

Preface
This Lab introduce the student the networking concepts of Linux. Ubuntu
Linux is one of a number of different flavors of the Linux operating system. As System Administrator we need to know how to install and configure open source

SYSTEM ADMINISTRATION

technologies like linux. The list of topics

discuss are: History of Linux and Ubuntu Networking Configuration in Linux Managing Users and Groups File Server Services using Samba Web Server Services using Apache Chapter Objectives At the end of the chapter, the

LINUX LAB MANUAL

students will be able to:


Know and understand the history and concept of linux in networking Install and configure managing users and groups in linux Install and Configure File Server using Samba Install and configure Web Server using Apache

INSY571

By: Dr. Patrick D. Cerna

Page 1

Linux Lab Manual Networking

1. The History of Ubuntu Linux


Ubuntu Linux is one of a number of different flavors of the Linux operating system. The various different brands of Linux are generally known as Linux Distributions (usually shortened to Linux Distros by Linux experts). In terms of the history of Linux, Ubuntu is something of a newcomer. In the relatively short period of time that it has been available, however, Ubuntu has rapidly gained the respect of both experienced and novice Linux users throughout the world. Who Created Linux? The origins of Linux can be traced back to the work of two people. At the heart of the Linux operating system is something called the kernel. This is the core set of functions necessary for the operating system to function. The kernel manages the system's resources and handles communication between the hardware and the applications. The Linux kernel was developed by Linus Torvalds who needed an operating system but didn't want to have to buy one. When he had finished the first version of the kernel he released under an open source license that enabled anyone to download the source code and freely use and modify it without having to pay Linus any money.

What Exactly is Linux? Linux is an operating system in much the same way that Windows is an operating system (and there any similarities between Linux and Windows end). The term operating system is used to describe the software which acts as a layer between the hardware in a computer and the applications that we all run on a daily basis. When programmers write applications, they interface with the operating system to perform such tasks as writing files to the hard disk drive and displaying information on the screen. Without an operating system, every programmer would have to write code to directly access the hardware of the system. In addition, the programmer would have to be able to support every single piece of hardware ever created to be sure the application would work on every possible hardware configuration. Because the operating system handles all of this hardware complexity, application development becomes a much easier task. Linux is just one of a number of different operating systems available today. The History of Ubuntu As mentioned previously, Ubuntu is one of a number of Linux distributions. The source code that makes up the Ubuntu Linux distribution originates from another, much older Linux distribution known as Debian (so called because it was started by two people named Debra and Ian). Debian is still a widely respected operating system but came under criticism for infrequent updates and less than user friendly installation and maintenance (though these areas have shown improvement recently). Ubuntu has since gone from strength to strength. Dell and other hardware vendors now ship computers pre-loaded with Ubuntu Linux and Ubuntu usually tops the chart at DistroWatch.com (a web site which tracks the popularity of the various Linux distributions).

INSY571

By: Dr. Patrick D. Cerna

Page 63

Linux Lab Manual Networking If you are new to Linux, or already use Linux and want to try a different Linux distro it is unlikely you will find a better option than Ubuntu Linux.

What does the word "Ubuntu" Mean? The word "Ubuntu" is an ancient Zulu and Xhosa word which means "humanity to others". Ubuntu also means "I am what I am because of who we all are". It was chosen because these sentiments precisely describe the spirit of the Ubuntu Linux distribution.

2. Configuring IP Address in Ubuntu from Command Line


After installing Ubuntu Linux the IP address was assigned by DHCP served by my home router. This is fine for getting the server installed, but under most conditions, you will want to assign a static IP for your server. This topic will show you how to do just that. One of the issues with the Ubuntu is configuration can be done from a command line. One thing to note is that these commands need to be issued from either root or using sudo. I prefer to use the sudo su method to avoid having to type sudo each time I issue a command. (WARNING) if you do use sudo su, remember to exit the root when you are done. In this example, I will be assigning the a static IP address of 192.168.1.2 to the primary network interface on my server. My network subnet is 192.168.1.0 My network gateway is 192.168.1.3 And my netmask is 255.255.255.0

1. Gain root privledges sudo su Enter your password when prompted You should now have root access. 2. Backup your interfaces file cp /etc/network/interfaces /etc/network/interfaces.backup It is important to always create a backup of important files in case you need to restore your original files/settings. 3. Edit the Interfaces file Now using a text editor, modify the /etc/network/interfaces file. I prefer to use nano, but you can use any editor you prefer. For this example, I am going to use 192.168.1.2 as my static ip address. INSY571 By: Dr. Patrick D. Cerna Page 64

Linux Lab Manual Networking The original the interfaces file looks like this: # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp To set a static IP, you need to change the line under The primary network interface to something like this. # The primary network interface auto eth0 iface eth0 inet static address 192.168.1.2 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.3 5. Confirm Your Changes Your edited interfaces file should now look something like this. # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.168.1.2 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.3 6. Save Your Changes and Restart Networking If your changes are correct, you now need to save them to the interfaces file. If you used Nano, to save the new file, you press Ctrl-o to write the changes (hit enter when asked to overwrite the existing file) and the Ctrl-x to quit nano. Once your changes are saved you need to restart the networking service on the server by issuing the following command. /etc/init.d/networking restart

INSY571

By: Dr. Patrick D. Cerna

Page 65

Linux Lab Manual Networking 7. Test and Confirm If everything went well, you now have a static IP assigned to the eth0 network interface. To test and make sure your changes were applied successfully, issue this command: ifconfig eth0 Your output should look something like this: eth0 Link encap:Ethernet HWaddr 00:02:E3:09:C2:FB inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::202:e3ff:fe09:c2fb/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:512598 errors:0 dropped:0 overruns:0 frame:0 TX packets:5428 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:30923166 (29.4 MB) TX bytes:547585 (534.7 KB) Interrupt:10 Base address:0x6000 Note the second line inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0 now shows the correct static ip, Bcast and Mask information that we assigned. If you gained root by using the sudo su option, remember to exit root by simply issuing the exit command.

3. Managing Ubuntu Linux Users and Groups


Linux is a multi-user operating system. This means that more than one user can be actively logged and using the system at any one time. Obviously, it makes sense for each user to have their own user account and home directory, and for different users to have different privileges. Users are further divided into groups for the purposes of easier administration and those groups can have different levels of privileges. For example, you may have a group of users who work in the Accounting department. In such an environment you may wish to create an accounts group and assign all the Accounting department personnel to that group. In this Topic we will cover the steps to add, remove and manage users and groups on an Ubuntu Linux system.

Adding a User to an Ubuntu Linux System There are two methods for adding new users to a system, one way is using the graphical User settings tool and the other is to use the adduser command-line tool. In this section we will look at both approaches. As mentioned above it is also possible to add new users from the command-line. To do so, start a terminal window session and at the command prompt enter a command similar to:

INSY571

By: Dr. Patrick D. Cerna

Page 66

Linux Lab Manual Networking

sudo adduser --home /home/john john The above command will prompt for a password for the account and optional contact information. Once the information has been gathered adduser creates the new account and the /home/john home directory. The adduser tool provides a number of different options, details of which can be learned by reviewing the adduser man page as follows: man adduser Editing the Properties of a User The properties of a user may be changed using the same User settings dialog used to add a user as outlined above. Select the Systemdesktop menu and choose Users and Groups from the Administration sub-menu to launch the User settings dialog. To make changes to the user properties select the user from the list and click on Properties. Work through the various screens in the Account Properties for the selected user and click on the OK button to apply the changes. Deleting a User from an Ubuntu Linux System An existing user may be deleted using the same User settings dialog used to add a user as outlined above. Select the System desktop menu and choose Users and Groups from the Administration sub-menu to launch the User settings dialog. Select the user to be deleted and click on Delete. A confirmation dialog will appear. If you wish to proceed click on Delete in the confirmation dialog to commit the change. Note that the deletion process will remove the account but leave the user's home directory intact. This will need to be deleted manually if it, and any files therein, are no longer required. A user account may also be deleted from command-line using the deluser utility: sudo deluser john It is also possible to remove the user's home directory as part of the deletion process: sudo deluser --remove-home john Alternatively all files owned by the user, including those in the user's home directory may be removed as follows: sudo deluser --remove-all-files john The files in the user's home directory can also be backed up to another location before the directory is deleted using --backup-to command-line option together with the path to the backup directory:

INSY571

By: Dr. Patrick D. Cerna

Page 67

Linux Lab Manual Networking

sudo deluser --backup-to /oldusers/backups/john --remove-home john Adding a New Group to an Ubuntu Linux System All users are members of one or more groups. As an administrator it makes sense to organize users into logical groups. For example all sales people might belong to a sales group, whilst accounting staff might belong to the accounts group and so on. New groups are added either using the Users settings graphical tool, or by using the addgroup command-line tool. In this section we will look at both methods. To access the User settings dialog select the desktop System menu and choose Users and Groups from the Administration sub-menu. To administer the group settings click on the Manage Groups button. The Group settings dialog will appear, listing all the groups available on the system:

To add a new group click on the Add Group and enter the name of the group you wish to add. Add the users that should belong to this group by checking the box next to each user name in the list. For example the following screenshot shows user John Smith being added to the new accounts group:

INSY571

By: Dr. Patrick D. Cerna

Page 68

Linux Lab Manual Networking

Click on OK to add the new group to the system. Modifying an Ubuntu Linux Group To modify an Ubuntu user group, select the group to modify from the list of groups in the Group settings dialog (as outlined above) and click on Properties. The resulting Group properties dialog (shown below) allows basic settings such as the group ID, group name and group members to be changed.

INSY571

By: Dr. Patrick D. Cerna

Page 69

Linux Lab Manual Networking

To add a group from the command line, use the addgroup utility. For example: sudo addgroup accounts To add an existing user to an existing group: sudo adduser john accounts Deleting a Group from an Ubuntu Linux System A group may be deleted from a system using the delgroup utility: sudo delgroup accounts Note that if the group to be deleted is the primary group for any user it cannot be deleted. A group can be deleted only if it is empty using the following command: sudo delgroup --only-if-empty accounts To remove a user from membership of a group use the following command syntax: sudo deluser john accounts

4. Installing and Configuring an Ubuntu Linux Based Web Server

It is surprising the number of people who now host their own web sites. Some reasons for this are that doing so is now relatively easy and many people now have high speed internet connections. In addition, Linux provides a free, enterprise level operating system with everything needed to create a web server for free (with the exception of the hardware of course). In this chapter we will explain how to configure an Ubuntu system to act as a web server.

Requirements for Configuring a Web Server

To set up your own web site you need a computer, an operating system, a web server, a domain name, a name server and an IP address. INSY571 By: Dr. Patrick D. Cerna Page 70

Linux Lab Manual Networking The computer can be any system capable of running Linux. In terms of an operating system, we will assume you are using Ubuntu Linux. Ubuntu supports the Apache web server which can easily be installed once Ubuntu is up and running. A domain name can be registered with any domain name registration service. If your ISP provides static IP addresses then you will need to associate your domain with your static IP address. This is achieved using a name server. Some domain registration services will provide this service for you. If yours does not, you can create a free account at http://www.zoneedit.com and use their name servers to point your domain name at your static IP address. If you do not have a static IP address (i.e. your ISP provides you with a dynamic address which changes frequently) then you can use one of a number of free services that map your dynamic IP address to your domain name. One such service is provided by http://www.dnsExit.com. Once you have your domain name and your name server configured the next step is to install and configure your web server.

5. Installing and Configuring File Server using Samba


Samba is a Linux/UNIX software package that allows you to share files and directories with computers running other operating systems over the network. It also allows your Linux desktop or laptop to sign into a Windows network and be able to share files inside a workgroup. There are several advanced features that Samba comes with, such as domain controller. We will look at how to convert your Ubuntu box into a Samba file server and configure it to share directories with different combinations of permissions. Step 1: Installing Samba Distributions such as Ubuntu have made the installation of just about anything so simple and straightforward with smart package management that you can have pretty much any software installed with a one-line command. To install Samba on your Ubuntu computer, execute the following: # sudo apt-get update # sudo apt-get install libcupsys2 samba samba-common Or

sudo apt-get install samba smbfs

INSY571

By: Dr. Patrick D. Cerna

Page 71

Linux Lab Manual Networking Here we are requesting Ubuntu to install three packages. The first one is to share your printer, the other two are Samba and its support packages. Step 2: Configuration file The configuration files of Samba are stored in the /etc/samba/ directory. The first thing you should do before we dive into the configuration of Samba is to make a backup of the main configuration file. # cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

Now open the file with your favourite text editor and lets make some configuration changes: # sudo vim /etc/samba/smb.conf

Step 3: Basic configuration When you have opened the file, scroll down a bit and look for a section called Authentication. This section will have a configuration area that looks like the following: # security = user is always a good idea. This will require a Unix account # in this server for every user accessing the server. See # /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/ServerType.html # in the samba-doc package for details. # security = user

Comment out the security = user bit by removing the # or at the beginning of the line. What this setting change does is that it now allows users registered on the Linux system to log into the Samba server using their username. Alternative Solution:

Find this section in the file: ####### Authentication ####### # security = user is always a good idea. This will require a Unix account # in this server for every user accessing the server. See INSY571 By: Dr. Patrick D. Cerna Page 72

Linux Lab Manual Networking # /usr/share/doc/samba-doc/htmldocs/Samba-HOWTO-Collection/ServerType.html # in the samba-doc package for details. ; security = user Uncomment the security line, and add another line to make it look like this: security = user username map = /etc/samba/smbusers This will set Samba to use the smbusers file for looking up the user list.

Step 4: Workgroup Another thing that you might want to change, depending upon how your current network is set up, is the workgroup settings of your Samba server. Look for the following line: # Change this to the workgroup/NT-domain name your Samba server will part of workgroup = WORKGROUP

If you already have a workgroup set up, or are in a network with a Windows Server, you can change the workgroup setting from WORKGROUP to whatever is being used currently on your network. Alternatively you could set something new and start a new workgroup for your network. MS Windows-based networks often use the workgroup MSHOME. Step 5: Start Samba At this point you can save the Samba configuration file, smb.conf, and restart the Samba service. This can be done in several ways. If you want to use the command-line interface, execute the following command: # sudo /etc/init.d/samba restart

Step 6: Create a Samba User There are two steps to creating a user. First well run the smbpasswd utility to create a samba password for the user. sudo smbpasswd -a <username> Next, well add that username to the smbusers file. sudo gedit /etc/samba/smbusers

INSY571

By: Dr. Patrick D. Cerna

Page 73

Linux Lab Manual Networking Add in the following line, substituting the username with the one you want to give access to. The format is <ubuntuusername> = <samba username>. You can use a different samba user name to map to an ubuntu account, but thats not really necessary right now. <username> = <username> Now you can create samba shares and give access to the users that you listed here.

Step 7: Share Home Directories To share the home directories, open up smb.conf with the following command: sudo gedit /etc/samba/smb.conf Find this section of the file, and make it match the following: #======================= Share Definitions ======================= # Un-comment the following (and tweak the other settings below to suit) # to enable the default home directory shares. This will share each # users home directory as \\server\username [homes] comment = Home Directories browseable = yes # By default, \\server\username shares can be connected to by anyone # with access to the samba server. Un-comment the following parameter # to make sure that only username can connect to \\server\username valid users = %S # By default, the home directories are exported read-only. Change next # parameter to yes if you want to be able to write to them. writable = yes Now you should be able to map a drive on windows using the following share format: \\ubuntumachine\username For example, if the Ubuntu machine is named ubuntuserv, and the username is geek, your share path would be \\ubuntuserv\geek

INSY571

By: Dr. Patrick D. Cerna

Page 74

Linux Lab Manual Networking

6. Installing the Apache Web Server on Ubuntu Linux


The standard web server on Linux is Apache. The web server is the technology that receives
requests from web browsers and serves up the requested web pages to those browsers. The desktop version of Ubuntu Linux does not install the Apache web server by default. The first step in setting up a web server, therefore, is to install Apache. This can be performed either from the command-line or using the Synaptic Package Manager. To use the Synaptic Package Manager, click on the System menu, select Administration and click on Synaptic Package Manager. Enter your password if prompted to do so. Click on the Search toolbar button and search for apache2. After the search completes, the Apache 2 Server should be listed in the Synaptic window. Click on the toggle next to the Apache server and select Mark for installation. Finally, click on Apply in the toolbar to begin the installation. To install Apache from the command-line start a terminal window (Applications->Accessories>Terminal) and run the following command at the command prompt: sudo apt-get install apache2 The installation process will not only install, but also start up the web server. Testing the Web Server Once the installation is complete the next step is to verify the web server is up and running. To do this fire up the web browser by clicking on the Firefox logo and enter 127.0.0.1 in the address bar (127.0.0.1 is the loop-back network address which tells the system to connect to the local machine). The browser should load a page that reads It works!. Congratulations, you have now installed the web server and served up what will hopefully be the first of many web pages. Configuring the Apache Web Server for Your Domain The next step in setting up your web server is to configure it for your domain name. This is performed in the /etc/apache2 directory. To configure the web server open a terminal window and change directory to /etc/apache2. In this directory you will find two sub-directories,sitesavailable and sites-enabled. Change directory into sites-available. In this directory you will find a default file which may be used as a template for your own site. Copy the default file to a new file with a name which matches your domain name. For example: sudo cp default myexample.com Edit your myexample.com file using your favorite editor using the sudo command to ensure you have write permission to the file. The top of the file will appear as follows: <VirtualHost *> ServerAdmin webmaster@localhost DocumentRoot /var/www/ <Directory /> Options FollowSymLinks INSY571 By: Dr. Patrick D. Cerna Page 75

Linux Lab Manual Networking

AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all # This directive allows us to have apache2's default start page # in /apache2-default/, but still have / go to the right place #RedirectMatch ^/$ /apache2-default/ </Directory>

If you are using an older version of Ubuntu, the file on your system may have a NameVirtualHost line at the top of the file. If so, comment it out by prefixing it with a '#' character: #NameVirtualHost * The reason for this is that this directive is already specified in the sites-enabled/000-default file. NameVirtualHost 68.206.209.234 If the above line is not commented out the following warning will appear when the Apache server is restarted: [warn] NameVirtualHost *:0 has no VirtualHosts The ServerAdmin directive defines an administrative email address for people wishing to contact the web master for your site. Change this to an appropriate email address where you can be contacted: ServerAdmin webmaster@myexample.com Next the ServerName and ServerAlias directives need to be defined so that the web server knows which virtual host this configuration file refers to: ServerName myexample.com ServerAlias www.myexample.com In the next stage we need to define where the web site files are going to be located using the DocumentRoot directive. The tradition is to use /var/www/ domain-name:

INSY571

By: Dr. Patrick D. Cerna

Page 76

Linux Lab Manual Networking

DocumentRoot /var/www/myexample.com Having completed the changes we now need a copy of the /etc/apache2/sitesavailable/myexample.com configuration file in /etc/apache2/sites-enabled. We do this by creating a symbolic link from the file in sites-available: cd /etc/apache2/sites-enabled ln -s /etc/apache2/sites-available/myexample.com . Next, create the /var/www/myexample.com directory and place an index.html file in it. For example: <html> <title>Sample Web Page</title> <body> Welcome to MyExample.com </body> </html> The last step is to restart the Apache web server to make sure it picks up our new settings: sudo /etc/init.d/apache2 restart Web Server and Firewall Issues If your Ubuntu Linux system is configured to use a firewall, you will need to ensure that HTTP traffic on port 80 is permitted in order for external system to be able to access your web server. Refer to the Basic Ubuntu Linux Firewall Configuration and Using Firestarter to Configure an Ubuntu Linux Firewall chapters of this book for details on configuring Ubuntu Linux Firewalls. If the Ubuntu system running your web server sits on a network protected by a firewall (either another computer running a firewall, or a router or wireless base station containing built in firewall protection) you will need to configure the firewall to forward port 80 to your web server system. The mechanism for performing this differs between firewalls and devices so check your documentation to find out how to configure port forwarding. Once everything is configured it should be possible to enter the domain name of your web site into a browser anywhere in the world and access your web server.

INSY571

By: Dr. Patrick D. Cerna

Page 77

Você também pode gostar