Conversational Linux
Conversational Linux
This license lets you remix, tweak, and build upon this work
even for commercial reasons, as long as you credit Joe Roper
and license your new creations under the identical terms. This
license is often compared to open source software licenses. All
new works based on yours will need to carry the same license,
so any derivatives will also allow commercial use.
2 Table of Contents...........................................................................................................................................3
3 Introduction....................................................................................................................................................7
5 Preparation...................................................................................................................................................10
5.1 Virtual Machine ....................................................................................................................................10
5.1.1 VMware........................................................................................................................................10
5.1.2 Microsoft Virtual PC....................................................................................................................11
5.2 Hardware ..............................................................................................................................................11
5.3 PuTTY....................................................................................................................................................12
5.4 WinSCP .................................................................................................................................................12
7 Webmin.........................................................................................................................................................14
9 Linux Filesystem..........................................................................................................................................20
9.1 Linux File System Explained ................................................................................................................21
15 Services .....................................................................................................................................................31
15.1 # chkconfig ............................................................................................................................................32
15.2 /etc/rc.d/rc.local ....................................................................................................................................32
15.3 Stopping services and processes. .........................................................................................................32
15.4 # ps aux..................................................................................................................................................33
15.5 # kill .......................................................................................................................................................33
15.6 # kill -9...................................................................................................................................................33
15.7 # top .......................................................................................................................................................33
17 Pipe............................................................................................................................................................34
17.1 # | ...........................................................................................................................................................34
17.2 Redirect Output.....................................................................................................................................34
17.3 # >..........................................................................................................................................................34
17.4 ## >>.....................................................................................................................................................34
18 Compression ............................................................................................................................................34
18.1 # tar........................................................................................................................................................35
18.2 # gzip......................................................................................................................................................35
18.3 # bzip......................................................................................................................................................35
18.4 # zip & unzip .........................................................................................................................................35
19 Networking...............................................................................................................................................36
19.1 # ifconfig................................................................................................................................................36
19.2 # system-config-network.......................................................................................................................36
19.3 # resolv.conf ..........................................................................................................................................36
19.4 # hostname.............................................................................................................................................37
19.5 # ifdown .................................................................................................................................................37
19.6 # ifup......................................................................................................................................................37
19.7 # ping .....................................................................................................................................................37
19.8 # traceroute ...........................................................................................................................................37
19.9 # mtr.......................................................................................................................................................37
21 Installing software...................................................................................................................................38
21.1 Compiling from source .........................................................................................................................38
21.1.1 # make clean.................................................................................................................................38
21.1.2 # ./configure..................................................................................................................................38
21.1.3 # make...........................................................................................................................................38
21.1.4 # make install................................................................................................................................38
21.2 # yum .....................................................................................................................................................38
21.3 # rpm......................................................................................................................................................39
22 Logs ...........................................................................................................................................................39
22.1 /var/log/messages..................................................................................................................................39
22.2 /var/log/dmesg.......................................................................................................................................39
22.3 /var/log/asterisk/full ..............................................................................................................................39
22.4 # logrotate .............................................................................................................................................40
23 Crontab.....................................................................................................................................................40
25 Network Services.....................................................................................................................................41
25.1 NTP........................................................................................................................................................41
25.2 DNS........................................................................................................................................................41
25.3 DHCP ....................................................................................................................................................42
25.4 TFTP......................................................................................................................................................42
25.4.1 Option 66......................................................................................................................................42
25.5 Sendmail / Postfix..................................................................................................................................42
25.6 Apache...................................................................................................................................................42
25.7 PHP .......................................................................................................................................................43
25.8 MySQL...................................................................................................................................................43
26 Hardware..................................................................................................................................................43
26.1 # lspci....................................................................................................................................................43
26.2 # cat /proc/interrupts ............................................................................................................................43
27 SSH Tunnelling........................................................................................................................................43
27.1 Example One.........................................................................................................................................44
27.2 Example Two.........................................................................................................................................44
28 Conclusion................................................................................................................................................45
4 Open Source
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
There is a GPL v3, but this has not been widely adopted as yet.
The idea with OSS software is that you can contribute to the
development of the product, and enjoy the fruits of your labour.
The code can be inspected by your peers, and commented
about publicly. This concentrates the mind to do it properly.
http://wiki.pentaho.org/display/BEEKEEPER/The+Beekeeper
Additionally, under the terms of the GPL, you must make your
modifications freely (as in make no charge) available to any and
all third parties, e.g. post a link to it on your website. (Section
2b of the GPL)
4.5 I’ve written a killer App for the product; do I need to give it
away?
You may write an application or modification to the product,
but do not want to release the code as it gives you a competitive
advantage. The answer to this is a little more grey, and to a
great degree, depends on your moral radar’
There are a number of ways that both the provider of the OSS
software and the reseller can make money from OSS.
3. Provide other Value Add Services, e.g. minutes and DID for
PBX services.
5 Preparation
5.1.1 VMware
You will need a VMware hard disk, and the .vmx configuration
file. The .vmx file controls the attributes of the virtual machine,
such as the memory, presence of network interfaces, the
CDRom etc. It is a text file can be edited with notepad or
wordpad. There is a blank hard disk and basic configuration file
available from: -
http://www.pbxinaflash.com/downloads/pbxinaflash.zip
http://petruska.stardock.net/software/VMware.html
http://www.microsoft.com/windows/products/winfamily/virtu
alpc/default.mspx
5.2 Hardware
Almost any hardware will do to run Linux on. Bear in mind that
most Linux installs will delete any data on the PC, so do not
install your main machine.
10Gb is more than sufficient for the hard drive. 256Mb of RAM
or more is recommended.
5.3 PuTTY
5.4 WinSCP
WinSCP is a program similar to Windows Explorer. It is a good
program for those more used to Windows than they are to the
command line.
It allows drag and drop copying to and from the desktop, as well
as changing permissions on files, editing files, and running non
interactive commands.
6 Installation of ISO
Ensure that all data that you want to keep has been backed up.
ide0:1.fileName = "c:\ippbx\concordiax.iso"
7 Webmin
CentOS is Redhat Linux with all the branding taken out. RHEL
is not usually available free of charge, and requires an annual
support fee, and as such, has lots of paid developers working
on the system. Not surprisingly, this allows it to spend more
money on the development and support of hardware, and has
been adopted as the defacto distribution for servers.
A side benefit is that if you were to ever release a PBX where the
customer wanted to have some guarantees about the stability, a
PBX could easily be built using RHEL and Asterisk Business
Edition.
8.9 SCP
Secure copy. Copy a file. Using the SCP protocol, copy files from
one Linux machine to another.
9 Linux Filesystem
The first thing that most new users shifting from Windows will
find confusing is navigating the Linux file system. The Linux file
system does things a lot more differently than the Windows file
system. This article explains the differences and takes you
through the layout of the Linux file system.
This kind of layout, known as the unified file system, does offer
several advantages over the approach that Windows uses. Let's
take the example of the /usr directory.
This directory off the root directory contains most of the system
executables. With the Linux file system, you can choose to
mount it off another partition or even off another machine over
the network. The underlying system will not know the difference
because /usr appears to be a local directory that is part of the
local directory structure! How many times have you wished to
move around executables and data under Windows, only to run
into registry and system errors? Try moving c:/windows/system
to another partition or drive. (No; Don't!!!)
9.2 Directories
We now move on to the layout or the directory structure of the
Linux file system. Given below is the result of a 'ls -p' in the root
directory.
bin/ dev/ home/ lost+found/ proc/ sbin/ usr/ boot/ etc/ lib/
mnt/ root/ tmp/ var/
9.2.1 /sbin
This directory contains all the binaries that are essential to the
working of the system. These include system administration as
well as maintenance and hardware configuration programs.
Find lilo, fdisk, init, ifconfig etc here. These are the essential
programs that are required by all the users. Another directory
that contains system binaries is /usr/sbin. This directory
contains other binaries of use to the system administrator. This
is where you will find the network daemons for your system
along with other binaries that only the system administrator
has access to, but which are not required for system
maintenance, repair etc.
9.2.2 /bin
9.2.3 /boot
This directory contains the system map file as well as the Linux
kernel. Lilo places the boot sector backups in this directory.
9.2.4 /dev
9.2.5 /etc
9.2.6 /home
9.2.7 /lib
9.2.8 /lost+found
9.2.9 /mnt
This is a generic mount point under which you mount your file
systems or devices. Mounting is the process by which you make
a file system available to the system. After mounting your files
will be accessible under the mount-point. This directory usually
contains mount points or sub-directories where you mount
your floppy and your CD. You can also create additional mount-
points here if you want. There is no limitation to creating a
mount-point anywhere on your system but convention says
that you do not litter your file system with mount-points.
9.2.10 /opt
9.2.11 /proc
9.2.12 /root
We talked about user home directories earlier and well this one
is the home directory of the user root. This is not to be confused
with the system root, which is directory at the highest level in
the file system.
9.2.13 /tmp
9.2.14 /usr
9.2.15 /var
This directory contains spooling data like mail and also the
output from the printer daemon. The system logs are also kept
here in /var/log/messages. You will also find the database for
BIND in /var/named and for NIS in /var/yp.
This was a short and basic look at the Linux file system. You do
need to have at least this basic knowledge of the layout of the
file system to fully utilize its potential. One good place to read
about the file system is this detailed document at
www.pathname.com/fhs/1.2/fsstnd-toc.html that specifies the
standard structure of the Linux file system.
11.1 # ls
Like dir in Dos, it lists the current directory. It lists the contents
of the current directory. With the –al switch, it displays the
permissions and ownership of the files as well.
11.2 # cd
Change Directory, type cd /path/to/directory cd / takes you to
the root of the filesystem, while cd ~ takes you to your home
directory. cd .. takes you up one directory level.
11.3 # pwd
Tells you where you are in the directory system.
11.4 # cp
copy, copies a file from one place to another, e.g cp file.txt ~
would copy the file.txt to your home directory. You can copy
recursively, e.g the directory and all subdirectories using the –r
switch
11.5 # mv
Moves a file from one location to another. This is also a popular
method of renaming a file. E.g. mv file.txt newfile.txt would
rename file.txt to newfile.txt
11.7 # find
Find a file on the file system. This is memory intensive, so if the
system is being used as a PBX, it may cause some voice quality
issues. The usual syntax is find –name filename. Wildcards can
be used such as * Note that the find command only looks in the
current directory and all sub directories. So to search the
complete file system, you need to either do cd / to get to the
root of the file system,, or find / -name name* to find all files
that begin with name.
11.8 # grep
Searches the contents of the files for the word stated – e.g. grep
-i tom would find all files with the word “tom” in them.
11.9 # rm
Remove a file, Note that there is no undelete command, or
recycle bin in Linux, so when a file is deleted, it is gone for ever.
A tip to ensure that there are no mistakes is to try the
command substituting ls for rm. E.g. to remove all files that end
in txt you may want to type rm *.txt but try the command ls
*.txt to ensure that it does what you think it is going to do. The
–r switch deletes all subdirectories and their files. The –f forces
the delete, and does not prompt, so if you have a large directory
and subdirectory to delete, then a valid command would be rm
–rf * which would delete everything in the current directory.
11.10 # touch
Create an empty file. E.g. touch newfile.txt will create a new file
called newfile.txt in the current directory.
11.12 # wget
Downloads a file from the internet using http. E.g. wget
www.mysite.com/filename.txt
12.1 # du
Shows the contents, directory and file sizes.
12.2 # df
Shows the current disk usage. Note that if a hard drive becomes
full. Linux will cease to work, and may become inaccessible to
SSH. Where you are running an FTP site, it may be a good idea
to put the FTP site on it’s own partition so that it’s becoming
full does not cause problem with the operating system.
In most files, the “#” denotes that the following characters are
simply comments. However, in Asterisk Dial plans, # means
include the named file. Comments are denoted by a semi-colon
“;”
13.2 WinSCP
WinSCP can be used for editing files in a familiar Windows
interface, simply right click on the file to edit, and click edit.
Save when done.
13.3 # cat
Cat lists the entire contents of a file in one go.
13.4 # less
Lists the contents of a file one page at a time. Press q to exit.
E.g. less myfile.txt
13.5 # tail
Lists the last 10 lines of a file. There are switches to change this
value. Tail –f logfilename shows the log in realtime.
13.6 # head
Lists and displays the top 10 lines of a file.
14.2 Chmod
(Parts reproduced from http://www.freeos.com/articles/3127/ By Mayank Sarup)
- r=4
- w=2
- x=1
Now you can use numbers, which are the sum of the various
permission bits.
E.g - rwx will be 4+3+1 = 7. rx becomes 4+1 = 5. The chmod
command now
becomes chmod xyz filename where x,y and z are numbers
representing the permissions of user, group and others
respectively. Each number is the sum of the permissions to be
set and are calculated as given above.
- 6 = 4 + 2 = rw
- 4=r
- 4=r
- 0 - ---
- 1 - --x
- 2 - -w-
- 3 - -wx
- 4 - r—
- 5 - r-x
- 6 - rw-
- 7 – rwx
Tip: The easiest way to set the permissions is to right click on the file or
directory in WinSCP, select properties. You can then tick the permission
you want to allow.
14.3 Chown
In addition to the file permission, you can also modify the
owner and group of the file. The chown program is used here
and its syntax is very simple. You need to be the owner of a file
or root to do this.
14.4 chgrp
To change group, user the chgrp command. Syntax is similar to
chown. You
will need to be the owner of the file and also belong to the same
group as
the file, or you should be root.
15 Services
15.1 # chkconfig
To start services automatically at boot time, the chkconfig
command is used.
- 0 - Halt
- 1 - Single user
- 2 - Not used/User definable
- 3 - Full multi-user, console logins only
- 4 - Not used/User definable
- 5 - Full multi-user, with display manager as well as
console logins
- 6 - Reboot
to turn it off:-
# chkconfig –list
15.2 /etc/rc.d/rc.local
This file is like the windows startup folder. Processes and
scripts can be launched from here at the end of the boot
process.
15.4 # ps aux
Shows a list of running processes, with the PID and some other
metrics
15.5 # kill
Kills the process. Kill 235 where 235 is the PID to kill
15.6 # kill -9
Force kills the process kill -9 235 force kills the PID
15.7 # top
Shows the running processeswith the most processor intensive
at the top. This displays in real-time.
16.1 # reboot
Reboots the Server
17.1 # |
The pipe command allows the output of one command to be
piped into the input of another command.
e.g. ls –al > list.txt willl send the output of ls –al to a the text
file; list.txt
17.3 # >
Appends to the end of an existing file.
17.4 ## >>
Clears the file first.
18 Compression
Creating a Tarball is a two stage process. First all the files are
put into a TAR file, and then they are compressed using a
compression utility such as Gzip or Bzip.
18.1 # tar
Strictly speaking, TAR, derived from the words Tape ARchive is
not really used for compression. It simply rolls a number of files
into one big file (Tarball)
Tip: For untarring a file, do it from the command line – tar zxfv
filename.tar.gz. To tar and compress a file, it is easiest, and less
prone to error if you do it from within WinSCP. Select the
directories to be compressed, rightclick and select Tar.
18.2 # gzip
As above
18.3 # bzip
bzip –czvf filename.tar filename but using the bzip compression
algorithm
- The IP address
- Netmask
- Gateway
- DNS server
19.1 # ifconfig
Shows the current IP addresses of every interface, note that a
physical interface can have more than one IP address.
19.2 # system-config-network
A text based GUI to set the IP address of any interface. This
utility writes to:-
/etc/sysconfig/network-scripts/ifcfg-eth0 in the case of
network interface known as eth0. It can be manually edited if
necessary. With a fixed IP address the file should look like this:-
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.3.200
NETMASK=255.255.255.0
GATEWAY=192.168.3.254
19.3 # resolv.conf
The file containing the details of how to resolve an domain
name to an IP address.
To add a nameserver, type nano –w /etc/resolv.conf and add
the line: -
Nameserver 1.2.3.4
Where 1.2.3.4 is the DNS server. Often, but not always, the
gateway/router doubles up as the DNS Server
19.4 # hostname
Sets the name of the server.
19.5 # ifdown
Stop the interface, e.g. ifdown eth0
19.6 # ifup
Bring the interface back up again.
19.7 # ping
Send a packet to a host and measure the time it takes to make
the round trip. E.g. ping www.google.com
19.8 # traceroute
Trace the route to a host. E.g. traceroute www.google.com
19.9 # mtr
mtr is a very useful command combining ping and traceroute in
the same command. It shows the live status of the path to a
host. E.G. mtr www.google.com
20 Network Security
20.1.1 Iptables
21.1.2 # ./configure
21.1.3 # make
21.2 # yum
Use the CentOS repository, and other repositories to install and
update software. E.g.
21.3 # rpm
Many programs, e.g. webmin come as an rpm, or a pre-
compiled binary, so that the program does not have to be
compiled on the machine.
22 Logs
There are a large number of logs on the system, which can give
good information on any problems, who has accessed the
machine, and what they have done with them. To view them,
you can use less, tail, cat, and other similar commands as
listed above. A few of the more important logs are below.
22.1 /var/log/messages
Contains general system logging
22.2 /var/log/dmesg
Contains hardware loading information
22.3 /var/log/asterisk/full
Contains the Asterisk log file
This is usually done for you. But if not, read the man logrotate.
23 Crontab
24.1 Users
Users are people, and processes that have access to things on
the system
24.2 Groups
A group is a collection of users to make administration easier.
24.3 # sudo
It is not necessarily desirable to have root as the main access to
system. If hackers get access to the system, they can go
everywhere. Additionally, it is possible to make a mistake on the
system. By being a non root user, some of these mistakes can
be mitigated.
# adduser myusername
# passwd myusername <password>
25 Network Services
25.1 NTP
A time server. Linux can get its time from the internet, and act
as a time server for devices on your network. For this to
happen, ntpd must be running (service ntpd status) and port
123 udp must be open on the firewall
25.2 DNS
Domain Name resolution. Linux can be a domain name server.
The easiest way to set this up is in webmin. Click on servers,
then Bind.DNS Server, and set it up with the default values
offered by Webmin.
25.4 TFTP
A TFTP server is what a phone and other devices use to get
their configuration. Run these commands to get it running: -
To check it is running: -
netstat -nulp|grep 69
You should see a result that includes a line that looks similar to
the following:
25.4.1 Option 66
25.6 Apache
The web server, that delivers web pages. The Daemon is called
httpd. To restart apache, type httpd –k restart
25.8 MySQL
MySQL is one of the most popular database systems. It can
handle many millions of records. If you have Apache and PHP
installed, the database can be viewed via phpMyAdmin. See
www.phpmyadmin.net. Do however note the licensing of
MySQL. It is undergoing change due to a commercial buyout.
26 Hardware
26.1 # lspci
Show the interrupts on the system, add –v for more information
27 SSH Tunnelling
• Source port = 80
• Destination = 192.168.3.202:80
Click Add, and continue in this manner. When you have added
all your phones, click Apply.
28 Conclusion
Now you have read this document, you should have enough
information and tools to be able to do basic Linux installs,
configuration and maintenance, as well as search for further
information should you need to.