Wednesday, July 27, 2011

Linux Creating or Adding New Network Alias To a Network Card (NIC)

Linux Creating or Adding New Network Alias To a Network Card (NIC)

Q. I would like to create alias for my network card (NIC).
How do I setup 2 IP address on One NIC?
How do I add alias under Centos / Fedora / Debian / Ubuntu Linux?

A. Linux allows you to add additional network address using alias feature.
Please note that all additional network IP address must be in same subnet.
For example if your eth0 using 192.168.1.5 IP address then alias must be setup using 192.168.1.0/24 subnet.

fconfig command line

You can use ifconfig command to configure a network interface and alias. For example:
  • eth0 NIC IP 192.168.1.5
  • eth0:0 first NIC alias: 192.168.1.6
To setup eth0:0 alias type the following command as the root user:
# ifconfig eth0:0 192.168.1.6 up

Verify alias is up and running using following command:
# ifconfig -a
# ping 192.168.1.6

However, if you reboot the system you will lost all your alias. To make it permanent you need to add it network configuration file.

Debian / Ubuntu Linux Instructions

You can configure the additional IP addresses automatically at boot with another iface statement in /etc/network/interfaces:
# vi /etc/network/interfaces

Append text as follows:
auto eth0:1
iface eth0:1 inet static
name Ethernet alias LAN card
address 192.168.1.7
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0
 
Save and close the file. Restart the network:
# /etc/init.d/networking restart


Red Hat / RHEL / CentOS / Fedora Linux Instructions

Copy etc/sysconfig/network-scripts/ifcfg-eth0 file as /etc/sysconfig/network-scripts/ifcfg-eth0:0
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0

Open file /etc/sysconfig/network-scripts/ifcfg-eth0:0 using vi text editor:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0:0

Find entry that read as follows:
DEVICE=eth0 

Replace with:
DEVICE=eth0:0

Find entry that read as follows:
IPADDR=xxx.xxx.xxx.xxx
 
Replace it with your actual IP address:
IPADDR=192.168.1.7
 
At the end your file should like as follows:
DEVICE=eth0:0
IPADDR=192.168.1.7
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
NAME=eth0:0
 
Open file /etc/sysconfig/network-scripts/ifcfg-eth0 and make sure file does not have a GATEWAY= entry:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Find the entry that read as follows:
GATEWAY=your-ip
 
Remove or comment it out by prefixing # (hash) :
# GATEWAY=192.168.1.254
 
Save the file. Add the GATEWAY= to your /etc/sysconfig/network:
# vi /etc/sysconfig/network
 
Append or modify GATEWAY entry:
GATEWAY=192.168.1.254
 
Save the file. Reboot the system or run the following command:
# ifup eth0:0
OR
# service network restart

Red Hat / CentOS / Fedora Multiple IP address range

You can assign multiple ip address range as follows to eth0:
vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0

Append following code from 202.54.112.120 to 202.54.112.140:
IPADDR_START=202.54.112.120
IPADDR_END=202.54.112.140
CLONENUM_START=0
NETMASK=255.255.255.0 
Save and close the file.

 ====================================

Network IP aliasing:
Assign more than one IP address to one ethernet card:
ifconfig eth0   XXX.XXX.XXX.XXX netmask 255.255.255.0 broadcast XXX.XXX.XXX.255
ifconfig eth0:0 192.168.10.12   netmask 255.255.255.0 broadcast 192.168.10.255
ifconfig eth0:1 192.168.10.14   netmask 255.255.255.0 broadcast 192.168.10.255
 
route add -host XXX.XXX.XXX.XXX dev eth0
route add -host 192.168.10.12 dev eth0
route add -host 192.168.10.14 dev eth0
In this example 0 and 1 are aliases in addition to the regular eth0. The result of the ifconfig command:
eth0      Link encap:Ethernet  HWaddr 00:10:4C:25:7A:3F  
          inet addr:XXX.XXX.XXX.XXX  Bcast:XXX.XXX.XXX.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:14218 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1362 errors:0 dropped:0 overruns:0 carrier:0
          collisions:1 txqueuelen:100 
          Interrupt:5 Base address:0xe400 

eth0:0    Link encap:Ethernet  HWaddr 00:10:4C:25:7A:3F  
          inet addr:192.168.10.12  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:5 Base address:0xe400 

eth0:1    Link encap:Ethernet  HWaddr 00:10:4C:25:7A:3F  
          inet addr:192.168.10.14  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:5 Base address:0xe400 
Config file: /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=static
BROADCAST=192.168.10.255
IPADDR=192.168.10.12
NETMASK=255.255.255.0
NETWORK=192.168.10.0
ONBOOT=yes
Aliases can also be shut down independently. i.e.: ifdown eth0:0 The option during kernel compile is: CONFIG_IP_ALIAS=y (Enabled by default in Redhat)       

Linux bond or team multiple network interfaces (NIC) into single interface

Linux bond or team multiple network interfaces (NIC) into single interface


Finally today I had implemented NIC bounding (bind both NIC so that it works as a single device). We have two Dell servers that need setup with Intel Dual Gig NIC. My idea is to improve performance by pumping out more data from both NIC without using any other method.

This box act as heavy duty ftp server. Each night I need to transfer over 200GB data from this box to another box. Therefore, the network would be setup is two servers on a switch using dual network cards.
I am using Red Hat enterprise Linux

Linux allows binding multiple network interfaces into a single channel/NIC using special kernel module called bonding. According to official bonding documentation, "The Linux bonding driver provides a method for aggregating multiple network interfaces into a single logical "bonded" interface. The behavior of the bonded interfaces depends upon the mode; generally speaking, modes provide either hot standby or load balancing services.
Additionally, link integrity monitoring may be performed."Setting up bounding is easy with RHEL

Step #1: Create a bond0 configuration file

Red Hat Linux stores network configuration in /etc/sysconfig/network-scripts/ directory.
First, you need to create bond0 config file:

# vi /etc/sysconfig/network-scripts/ifcfg-bond0

Append following lines to it:
DEVICE=bond0
IPADDR=192.168.1.20
NETWORK=192.168.1.0
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes

Replace above IP address with your actual IP address. Save file and exit to shell prompt.


Step #2: Modify eth0 and eth1 config files:

Open both configuration using vi text editor and make sure file read as follows for eth0 interface
# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Modify/append directive as follows:
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none


Open eth1 configuration file using vi text editor:#
 vi /etc/sysconfig/network-scripts/ifcfg-eth1

Make sure file read as follows for eth1 interface:
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

Save file and exit to shell prompt.


Step # 3: Load bond driver/module

Make sure bonding module is loaded when the channel-bonding interface (bond0) is brought up. You need to modify kernel modules configuration file:
# vi /etc/modprobe.conf

Append following two lines:
alias bond0 bonding
options bond0 mode=balance-alb miimon=100


Save file and exit to shell prompt. You can learn more about all bounding options in kernel source documentation file (click here to read file online).


Step # 4: Test configuration

First, load the bonding module:
# modprobe bonding

Restart networking service in order to bring up bond0 interface:
# service network restart

Verify everything is working:
# less /proc/net/bonding/bond0

Output:
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c6:be:59

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c6:be:63
 
List all interfaces:
# ifconfig

Output:

bond0     Link encap:Ethernet  HWaddr 00:0C:29:C6:BE:59
 inet addr:192.168.1.20  Bcast:192.168.1.255  Mask:255.255.255.0
 inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
 UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
 RX packets:2804 errors:0 dropped:0 overruns:0 frame:0
 TX packets:1879 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:0
 RX bytes:250825 (244.9 KiB)  TX bytes:244683 (238.9 KiB)

eth0      Link encap:Ethernet  HWaddr 00:0C:29:C6:BE:59
 inet addr:192.168.1.20  Bcast:192.168.1.255  Mask:255.255.255.0
 inet6 addr: fe80::20c:29ff:fec6:be59/64 Scope:Link
 UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
 RX packets:2809 errors:0 dropped:0 overruns:0 frame:0
 TX packets:1390 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:1000
 RX bytes:251161 (245.2 KiB)  TX bytes:180289 (176.0 KiB)
 Interrupt:11 Base address:0x1400

eth1      Link encap:Ethernet  HWaddr 00:0C:29:C6:BE:59
 inet addr:192.168.1.20  Bcast:192.168.1.255  Mask:255.255.255.0
 inet6 addr: fe80::20c:29ff:fec6:be59/64 Scope:Link
 UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
 RX packets:4 errors:0 dropped:0 overruns:0 frame:0
 TX packets:502 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:1000
 RX bytes:258 (258.0 b)  TX bytes:66516 (64.9 KiB)
 Interrupt:10 Base address:0x1480

Monday, July 25, 2011

Howto Red hat enterprise Linux 5 configure the network card

Howto Red hat enterprise Linux 5 configure the network card


Q. I’ve installed Red Hat enterprise Linux 5 and now added one more LAN card (NIC).
How do I configure the network card from the command line? I can see 2nd my network card detected while booting the IBM server.

A. Red hat Linux provides following tools to make changes to Network configuration such as add new card, assign IP address, change DNS server etc.

[a] GUI tool (X Windows required) - system-config-network
[b] Command line text based GUI tool (No X Windows required) - system-config-network
[c] Edit configuration files stored in /etc/sysconfig/network-scripts/ directory.

Following instructions are compatible with
(1) Cent OS Linux
(2) Fedora Core Linux
(3) Red Hat Enterprise Linux (RHEL) 3/4/5

Method # 1: GUI tool system-config-network

Type the following command at shell prompt (open x terminal):
$ system-config-network &
Red hat enterprise Linux 5 configure the network card - system-config-network

You will see Window as above. Now select your Ethernet card (eth0 or eth1) and click on Edit button. You can now setup IP address, netmask, default gateway and other properties.
setup IP address, netmask, default gateway and other properties

You can obtain IP address using DHCP or setup manually. Once IP address assigned, click on Ok button to save the changes. You can activate card by clicking on Activate button.

Method # 2: Command line tool system-config-network-tui

If you don’t have X windows GUI installed type the following command at shell prompt:
# system-config-network-tui &
Command line tool system-config-network-tui

(click to enlarge image)
You will see text based GUI as above. Select your Ethernet card (eth0 or eth1) and hit [Enter] or [F12] special key.
Cent OS, Fedora Core, RHEL configure the network card - system-config-network-tui
(click to enlarge image)
You can obtain IP address using DHCP or setup manually. Once IP address assigned, click on Ok button to save the changes


Method #3: Edit configuration files stored in /etc/sysconfig/network-scripts/

You can configure network card by editing text files stored in /etc/sysconfig/network-scripts/ directory.
First change directory to /etc/sysconfig/network-scripts/:
# cd /etc/sysconfig/network-scripts/
You need to edit / create files as follows:
  • /etc/sysconfig/network-scripts/ifcfg-eth0 : First Ethernet card configuration file
  • /etc/sysconfig/network-scripts/ifcfg-eth1 : Second Ethernet card configuration file
To edit/create first NIC file, type command:
# vi ifcfg-eth0
Append/modify as follows:

# Intel Corporation 82573E Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:30:48:56:A6:2E
IPADDR=10.10.29.66
NETMASK=255.255.255.192
ONBOOT=yes


 
Save and close the file. Define default gateway (router IP) and hostname in /etc/sysconfig//network file:
# vi /etc/sysconfig/network

Append/modify configuration as follows:
NETWORKING=yes
HOSTNAME=www1.nixcraft.in
GATEWAY=10.10.29.65

Save and close the file. Restart networking:
# /etc/init.d/network restart

Make sure you have correct DNS server defined in /etc/resolv.conf file:
# vi /etc/resolv.conf

Setup DNS Server as follows:
nameserver 10.0.80.11
nameserver 10.0.80.12
nameserver 202.67.222.222


Save and close the file. Now you can ping the gateway/other hosts:
$ ping 10.0.80.12

Output:
PING 10.0.80.12 (10.0.80.12) 56(84) bytes of data.
64 bytes from 10.0.80.12: icmp_seq=1 ttl=251 time=0.972 ms
64 bytes from 10.0.80.12: icmp_seq=2 ttl=251 time=1.11 ms
 
