Category Archives: sys admin

check smtp from commnad line

telnet smtp command line image

When working with Linux servers, you need to get mails from them,
they like to alert you on different issues like “help – im dying from lack of space” etc.

mail forwarding

you can easily setup mail forwarding in your sendmail through an external mail server.
all the sendmail config files are in /etc/mail.
edit the mailertable file and add a line like this:

domain    smtp:company_mail_server

for example – lets say you work for data.com and you want to send mails to the data.com domain from your Linux machine through the data.com mail server which is called mail.data.com, so your line in mailertable should be:

data.com    smtp:mail.data.com

test mail

to check that your company mail server will actually allow you to forward mails through it, you need to connect to the smtp service and try to send a mail, this will work from the command line:

telnet mail.data.com 25

this will try to connect to the mail server smtp port and if there is no firewall problem then you should see something like 220 localhost.localdomain ESMTP Sendmail 8.13.8/8.13.8 as a reply.

at this point you try to send a mail through the server.

send mail from command line

telnet to the machine and copy paste this text after editing it:

helo domain_name
mail from: test@email
rcpt to: test@email
data
From: test@email
Subject: subject
whatever you want the mail to have in the body.
.

(the “.” in the end will finish the mail – dont forget it).

so lets explain:
helo domain_name – change the domain_name to your domain – data.com for example
mail from: the email you want the mail to look like it was sent from – test@data.com
rcpt to: who you want to get this test mail – admin@data.com
so the new updated test text would look like:

helo data.com
mail from: test@data.com
rcpt to: admin@data.com
data
From: test@data.com
Subject: test mail from command line
this is test number 1
sent from linux box
.

if there arent any permissions issues the mail server should show you something like: 250 2.0.0 n4CNnNPG003499 Message accepted for delivery

mail queue

there is another nice command line tool to show you whats your Linux server current mail queue: mailq:

[root@centos mail]# mailq
/var/spool/mqueue (1 request)
—–Q-ID—– –Size– —–Q-Time—– ————Sender/Recipient———–
n4CNnNPG003499        0 Wed May 13 02:49 test@email
(host map: lookup (email): deferred)
test@email
Total requests: 1

Technorati Tags: , ,

installing wordpress on windows

installing wordpress on windows image

In my last post i talked about installing apache and mysql on windows for development needs, and now we can add to that install a wordpress blog.

when i do changes to the php code on wordpress i first test it on the local version of the them to make sure its good before going with it public.

1) get the wordpress files

first thing – download the wordpress install file from the website,
the default html folder for xampp is C:\xampp\htdocs so lets create a folder for our blog there: C:\xampp\htdocs\testblog and unzip the wordpress files into that location.

2) setup the MySQL user and database

go to http://localhost/phpmyadmin/index.php and choose the Privileges tab,
find the “Add a new User” link.
fill in a user name – anything you want, and a password.
in the “Database for user” section make sure to check: “Global privileges” press the “Check All” link to give the user all the privileges (this is something you should do only on a development server!!! )

press the Go button.

at this point its best to reload the privileges tab and use the “reload the privileges” link to make sure the user is loaded.

3) edit the wp-config.php file

go to C:\xampp\htdocs\testblog where all the blog files are located and rename wp-config-sample.php to wp-config.php, edit the file and setup:
edit the DB-NAME line and replace “putyourdbnamehere” with the username we created a minute ago,
replace “usernamehere” with the the same user name we just used,
“yourpasswordhere” should be replaced with the user’s password,
and also you have the “Authentication Unique Keys” part where you need to create keys for your blog,
you can use this wordpress.org page which will create the keys for you. copy and paste the keys to the config file.

4) run the wordpress config php

if you installed the wordpress files into “testblog” folder, the install file will be at: http://localhost/testblog/wp-admin/install.php

choose a blog title and an email, and you have your own development blog running.
don’t forget to change the admin password first thing…

