- Basic System Configuration Tools
- Network Configuration File
- Network Interface Configuration
- Global Network Setting
- DNS Configuration
- 2. Printing in Linux
- Supported printer connections
- Queues
- Jobs
- system-config-printer
- Printing Commands
- Printing Utilities
- Managing Printers With CUPS
- 3. System’s Date and Time
- GUI Method
- CLI Method
- 4. Shell Scripting
- read command
Basic System Configuration Tools
NOTE!: By Default, ifconfig command print the information about all active interfaces.
If the interface name is passed as an argument, ifconfig command print the information about that interface only.
[mitesh@Matrix ~]$ ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:09:6B:CD:2B:87 inet addr:192.168.0.254 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr:fe80::209:6bff:fecd:2b87/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:851525 errors:0 dropped:0 overruns:0 frame:0 TX packets:1132322 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:211140434 (201.3 MiB) TX bytes:1113058956 (1.0 GiB)
Enable/Disable Network Interface
ifup ethX; ifconfig ethX up ifdown ethX; ifconfig ethX down
Graphical Network Configuration:
System -> Preferences -> Network Connections
- Add, Edit, Delete Network Interface
- Assign IP Addresses/DHCP
- Modify Gateway Address
- Modify DNS Setting
NOTE!: The system-config-network also provides all the features listed above.
Network Configuration File
Ethernet Devices
- Whether or not you use system-config-network to configure your network interfaces, All the Network Interface settings are stored in /etc/sysconfig/network-scripts/ directory.
- The Network Interface Configuration is stored in a Text Files /etc/sysconfig/network-scripts/ifcfg-ethX
NOTE!: These files are read by system-config-network , ifup , ifdown and other tools that bring the Network Interface up and down.
/-------------------------------------------------------------------------------\ | Dynamic Configuration | Static Configuration | |-------------------------------------------------------------------------------- | | | DEVICE=ethX | DEVICE=ethX | | HWADDR=00:09:6B:CD:2B:87 | HWADDR=00:09:6B:CD:2B:87 | | BOOTPROTO=dhcp | IPADDR=192.168.0.123 | | ONBOOT=yes | NETMASK=255.255.255.0 | | TYPE=Ethernet | GATEWAY=192.168.0.254 | | | ONBOOT=yes | | | TYPE=Ethernet | \-------------------------------------------------------------------------------/
NOTE!: The Network Interface file is just a collection of bash variables that define the interface’s setting. Remember the syntax of bash variable is VARIABLE=VALUE , with no spaces on either side of the =.
Network Interface Configuration
/-----------------------------------------------------------------------------------------------------------------------\ | Setting | Meaning | |------------------------------------------------------------------------------------------------------------------------ | | | DEVICE | Specify the Network Interface Name or Alias (Example eth0) | | | | HWADDR | Hardwaare(MAC) Address. | | | This setting is optional & can cause problems, | | | when ethernet card is replaced | | | | BOOTPROTO | Where IP Settings should be retrieved from. | | | Set to dhcp to use DHCP. | | | Leave the variable unset or set it to static for manual IP Settings. | | | | IPADDR & | Basic IP Settings. | | NETMASK | Only necessary when not using the DHCP Server. | | | | GATEWAY | Only necessary when not using the DHCP Server. | | | The Gateway can also be set in /etc/sysconfig/network file. | | | If the Gateway is defined in the /etc/sysconfig/network and ifcfg file, | | | The Gateway defined in the most recently activated ifcfg file is used. | | | | ONBOOT | Whether to bring the network interface up automatically when the system boots. | | | Set to yes or no. The default value is no. | | | | USERCTL | Whether to allow non-root users to bring this interface up & down. | | | Set to yes or no. The default value is no. | | | | TYPE | Specify the type of network interface. | | | \-----------------------------------------------------------------------------------------------------------------------/
Global Network Setting
- Some Network Settings are defined globally, rather than on a per-interface basis.
- The Global Network Settings are defined in the /etc/sysconfig/network
- Many may be provided by DHCP Server.
- GATEWAY can be overridden in ifcfg file.
[mitesh@Matrix ~]$ cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=server1.example.com GATEWAY=192.168.2.254
NOTE!: If the Gateway is defined in the /etc/sysconfig/network and ifcfg file, The Gateway defined in the most recently activated ifcfg file is used.
DNS Configuration
- Domain Name Service Translate Hostname to IP Address.
- The DNS Server address is specified by DHCP or in /etc/resolv.conf
[mitesh@Matrix ~]$ cat /etc/resolv.conf search example.com cracker.org nameserver 192.168.0.254 nameserver 192.168.1.254
Explain DNS
- When we type www.google.com into web browser, it initiates a DNS Lookup, in which it ask Local DNS Server what IP Address is assigned to that name.
- If Local DNS Server does not know, it will try to find out which other DNS Server on the internet know about the google.com and will forward my request to one of them.
Local DNS Server
- Local DNS Configuration is performed using the /etc/resolv.conf
- Remember two things while creating or modifying /etc/resolv.conf file
- The search specifies the Domain Name when incomplete DNS Name is give to the command.
- If /etc/resolv.conf file contains the line: search example.com cracker.org
- Now when we try to run following command ping server1
- In this case system automatically convert server1 into server1.example.com
- If the server1.example.com is not found then system try server1.cracker.org
- The nameserver is most important, as it specify the IP Address of the DNS Server that your system should use.
- Multiple nameserver are added but remember that nameserver are tried in order, So be sure to put the fastest and available namesserver at first place.
2. Printing in Linux
- Printing on Linux system is handled by the Common Unix Printing System (CUPS).
- Printers May Be
- Local (serial, parallel or usb)
- Networked
Supported printer connections
- Local (serial, parallel or usb)
- Unix/Linux print server
- Netware print server
- Windows print server
- HP JetDirect
- IPP — Internet Printing Protocol
Queues
- Print request are sent to the queues.
- Different queues for the same printer may have different priority or output options.
- Queued jobs are sent to the printer on a First Come First Served basis.
Jobs
- Once a file has been sent to a queue for printing, it is called a job.
- Jobs may be canceled before or during printing.
system-config-printer
- A Graphical Configuration Tool is used to adding new printers to your systems.
- To run this tools Select System -> Administration -> Printing OR Run the system-config-printer on the terminal
Printing Commands
lpr command
- lpr Send job to the printer
- Accepts ASCII, PDF, PostScript and other Formats
- Most applications under Linux output PostScript Formats
[mitesh@Matrix ~]$ lpr reports.txt # Print 5 copies of the file reports.txt on the accounting printer [mitesh@Matrix ~]$ lpr -P accounting -#5 reports.txt
lpq command
[mitesh@Matrix ~]$ lpq Printer: ps@localhost Queue: no printable jobs in queue Server: no server active Status: job 'jay@localhost+916' removed at 12:16:03.083 Rank Owner/ID Class Job Files Size Time done jay@localhost+185 A 185 results 2067 08:38:04
lprm command
[mitesh@Matrix ~]$ lprm 916 Printer ps@localhost:
NOTE!: A user may only remove his own jobs from the queue.
lpstat command
Printing Utilities
- evince : Views PDF Documents
- ps2pdf : Converts PostScript to PDF
- pdf2ps : Converts PDF to PostScript. Which makes it easy to print PDF Documents right from the command line.
- pdftotext : Converts PDF to Plain Text
- enscript , a2ps : Converts Text to PostScript
- mpage : Prints multiple pages per sheet
Managing Printers With CUPS
- Daemons: cups
- Services: chkconfig cups on | off & service cups status | start | stop | restart
Configuration Files
Configuration Tools
- CLI: lpr lpq lprm lpstat lpadmin lpinfo
- GUI: system-config-printer System -> Administration -> Printing
- Web Based: http://localhost:631
3. System’s Date and Time
GUI Method
- system-config-date System -> Administration -> Date & Time
- Can set Date/Time Manually or use NTP
- Additional NTP Servers can be added
- Can use Local Time or UTC
CLI Method
[root@Matrix ~]# date 01011010 # 1st Jan, at 10:10am. [root@Matrix ~]# date 01010101.01 # 1st Jan, at 01:01:01 am. [root@Matrix ~]# date 12312359 # 31st Dec, at 11:59pm. [root@Matrix ~]# date 123123592007 # 31st Dec 2007, at 11:59pm. [root@Matrix ~]# date 123123592007.05 # 31st Dec 2007, at 11:59:05pm.
4. Shell Scripting
- Taking Input With Positional Parameters:
- Many commands and scripts can perform different tasks depending on the arguments supplied to the program.
- Positional Parameters are special variables that hold the command-line arguments to the script.
- The available Positional Parameters are: $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $, $…
NOTE!: $0 Specify the program name
$* Holds all command-line arguments
$# Holds the number of command-line arguments#!/bin/bash # positionaltester # Demonstrates the use of positional parameters echo "The program name is $0" printf "The first argument is %s and the second is %s\n" $1 $2 echo -e "All command line parameters are $*\n" echo -e "Total number of command line parameters are $#\n"
[mitesh@Matrix ~]$ ./positionaltester Red Hat Enterprise Linux The program name is ./positionaltester The first argument is Red and the second is Hat All command line parameters are Red Hat Enterprise Linux Total number of command line parameters are 4
read command
- Taking Input With Read Command
- The read commands takes a line from the STDIN and breaks it down into individual words. (Usaually a word is defined as a character string surrounded by white space such as spaces and tabs).
- The way the shell interprets words may be changed by setting the IFS variable.
NOTE! IFS=’:’ will tells the shell that words are separated by colons instead of white space).
- The 1st word is assigned to the 1st variable The 2nd word is assigned to the 2nd variable and so on.
- If there are more words than variables, All the remaining words are assigned to the last variable.
#!/bin/bash echo -n "Enter name ( first last ): " read FIRST LAST echo "Your first name is $FIRST and your last name is $LAST" #!/bin/bash read -p "Enter name ( first last ): " FIRST LAST echo "Your first name is $FIRST and your last name is $LAST" #!/bin/bash read -p "Enter several values: " value1 value2 value3 echo "value1 is $value1" echo "value2 is $value2" echo "value3 is $value3"