You can also check for Internet connectivity with nslookup or host command:
$ nslookup cyberciti.biz

Output:
Server:         10.0.80.11
Address:        10.0.80.11#53

Non-authoritative answer:
Name:   cyberciti.biz
Address: 75.126.43.232
You can also use host command:
$ host nixcraft.in

Output:
nixcraft.in has address 75.126.43.232
nixcraft.in mail is handled by 10 mail.nixcraft.in.

Wednesday, July 13, 2011

Step-By-Step Configuration of NAT with iptables

Requirements:

CPU - PII or more
OS - Any Linux distribution
Software - Iptables
Network Interface Cards: 2
Here is my considerations:
Replace xx.xx.xx.xx with your WAN IP
Replace yy.yy.yy.yy with your LAN IP
(i.e. 192.168.0.0/16, 172.16.0.0/12,  10.0.0.0/8 as suggested by Mr. tzs)
WAN = eth0 with public IP xx.xx.xx.xx
LAN = eth1 with private IP yy.yy.yy.yy/ 255.255.0.0

 

Step by Step Procedure

Step #1. Add 2 Network cards to the Linux box
Step #2. Verify the Network cards, Wether they installed properly or not
ls /etc/sysconfig/network-scripts/ifcfg-eth* | wc -l
    ( The output should be "2")
Step #3. Configure eth0 for Internet with a Public ( IP External network or Internet)
cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
BROADCAST=xx.xx.xx.255    # Optional Entry
HWADDR=00:50:BA:88:72:D4    # Optional Entry
IPADDR=xx.xx.xx.xx
NETMASK=255.255.255.0    # Provided by the ISP
NETWORK=xx.xx.xx.0       # Optional
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
GATEWAY=xx.xx.xx.1    # Provided by the ISP

Step #4. Configure eth1 for LAN with a Private IP (Internal private network)
cat /etc/sysconfig/network-scripts/ifcfg-eth1
BOOTPROTO=none
PEERDNS=yes
HWADDR=00:50:8B:CF:9C:05    # Optional
TYPE=Ethernet
IPV6INIT=no
DEVICE=eth1
NETMASK=255.255.0.0        # Specify based on your requirement
BROADCAST=""
IPADDR=192.168.2.1        # Gateway of the LAN
NETWORK=192.168.0.0        # Optional
USERCTL=no
ONBOOT=yes

Step #5. Host Configuration    (Optional)
cat /etc/hosts
    127.0.0.1       nat localhost.localdomain   localhost
Step #6. Gateway Configuration
cat /etc/sysconfig/network
    NETWORKING=yes
    HOSTNAME=nat
    GATEWAY=xx.xx.xx.1    # Internet Gateway, provided by the ISP

Step #7. DNS Configuration
cat /etc/resolv.conf
    nameserver 203.145.184.13      # Primary DNS Server provided by the ISP
    nameserver 202.56.250.5        # Secondary DNS Server provided by the ISP

Step #8. NAT configuration with IP Tables
    # Delete and flush. Default table is "filter". Others like "nat" must be explicitly stated.
iptables --flush            # Flush all the rules in filter and nat tables
iptables --table nat --flush
iptables --delete-chain
# Delete all chains that are not in default filter and nat table
iptables --table nat --delete-chain
# Set up IP FORWARDing and Masquerading
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface eth1 -j ACCEPT
# Enables packet forwarding by kernel
echo 1 > /proc/sys/net/ipv4/ip_forward
 #Apply the configuration
service iptables restart
Step #9. Testing
 # Ping the Gateway of the network from client system
ping 192.168.2.1
Try it on your client systems
ping google.com

 Configuring PCs on the network (Clients)

•    All PC's on the private office network should set their "gateway" to be the local private network IP address of the Linux gateway computer.
•    The DNS should be set to that of the ISP on the internet.
Windows '95, 2000, XP,  Configuration:

•    Select "Start" + Settings" + "Control Panel"
•    Select the "Network" icon
•    Select the tab "Configuration" and double click the component "TCP/IP" for the ethernet card. (NOT the TCP/IP -> Dial-Up Adapter)
•    Select the tabs:
o    "Gateway": Use the internal network IP address of the Linux box. (192.168.2.1)
o    "DNS Configuration": Use the IP addresses of the ISP Domain Name Servers. (Actual internet IP address)
o    "IP Address": The IP address (192.168.XXX.XXX - static) and netmask (typically 255.255.0.0 for a small local office network) of the PC can also be set here.

Thursday, July 7, 2011

Adding Microsoft Office Document Image Writer Printer back after being removed.

Solution 1.
Type the following into a command prompt window: (unsure if you have to be admin or not)
cscript c:\windows\system32\prnmngr.vbs -a -p "Microsoft Office Document Image Writer" -m "Microsoft Office Document Image Writer Driver" -r "Microsoft Document Imaging Writer Port:"

Solution 2. (Not mine, borrowed from somewhere else.)
1. Close all running applications. If you have any Office application
running, the driver will not be installed properly.
2. Go to the "Control Panel" and "Add or Remove Programs".
3. Click on"Microsoft Office 2003" and then click on "Change".
4. Check "Add or Remove Features" and click "Next".
5. On the bottom of the page check "Choose advanced customization of
applications." and click "Next".
6. Under Microsoft Office click on the + sign in front of "Office
Tools"
7. Locate "Microsoft Office Document Imaging", click the icon and
select "Not Available".
8. Click on "Update". This will uninstall the MODI driver.

9. Repeat steps 1 to 6 to go back to the same location you were before.

10. Locate the object "Microsoft Office Document Imaging", click the
icon and select "Run from My Computer".
11. Click on "Update".

Use the Remote Shutdown Tool to Shutdown, Restart, or Logoff a Local or Networked Computer on Windows OS

This guide shows you how to use the shutdown command and its various switches to shutdown, restart, or logoff local or networked computers from the command prompt, dialog window, or batch file.