you can access your new blog at: http://localhost/testblog/

from here now you can do all the changes and testing you want, including themes and plugins, before you upload them to your live blog.

Technorati Tags: , , , ,

Apache and MySQL on windows

xampp apache and mysql on windows

Although I’m a great Linux fan, i still have Windows on my personal computer, since the computer is not used by me alone, and although i have various Linux OS installed on this same computer, most of the time its on the windows mode. so what do i do when i need to test something on wordpress or mediawiki?

For that reason i needed a development environment on my home computer that will run Apache, MySQL, php and Perl. There are some ways to go about that – i could have installed Cygwin, which is a Linux-like environment for windows.

Another way to go about it is to install the windows version Apache and mysql and php and perl.

These two options are fine solutions but they will need some more work on them , other then the point and click option which is xampp.
xampp for windows version 1.7.1 on default will include all of these:

  • Apache HTTPD 2.2.11 + Openssl 0.9.8i
  • MySQL 5.1.33
  • PHP 5.2.9
  • phpMyAdmin 3.1.3.1

and if you want to can add Perl 5.10.0-2.2.11 from their Add-Ons page.

The install process is a next,next,next version of a regular windows install, and in the the end you have everything installed into the default location at C:\xampp.

xampp control panel

This is the windows control panel that stops and starts the Apache and MySQL for you if you don want to install them as services, personally i prefer to start them when I’m developing since they are resource heavy applications.

Some default file locations:
the html and php files are installed to C:\xampp\htdocs
Perl scripts should be placed here: C:\xampp\cgi-bin
the php.ini (php config file) can be found at: C:\xampp\apache\bin\php.ini
httpd.conf (apache config file) is located in: C:\xampp\apache\conf

Note that for Unix Perl scripts you need to replace the first line with the location of the Perl binary on your windows, so it should look like:
#!”C:\xampp\perl\bin\perl.exe”

Another not is that the xampp on default is set to work with php 5 , but you can from the xampp configure page which is at http://localhost/xampp/ , use the “PHP switcher” and change the install to work with php 4 instead.

And that’s it – your local development website is ready and is available at: http://localhost/ to play with.

Technorati Tags: , , , ,

13 books and magazines for linux sysadmins

This is a list of books and magazines i read through the years to learn my job,
there are many other good books as well, but these are my must haves.

1) Magazines:

linux format linux magazin

These two magazines I have been reading for years and they keep getting me fresh ideas and money savers for work,
they have some tutorials for beginners, some more heavy weight material, and fun projects for the free time (ach, whose kidding, what free time…).

although the info in them is usually a little out of date – they are published once a month and the industry is moving so fast, they do have a lot of good ideas in them, and it much more fun to snuggle with a color magazine then sit in front of the screen to read.

2) DNS:

DNS and BIND (5th Edition)

DNS and bind – every Linux sysadmin should know networking as well, and DNS is one of the pillars of the Internet,
even if you are not responsible to a DNS server, if you are working with anything related to the web or networking, you are using DNS, and knowing this subject good will help you solve many networking and web related problems.

3) Sys Admin handbooks:

linux_system unix_system

These are two books from the same authors, both are fantastic easy to use, in depth system administration books,
but you should buy just one out of the two since they very much a like.

so which one to buy? that depends on what flavors of unix/linux you need this info for:
UNIX System Administration Handbook (3rd Edition)
if you have many different unix servers at work you should get the unix book, it covers Solaris 2.7, HP-UX 11.00, Red Hat Linux 6.2, and FreeBSD 3.4.
a little out dated, but still very helpful as it will show you how to do the same thing in the different systems.

Linux Administration Handbook
on the other hand, if you have different linux versions running this book covers redhat, suse and debian – again showing you how to do the same thing in the different flavors.

4) PHP scripting

Different scripting languages are good for different things, PHP is good for building web interfaces for actions you wish your users to do without a shell account on your server.
php allows you to easily build forms and web pages to manipulate files on your server, and changing passwords, restore and backup files, etc…