What can the shutdown command do?
The shutdown command can be use via the command prompt, the remote shutdown dialog window, or in a batch file.  You can logoff, shutdown, or restart a computer with this tool.  You can even set the shutdown tool to perform a task at a certain time on certain days and to many computers at one time using a batch file.
This is a good tool to easily shutdown or restart lots of computers on a network at one time.  It can also be handy for helpdesk technicians when fixing remote computers.

Shutdown Command via Dialog Window
Typing commands in a DOS window is not what most computer users want to fool with so I’m going to start by showing you how to use the dialog window to use the shutdown tool.
To open the dialog window click start, click run, type cmd and press enter.  A black DOS looking window will open.  Type shutdown -i and press enter.  A window similar to the one below will popup.




Under computers type the network name of the computer you want to shutdown, restart, or logoff.  In this example I will use \\yourcomputer.  You can use your computer’s name to try the commands on your computer if you like.

If you don’t know a computers name right click my computer, select properties, select the computer name tab.  Your computer name is listed next to full computer name.
To send these commands to other computers across your network you need to have administrative privileges on those computers.  An easy way to see if you have administrative privileges on a networked computer is to try browsing to it.  Click start, click run, type \\yourcomputer (replace yourcomputer with your computer’s name of course) and press enter.  If you are able to access the computer you will be able to send shutdown commands to it.  If you get asked for a password or it denies access you don’t have administrative privileges and you won’t be able to send shutdown commands to that computer.
In this example I’m going to shutdown computer \\yourcomputer on my network.  Before it shuts down it’s going to show a message for 20 seconds.

The first thing you need to do is add which computer you want to shutdown.  Click add and type your computer name in the add computers box.


You can send the command to multiple computers by pressing enter after the name of each computer and typing the name of the next computer on the next line.  Each computer needs to be on its own line.
Click OK when you are finished adding the computer(s) you want to send the command to.
Under what do you want these computers to do: tell it to shutdown, restart, or logoff.

If you want a box to popup on the computer(s) you are sending the command to that lets them know the computer is about to shutdown, restart, or logoff in X many seconds leave warn users of the action checked off.  If you want to change how many seconds to countdown before performing the action you can change that next to seconds.

You can tell a user on the computer you are about to perform the action on why you are performing that action by typing your message in under comment.

Click OK to send the command to the computer(s).


If you get an error when sending the command it will look like the one below.

Shutdown Command via Command Prompt
The shutdown command becomes more flexible and automated when used from the command prompt.  To run the shutdown command from the command prompt, go to start, run, type cmd, and press enter.  In the black box (the command prompt) type shutdown and the switches you want to use with the shutdown command.  You have to use at east one switch for the shutdown command to work.

The Switches
The shutdown command has a few options called switches.  You can always see them by typing shutdown -? in the command prompt if you forget any of them.
-i: Display GUI interface, must be the first option
-l: Log off (cannot be used with -m option)
-s: Shutdown the computer
-r: Shutdown and restart the computer
-a: Abort a system shutdown
-m \\computername: Remote computer to shutdown/restart/abort
-t xx: Set timeout for shutdown to xx seconds
-c “comment”: Shutdown comment (maximum of 127 characters)
-f: Forces running applications to close without warning
-d [u][p]:xx:yy:

The reason code for the shutdown u is the user code p is a planned shutdown code xx is the major reason code (positive integer less than 256) yy is the minor reason code (positive integer less than 65536)

Please note: I’ve noticed using a switch with a – sign doesn’t work sometimes. If you are having trouble try using a / in place of – in your switches.

Examples
shutdown –m \\computername –r –f 
This command will restart the computer named computername and force any programs that might still be running to stop.

shutdown –m \\computername –r –f –c “I’m restarting your computer. 

Please save your work now.” –t 120 
This command will restart the computer named computername, force any programs that might still be running to stop, give to user on that computer a message, and countdown 120 seconds before it restarts.

shutdown –m \\computername –a 
This command will abort a previous shutdown command that is in progress.

Using a Batch File
You can create a file that performs the shutdown command on many computers at one time.
In this example I’m going to create a batch file that will use the shutdown command to shut down 3 computers on my home network before I go to bed.

Open notepad and type the shutdown command to shut down a computer for each computer on the network.  Make sure each shutdown command is on its own line.  An example of what should be typed in notepad is below.
shutdown –m \\computer1 –s
shutdown –m \\computer2 –s
shutdown –m \\computer3 -s


Now I’ll save it as a batch file by going to file, save as, change save as type to all files, give the file a name ending with .bat.  I named mine shutdown.bat.  Pick the location to save the batch file in and save it.
When you run the batch file it’ll shutdown computer1, 2, and 3 for you.

You can use any combination of shutdown commands in a batch file.  I just used the one above as an example

Tuesday, July 5, 2011

Linux CentOS - LAMP (Apache, PHP and MySQL in Linux) Server for CentOS/RHEL

INTRODUCTION

This tutorial shows a quick way of installing a LAMP server (Linux + Apache + MySQL + PHP/Perl together commonly known as LAMP Server) with some additionally repositories (for updated PHP, MySQL packages and phpMyAdmin) on CentOS/RHEL server systems.


Install the extra repositories

The first step requires downloading some RPM files that contain the additional YUM repository definitions.

Centos 5.x

wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
sudo rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm

Centos 6.x

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm


Update CentOS
yum update

YUM PRIORITIES

The Yum Priorities plugin can be used to enforce ordered protection of repositories, by associating priorities to repositories. Visit the Yum Priorities CentOS Wiki for more information.

Install Yum Priorities
yum install yum-priorities

Configure Yum Priorities
1. Open the Yum Priorities configuration file with your favourite text editor
vi /etc/yum/pluginconf.d/priorities.conf
- Ensure the following lines exist
[main]
enabled=1
- Save and close the file

2. Open the CentOS base repository configuration file
vi /etc/yum.repos.d/CentOS-Base.repo
 

- Add the following text to the end of the Base, Updates, Addons, and Extras repository entries (A repository entry is specified with the repository name placed between [example], i.e. the base repository entry is specified with [base])
priority=1 - 
Enable (change the enable value 0 to 1) and add the following text to the end of the CentOSPlus repository entry
priority=2

EPEL RPOSITORY

Extra Packages for Enterprise Linux (EPEL) is a volunteer-based community effort from the Fedora project to create a repository of high-quality add-on packages that complement the Fedora-based Red Hat Enterprise Linux (RHEL) and its compatible spinoffs such as CentOS or Scientific Linux. Visit the Fedora EPEL Wiki for more information.

Install EPEL Repository
- Download the latest EPEL repository
wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

- Run the rpm install command
rpm -Uvh epel-release-5*.rpm

Open the EPEL repository file
/etc/yum.repos.d/epel.repo

- Set priority for the EPEL repository
Add priority=3 to the end of the [epel] section



REMI REPOSITORY

 

The Remi repository is a repository containing updated PHP and MySQL packages and is maintained by Remi. See the Remi Documentation for more information.

Install Remi Repository
1. Download the latest Remi repository
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm


2. Run the rpm install command
rpm -Uvh remi-release-5*.rpm


Configure Remi Repository
1. Open the Remi repository file
vi /etc/yum.repos.d/remi.repo


2. Enable the Remi Repository
Change enabled=0 to enabled=1

3. Set priority for the Remi Repository
Add priority=3 to the end of the [remi] section

Exclude PHP and MySQL packages from the CentOS base repositories
1. Open the CentOS base repository configuration file
vi /etc/yum.repos.d/CentOS-Base.repo


2. Append the following text to all repositories
exclude=*php* *mysql* *phpmyadmin*

APACHE SERVER

Apache HTTP Server is an open-source HTTP server for modern operating systems including UNIX and Windows NT. For more information on Apache HTTP Server, you can visit their website at httpd.apache.org.

Install Apache
yum install httpd

NOTE: The Apache server is installed with our VPS packages with CentOS by default so you may skip this step.

Set the apache service to start on boot
chkconfig httpd on

or type ntsysv for GUI tool

PHP

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. For more information on PHP, visit their website at http://www.php.net/.

Install PHP
yum install php

Restart Apache to load php
/etc/init.d/httpd restart


Test If PHP Is Working Or Not:

1. Create a file named info.php
vi /var/www/html/info.php 

with the following text:
<?php
  phpinfo();
?>

Then point your browser to http://ipaddress/info.php.
NOTE: It is NOT recommended to expose the info PHP file to public view.
That's it! You should see a PHP configuration file displaying all kind of paths and installed modules.

MYSQL

MySQL is a Relational Database Management System (RDBMS) that runs as a server providing multi-user access to a number of databases. For more information on MySQL, you can visit their website at www.mysql.com.

Install MySQL Database Server
yum install mysql-server mysql php-mysql

1. Set the MySQL service to start on boot
chkconfig mysqld on or type ntsysv for GUI tool
 
2. Start the MySQL service
/etc/init.d/mysqld start

3. Log into MySQL
mysql -u root

4. Set the root user password for all local domains (otherwise anybody can access your MySQL database!)
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new-password');
SET PASSWORD FOR 'root'@'localhost.localdomain' = PASSWORD('new-password');
SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('new-password');

5. Drop the Any user
DROP USER ''@'localhost';
DROP USER ''@'localhost.localdomain';

6. Exit MySQL
exit

Alternatively you can run a script to improve the security of your MySQL installation. This is recommended for all MySQL servers in production use!
mysql_secure_installation

PHPMYADMIN

phpMyAdmin is a tool written in PHP intended to handle the administration of MySQL over the Web. Visit the phpMyAdmin website for more information.

Install phpMyAdmin
yum install phpmyadmin

NOTE: You might encounter the following errors while configuring phpMyAdmin
Forbidden
You don't have permission to access /phpmyadmin/ on this server.


To fix:
Edit the /etc/httpd/conf.d/phpMyAdmin.conf file and uncomment the line deny from all
vi /etc/httpd/conf.d/phpMyAdmin.conf
<Directory "/usr/share/phpmyadmin">
  Order Deny,Allow
  # Deny from all
  Allow from 127.0.0.1
</Directory>

NOTE: The location of the phpMyAdmin configuration file is /etc/phpMyAdmin/config.inc.php

Restart the Apache Server
/etc/init.d/httpd restart
 
Test:
1. Visit http://ipaddress/phpmyadmin in your web browser. You should be prompted for authentication
2. Enter the system root username and password and click OK
3. You should now be presented with the phpMyAdmin home page


Monday, July 4, 2011

Upgrading CentOS 5.5 to CentOS 5.6

Before upgrading CentOS 5.5 to 5.6 it cannot be stressed enough how important it is to make a backup of your system before you do this. Actions listed in this post are written with the assumption that they will be executed by the root user running the bash or any other modern shell.Clean All Packages
# yum clean all
The following command will get a list of packages that are going to be updated.
# yum list updates
Lets begin upgrading CentOS 5.5 to 5.6
# yum update
Finally reboot the server for Kernel changes to take effect
# reboot
Verify that CentOS 5.6 is working:
# cat /etc/redhat-release
CentOS release 5.6 (Final)
Or:
# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.6 (Final)
Release: 5.6
Codename: Final
Or:
# rpm -q centos-release
centos-release-5-6.el5.centos.1

Sunday, July 3, 2011

Get Information About Your BIOS / Server Hardware From a Shell Without Opening Chassis ( BIOS Decoder )

biosdecode is a command line utility to parses the BIOS memory and prints information about all structures (or entry points) it knows of. You can find out more information about your hardware such as:
=> IPMI Device
=> Type of memory and speed
=> Chassis Information
=> Temperature Probe
=> Cooling Device
=> Electrical Current Probe
=> Processor and Memory Information
=> Serial numbers
=> BIOS version
=> PCI / PCIe Slots and Speed
=> Much more