php_cookbook programming_php

Programming PHP
Is the php book to start with, it takes you through the step of learning a new language and writing easy code.

PHP Cookbook
this php book will give you real world questions and answers for php coding – like how to open and read each word in a local or remote files, working with other web pages etc..

5) PERL scripting

PERL is faster to use when you want to do heavy weight work on databases or files and text manipulation and sorting.

Learning Perl, 5th Edition
The learning perl book will teach you perl from the beginning with real live samples and mind you – perl is tricky.

Programming Perl (3rd Edition)
this is a more in depth book for perl.

6) Bash shell

bash is the most popular shell for the linux environment, its strong and flexible and allows you to do many manipulations from the command line on files and texts, and its a great scripting tool to ease the work of a weary linux sysadmin (or lazy – its a great moto – always write something once).

Learning the bash Shell: Unix Shell Programming

and

bash Cookbook: Solutions and Examples for bash Users

as you can see by now, i really like the combination of a learning book and a cookbook 😉

7) security

hacking_linux_exposed
Hacking Exposed Linux, 3rd Edition

learning what your enemy knows will help you better understand where to look for security holes,
working in this job turns you slowly into a paranoid sysadmin if you wish to continue working, and this book will give you an insight into where likely holes in your servers will be and how to clear them.

8). IT management

practice_system
Practice of System and Network Administration, The (2nd Edition)

Never forget, your not only a linux sysadmin, you are also working in the IT environment and your decision and work is not just linux, you also need to consider network and the other servers and services around you.
this book is about the practice itself, not the technical stuff which we should all learn, and its based on the vast years of experience the authors have.
for example – how to build a support system – the people the software etc,
or how to structure your mail system so you will have place for growth when the company grows.

one of the best books I have read!!!

Technorati Tags: , , ,

proxy settings for the command line

  

When using applications from the command line,
you will sometimes need to setup a specific proxy for them to use, if you don’t have a direct access to the Internet from the server you are working on.

in some of these application you can setup this through the app switches itself, but simpler apps just use the system network settings.

to fix this you can first check what current settings you have now with:

ENV | grep -i proxy

this should show you the current proxy settings you have.

to add your own settings do:

export http_proxy=”http://<proxy-server-ip>:<port>”
export ftp_proxy=”http://<proxy-server-ip>:<port>”

for example:

export http_proxy=”http://192.168.0.10:8080″

after that, just run your command line app, it should pick up and use these settings.

   

 

Technorati Tags: , , ,

Check apache from command line

When working with web servers we sometimes need to test them and make sure we are getting what we need to get,
and to see what the web server is sending back including headers.
The simplest and fastest way to do that is through command line.

telnet to the web server port – (usually port 80) like this:
telnet yonitg.com 80

and then just paste:
GET / HTTP/1.1
Host: yonitg.com

and press “Enter” twice.

Your output should be something like this:

HTTP/1.1 200 OK
Date: Wed, 11 Mar 2009 00:09:53 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.8 mod_perl/2.0.4 Perl/v5.10.0
Last-Modified: Fri, 21 Dec 2007 02:01:16 GMT
ETag: “200000001d649-ca-441c240f37300″
Accept-Ranges: bytes
Content-Length: 202
Content-Type: text/html

these are standard reply headers from the Apache server on my host,
after the headers you will see the rest of the reply from the web server, in my case:

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
http://www.w3.org/TR/html4/loose.dtd“>
<html>
<head>
<title></title>
</head>
<body>
<h1>It works!</h1>
</body>
</html>

This way you don’t need a sniffer installed just to check if the web server is sane.
also from the linux command line you can also test this with:
GET http://yonitg.com
or
POST http://yonitg.com

the GET and POST command line apps are good tools to test http response,
they are part of the libwww-perl package.

Technorati Tags: , ,