biosdecode parses the BIOS memory and prints the following information about all structures :
=> SMBIOS (System Management BIOS)
=> DMI (Desktop Management Interface, a legacy version of SMBIOS)
=> SYSID
=> PNP (Plug and Play)
=> ACPI (Advanced Configuration and Power Interface)
=> BIOS32 (BIOS32 Service Directory)
=> PIR (PCI IRQ Routing)
=> 32OS (BIOS32 Extension, Compaq-specific)
=> VPD (Vital Product Data, IBM-specific)
=> FJKEYINF (Application Panel, Fujitsu-specific)
In this tip you will learn about decoding BIOS data (dumping a computer's DMI ) and getting all information about computer hardware without rebooting the server.

More about the DMI tables

The DMI table doesn’t only describe what the system is currently made of, it also can report the possible evolutions such as the fastest supported CPU or the maximal amount of memory supported.

dmidecode - Read biosdecode data in a human-readable format

Data provided by biosdecode is not in a human-readable format. You need to use dmidecode command for dumping a computer’s DMI (SMBIOS) table contents on screen. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. Thanks to this table, you can retrieve this information without having to probe for the actual hardware.

Task: Display information about IPMI Device

# dmidecode --type 38
Output:
# dmidecode 2.7
SMBIOS 2.4 present.

Handle 0x0029, DMI type 38, 18 bytes.
IPMI Device Information
        Interface Type: KCS (Keyboard Control Style)
        Specification Version: 2.0
        I2C Slave Address: 0x10
        NV Storage Device: Not Present
        Base Address: 0x0000000000000CA2 (I/O)
        Register Spacing: Successive Byte Boundaries

Task: Display information about PCI / PCIe Slots

# dmidecode --type 9
# dmidecode 2.7
SMBIOS 2.4 present.

Handle 0x000E, DMI type 9, 13 bytes.
System Slot Information
        Designation: PCIX#1-133MHz
        Type: 64-bit PCI-X
        Current Usage: Available
        Length: Long
        ID: 1
        Characteristics:
                3.3 V is provided

Handle 0x000F, DMI type 9, 13 bytes.
System Slot Information
        Designation: PCIX#2-100MHz
        Type: 64-bit PCI-X
        Current Usage: Available
        Length: Long
        ID: 2
        Characteristics:
                3.3 V is provided

Handle 0x0010, DMI type 9, 13 bytes.
System Slot Information
        Designation: PCIE#3-x8
        Type: Other
        Current Usage: Available
        Length: Other
        Characteristics:
                3.3 V is provided

Handle 0x0011, DMI type 9, 13 bytes.
System Slot Information
        Designation: PCIE#4-x8
        Type: Other
        Current Usage: Available
        Length: Other
        Characteristics:
                3.3 V is provided

Handle 0x0012, DMI type 9, 13 bytes.
System Slot Information
        Designation: PCIE#5-x8
        Type: Other
        Current Usage: Available
        Length: Other
        Characteristics:
                3.3 V is provided

Task: Find out Information about BIOS

# dmidecode --type 0
Output:
# dmidecode 2.7
SMBIOS 2.4 present.
Handle 0x0000, DMI type 0, 24 bytes.
BIOS Information
        Vendor: Phoenix Technologies LTD
        Version: 6.00
        Release Date: 01/26/2007
        Address: 0xE56C0
        Runtime Size: 108864 bytes
        ROM Size: 1024 kB
        Characteristics:
                PCI is supported
                PNP is supported
                BIOS is upgradeable
                BIOS shadowing is allowed
                ESCD support is available
                Boot from CD is supported
                Selectable boot is supported
                EDD is supported
                3.5"/2.88 MB floppy services are supported (int 13h)
                ACPI is supported
                USB legacy is supported
                LS-120 boot is supported
                ATAPI Zip drive boot is supported
                BIOS boot specification is supported
                Targeted content distribution is supported

Understanding BIOS keywords

dmidecode --type {KEYWORD / Number }
You need to pass dmidecode following keywords:
  • bios
  • system
  • baseboard
  • chassis
  • processor
  • memory
  • cache
  • connector
  • slot
All DMI types you need to use with dmidecode --type {Number}:
# Type Short Description
0 BIOS
1 System
2 Base Board
3 Chassis
4 Processor
5 Memory Controller
6 Memory Module
7 Cache
8 Port Connector
9 System Slots
10 On Board Devices
11 OEM Strings
12 System Configuration Options
13 BIOS Language
14 Group Associations
15 System Event Log
16 Physical Memory Array
17 Memory Device
18 32-bit Memory Error
19 Memory Array Mapped Address
20 Memory Device Mapped Address
21 Built-in Pointing Device
22 Portable Battery
23 System Reset
24 Hardware Security
25 System Power Controls
26 Voltage Probe
27 Cooling Device
28 Temperature Probe
29 Electrical Current Probe
30 Out-of-band Remote Access
31 Boot Integrity Services
32 System Boot
33 64-bit Memory Error
34 Management Device
35 Management Device Component
36 Management Device Threshold Data
37 Memory Channel
38 IPMI Device
39 Power Supply

Display Power supply information, enter:
# dmidecode --type 39

Display CPU information, enter:
# dmidecode --type processor

Read man page for more information:
$ man dmidecode

Restore GRUB

GRUB is a boot loader commonly used with linux operating system. It can be used to managed dual boot environment where linux and windows can coexist easily in a same machine without problem provided you install the windows OS first so that when you install linux, GRUB will overwrite Windows boot loader and automatically detect and manage both operating system the next time you boot your computer. Problems will happen if you alter your partitions outside the knowledge of GRUB, for example, you create new partition in your hard drive using windows. This will cause GRUB to automatically go into GRUB shell when boot. To restore back your GRUB is very simple, just follow easy steps below:

1. find in which partition does GRUB store its configuration file, which is your /boot partition. (hd0,2) means third partition of the first hard drive
grub> find /boot/grub/stage1
(hd0,2)

2. set the root for GRUB to be (hd0,2)
grub> root (hd0,2)

3. write GRUB to the Master boot record(MBR) of your hard drive. Change (hd0) to (hd0,2) to write GRUB to your /boot partition instead
grub> setup (hd0)

4. Reboot machine
grub> reboot

Checking hardisk information on linux

To check hardisk information such as model and serial number, there are a few useful commands like hdparm, sdparm and fdisk.

To check the information about first hardisk for PATA and SATA hardisk:
# hdparm -i /dev/sda

For SCSI disk, a different command is to be used:
# sdparm /dev/sda

To check the hardisk capacity and partitions contained in the hardisk, fdisk can be used:
# fdisk -lu /dev/sda

Setting Up An NFS Server And Client On CentOS 5.5

1 Preliminary Note

I'm using two CentOS systems here:
  • NFS Server: server.example.com, IP address: 192.168.0.100
  • NFS Client: client.example.com, IP address: 192.168.0.101

2 Installing NFS

server:
On the NFS server we run:
yum install nfs-utils nfs-utils-lib

Then we create the system startup links for the NFS server and start it:
chkconfig --levels 235 nfs on
/etc/init.d/nfs start 

client:
On the client we can install NFS as follows (this is actually the same as on the server):
yum install nfs-utils nfs-utils-lib

3 Exporting Directories On The Server

server:
I'd like to make the directories /home and /var/nfs accessible to the client; therefore we must "export" them on the server.
When a client accesses an NFS share, this normally happens as the user nobody. Usually the /home directory isn't owned by nobody (and I don't recommend to change its ownership to nobody!), and because we want to read and write on /home, we tell NFS that accesses should be made as root (if our /home share was read-only, this wouldn't be necessary).
The /var/nfs directory doesn't exist, so we can create it and change its ownership; in my tests the user and group nobody both had the ID 99 on both my CentOS test systems (server and client); when I tried to write to /var/nfs from the NFS client, I got a Permission denied error, so I did a chmod 777 /var/nfs so that everyone could write to that directory; writing to /var/nfs from the client worked then, and on the client the files written to /var/nfs appeared to be owned by the user and group nobody, but on the server they were owned by the (nonexistant) user and group with the ID 65534; so I changed ownership of /var/nfs to the user/group 65534 on the server and changed permissions of /var/nfs back to 755, and voilĂ , the client was allowed to write to /var/nfs:
mkdir /var/nfs
chown 65534:65534 /var/nfs
chmod 755 /var/nfs

Now we must modify /etc/exports where we "export" our NFS shares. We specify /home and /var/nfs as NFS shares and tell NFS to make accesses to /home as root (to learn more about /etc/exports, its format and available options, take a look at
man 5 exports
)
vi /etc/exports
/home           192.168.0.101(rw,sync,no_root_squash,no_subtree_check)
/var/nfs        192.168.0.101(rw,sync,no_subtree_check)
(The no_root_squash option makes that /home will be accessed as root.)

Whenever we modify /etc/exports, we must run
exportfs -a
afterwards to make the changes effective.

4 Mounting The NFS Shares On The Client

client:
First we create the directories where we want to mount the NFS shares, e.g.:
mkdir -p /mnt/nfs/home
mkdir -p /mnt/nfs/var/nfs

Afterwards, we can mount them as follows:
mount 192.168.0.100:/home /mnt/nfs/home
mount 192.168.0.100:/var/nfs /mnt/nfs/var/nfs

You should now see the two NFS shares in the outputs of
df -h
[root@client ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       28G  2.2G   25G   8% /
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 250M     0  250M   0% /dev/shm
192.168.0.100:/home    28G  2.6G   25G  10% /mnt/nfs/home
192.168.0.100:/var/nfs
                       28G  2.6G   25G  10% /mnt/nfs/var/nfs
[root@client ~]#
and
mount
[root@client ~]# mount /dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.0.100:/home on /mnt/nfs/home type nfs (rw,addr=192.168.0.100)
192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,addr=192.168.0.100)
[root@client ~]#

5 Testing

On the client, you can now try to create test files on the NFS shares:
client:
touch /mnt/nfs/home/test.txt
touch /mnt/nfs/var/nfs/test.txt

Now go to the server and check if you can see both test files:
server:
ls -l /home/
[root@server ~]# ls -l /home/
total 55540
-rw-r--r-- 1 root         root                0 Sep 16 17:30 test.txt
[root@server ~]#

Installing Apache2 With PHP5 And MySQL Support On CentOS 5.6 (LAMP)

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial shows how you can install an Apache2 webserver on a CentOS 5.6 server with PHP5 support (mod_php) and MySQL support.
I do not issue any guarantee that this will work for you!

1 Preliminary Note

In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.

2 Installing MySQL 5.0

To install MySQL, we do this:
yum install mysql mysql-server

Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

Set passwords for the MySQL root account:
mysql_secure_installation
[root@server1 ~]# mysql_secure_installation




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n]
 <-- ENTER
New password: <-- yourrootsqlpassword
Re-enter new password: <-- yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 <-- ENTER
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
 <-- ENTER
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
 <-- ENTER
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 <-- ENTER
 ... Success!

Cleaning up...


All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


[root@server1 ~]#


==========================================================================

3 Installing Apache2

Apache2 is available as a CentOS package, therefore we can install it like this:
yum install httpd

Now configure your system to start Apache at boot time...
chkconfig --levels 235 httpd on
... and start Apache:
/etc/init.d/httpd start
Now direct your browser to http://192.168.0.100, and you should see the Apache2 placeholder page:



Apache's default document root is /var/www/html on CentOS, and the configuration file is /etc/httpd/conf/httpd.conf. Additional configurations are stored in the /etc/httpd/conf.d/ directory. 

==========================================================================

Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:
yum install php

We must restart Apache afterwards:
/etc/init.d/httpd restart

Testing PHP5 / Getting Details About Your PHP5 Installation


The document root of the default web site is /var/www/html. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.


vi /var/www/html/info.php

type coding as below:-
<?php
phpinfo();
?>
Now we call that file in a browser (e.g. http://192.168.0.100/info.php):
As you see, PHP5 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.

==========================================================================

Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:
yum search php

Pick the ones you need and install them like this:
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

Now restart Apache2:
/etc/init.d/httpd restart

Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:

 ==========================================================================

phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases.
First we enable the RPMforge repository on our CentOS system as phpMyAdmin is not available in the official CentOS 5.6 repositories:

On x86_64 systems:
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
rpm -Uhv rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

On i386 systems:
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
rpm -Uhv rpmforge-release-0.5.2-2.el5.rf.i386.rpm

phpMyAdmin can now be installed as follows:
yum install phpmyadmin

Now we configure phpMyAdmin. We change the Apache configuration so that phpMyAdmin allows connections not just from localhost (by commenting out the <Directory "/usr/share/phpmyadmin"> stanza):
vi /etc/httpd/conf.d/phpmyadmin.conf
#
#  Web application to manage MySQL
#

#<Directory "/usr/share/phpmyadmin">
#  Order Deny,Allow
#  Deny from all
#  Allow from 127.0.0.1
#</Directory>

Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin

Next we change the authentication in phpMyAdmin from cookie to http:
vi /usr/share/phpmyadmin/config.inc.php
[...]
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';
[...]

Restart Apache:
/etc/init.d/httpd restart 

Afterwards, you can access phpMyAdmin under http://192.168.0.100/phpmyadmin/:

Saturday, July 2, 2011

Installing SHOUTcast Server on CentOS/RHEL

INTRODUCTION

This guide will explain you how to install SHOUTcast server on CentOS/RHEL. SHOUTcast lets you stream live music to listeners and start your own radio station on the web. For more information please visit their website.

What is shoutcast?
SHOUTcast is cross-platform proprietary software for streaming media over the Internet. SHOUTcast Radio is a related web site which provides a directory of SHOUTcast servers. The software, developed by Nullsoft, allows digital audio content, primarily in MP3 or HE-AAC format, to be broadcast to and from media player software, enabling the creation of Internet radio "stations".

WARNING: Please be aware of copyright laws. You cannot stream music unless you own the royalties to it or have permission from the owner, this blog is NOT responsible for what you use this tutorial to do, stream and set up your own server at your own risk.
We assume you have some Linux knowledge.

INSTALLING SHOUTCAST DNAS

 

The SHOUTcast Distributed Network Audio Server (DNAS) is responsible for the actual streaming and broadcasting of your audio content out to the world.

NOTE: If you are using some firewall don't forget to make exception on the appropriate ports.
ATTENTION: Please DO NOT run the DNAS as a root for the security reason, instead we'll create a

shoutcast user
adduser shoutcast
Update the password of 'shoutcast' using
passwd shoutcast
Now login as the new shoutcast user, or you can su to the user
su - shoutcast

Create a directory shoutcast
mkdir shoutcast
cd shoutcast
 
Lets download shoutcast from nullsoft
wget http://yp.shoutcast.com/downloads/sc1-9-8/sc_serv_1.9.8_Linux.tar.gz
Extract the files:

tar xzf sc_serv_1.9.8_Linux.tar.gz

Shoutcast has now been installed and you can tidy up the directory
rm -rf sc_serv_1.9.8_Linux.tar.gz

You need to edit the configuration file according to your needs
vi sc_serv.conf

We are not going to explain each options as they are well documented in the configuration file itself; the most important options are

1. "MaxUser=32"
"The maximum number of simultaneous listeners allowed. Compute a reasonable value for your available upstream bandwidth."

2. "Password=changeme"
"While SHOUTcast never asks a listener for a password, a password is required to broadcast through the server, and to perform administration via the web interface to this server."

3. "PortBase=8000"
"This is the IP port number your server will run on. The value, and the value + 1 must be available."
NOTE: at this point you can go through the settings and change them to what you want or you can save and start SHOUTcast and it will work perfectly.

So it's time to fire up your radio station
./sc_serv &


This will send the server into the background. The problem is, you will not be able to cleanly exit, so you need to just closed out your SSH client terminal window (in our case PUTTY). This way the server will keep running and you won't see it again. Now if you login to the server again and do ps aux, you will see sc_serv should be running still. Another test is to go to: http://serverurl:8000 (if you haven’t change the default ports).
To kill the shoutcast server, login to SHH, type in ps aux and find the PID of ./sc_serv and then in your next command type in kill -9 7537. where 8874 is the PID of the sc_serv process. This will kill your SHOUTcast. Keep in mind that SHOUTcast will not start at system boot, so you will manually need to restart it. Also, the SHOUTcast server uses approximately 32MB of memory while running.

INSTALLING WINAMP ON WINDOWS AND STREAMING TO A SHOUTCAST SERVER

Now lets get Winamp running on Windows so we can stream!
Winamp is a media player for Windows-based PCs, written also by Nullsoft, for more information and to download this software please visit http://www.winamp.com/

Install Winamp
The installation is pretty straight forward and it's just a few simple clicks
NOTE: Configure available options to meet your needs.

- Download and install the SHOUTcast DSP Plug-In for Winamp. By default it will be installed in the same directory as Winamp

- Start Winamp > go to Options > Preferences, then in that window scroll down to Plugins > Dsp/effect. Select Nullsoft shoutcast source dsp 2.0.0 then close it

- Find the new window that poped up, in it, go to the output tab and fill in the address: this is your server URL or IP address, port, and password. You can click on yellow pages and enter in personal info as well. If you make your server public, you will be listed in the SHOUTcast directory where anyone can find your server.

- Go to the encoder tab, and the encoder type should be MP3 encoder, and the settings should be whatever you want. In this example we're using 128Kbps, 44.1khz stereo.

- Go back to output and click on connect and it should be streaming to your server. Use Winamp to play a song of your choice. You can simply go to your now playing page in the main Winamp player window and open a song to play that's on your computer.

To broadcast your voice on mic, go to the input tab of the SHOUTcast source window and select sound card as input and push to talk (or lock if you want to click once to talk then click again to turn off your mic). Remember after done talking, switch back to Winamp as the input device to stream music playing in the player.

Visit http://yourserver:8000 to see the song title and information - which is live information with a total number of listeners. If you login, you will be able to see users connected and IPs with the ability to kick them. To login, the username is admin, and the password is your admin password, or if not set, your broadcast password.

On the website, you will find a link to the listen.pls file that clients can download and play in Foobar, Winamp or other Shoutcast enabled players.

NOTE: The SHOUTcast streams are normally delayed 30 seconds to listeners, so people listening will hear what you hear live about 30 seconds after the fact.