Tuncay Sahin

ICT Engineer | Docent ICT & Trainer

Network Configuration

Action

Command

Get IP configuration

ifconfig -a

IP configuration

vi /etc/sysconfig/network-scripts/ifcfg-eth0

Change hostname

vi /etc/sysconfig/network

 

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=hostname.local

GATEWAY=X.X.X.X

Setup a default Gateway

Open /etc/sysconfig/network file:

# vi /etc/sysconfig/network

 

GATEWAY=X.X.X.X

Local name resolution

vi /etc/hosts

Configure DNS servers

vi /etc/resolv.conf

search uk.aswats.net nl.aswatson.net

nameserver 10.128.254.240

nameserver 10.128.254.241

Network interface disable- enable scripts

“/etc/sysconfig/network-scripts”

ifdown eth0

ifup eth0

Text-based network configuration tool

system-config-network-tui

system-config-network

Restart Network service

service network restart

Manage network interface cards

vi /Etc/udev/Rules.d/70-persistent-net.rules

 

ping host and output results

ping host

get whois information for domain

whois domain

get DNS information for domain

dig domain

reverse lookup host

dig -x host

VI Commands

Action

Command

Exit VI Save

😡

Exit VI without Save

:q!

ULN Registration

Proxy

rpm –import /usr/share/rhn/RPM-GPG-KEY

up2date –proxy=proxy.uk.aswatson.net:8080

Sysprep tbv ULN

/usr/bin/uuidgen -t

Vb: f0dbc569-cd92-4f8d-bf29-9971c3f5721f

vi /etc/sysconfig/rhn/up2date-uuid

Change Password

passwd

Delegate persmissions

visudo

Updates installeren (alle)

yum update

Starting & Stopping

Shutdown the system now and do not

reboot

shutdown -h now

Shutdown the system in 5 minutes and reboot or now

shutdown -r 5 | now

Reboot

reboot now

Disk and Filesystems

 

 

Mount the device cdrom and call it cdrom under the /mnt directory

mount -t iso9660 /dev/cdrom /mnt/cdrom

Mount hard disk “a” as a VFAT file system and call it cdrive under the /mnt

directory

mount -t vfat /dev/hda1 /mnt/cdrive

Unmount the cdrom

umount /mnt/cdrom

Executes graphical application for mounting and unmounting file

systems

usermount

Mount a CIFS share

1.       Create Mount folder
cd /mnt

mkdir <folder>

2.       Modify permissions

chown <alloweduser> <folder>

chgrp <allowedgrp> <folder>

3.       Edit Configuration file

vi /etc/fstab

4.       insert:

<server_with_share>:/<share> /mnt/<folder> cifs user=<remoteuser>,domain=<remotedomain>,uid=<localuser>,gid=<localgrp>,password=<localpasswd>

5.       Run the mount command

mount –a

show disk usage

df

show directory space usage

du

Finding files

 

 

Starting with the root directory, look for the file called fname

find / -name fname

Starting with the root directory, look for the file containing the string fname

find / -name ”*fname*”

Find a file called missingfilename (assumes you have already used the command updatedb (see next)

locate missingfilename

Create or update the database of files on all file systems attached to the linux root directory

updatedb

Show the subdirectory containing the executable file called missingfilename

which missingfilename

Starting with the directory called dir, look for and list all files containing

textstringtofind

grep textstringtofind /dir

Display the last 10 lines of the system log.

tail -f /var/log/messages

Display the file containing the boot time messages – useful for locating

problems. Alternatively, use the dmesg command.

cat /var/log/dmesg

 

 

Moving, copying, deleting & viewing files

 

List files in current directory using long format

ls -l

List files in current directory and indicate the file type

ls –F

List all files in current directory in long format and display in columns

ls –laC

List all files with hidden files

ls -al

Remove a file or directory called name

rm name

Kill off an entire directory and all it’s includes files and subdirectories

rm -rf name

Copy the file called filename to the /home/dirname directory

cp filename /home/dirname

Move the file called filename to the /home/dirname directory

mv filename /home/dirname

Rename files

mv file1 file2

Display the file called filetoview

cat filetoview

Display the file called filetoview one page at a time, proceed to next page

using the spacebar

more filetoview

Create directory

mkdir dir

delete directory dir

rm -r dir

force remove directory dir *

rm -rf dir

Delete directory

rmdir dir

force remove file

rm -f file

Change file owner

chown

Change file group

chgrp

Change file protections

chmod

List opened files

lsof

show processes that using the file

fuser filename

Searching

 

 

search for pattern in files

grep pattern files

search recursively for pattern in dir

grep -r pattern dir

search for pattern in the output of command

command | grep pattern

find all instances of file

locate file

Yum Install

 

 

Display list of updated software

yum list updates

To download and install all updates

yum update

To download and install all Security updates

yum update –security

You can install multiple libraries at once by separating the name of each module with a space.

Yum install software1 software2 etc

Search software

yum search php-

Software info

yum info name

Installing Software

 

 

Install the rpm package called name

rpm -ihv name.rpm

Upgrade the rpm package called name

rpm -Uhv name.rpm

Delete the rpm package called Package

rpm -e package

List the files in the package called package

rpm -l package

List the files and state the installed version of the package called package

rpm -ql package

Reinstall the rpm package called name having deleted parts of it (not deleting using rpm -e)

rpm -i –force package

Decompress the files contained in the zipped and tarred archive called

archive

tar -zxvf archive.tar.gz or

tar -zxvf archive.tgz

User Administration

 

 

Create a new user call accountname

adduser accountname

Give accountname a new password

passwd accountname

Log in as superuser from current login

su

At the lilo prompt, start in single user mode. This is useful if you have forgotten your password. Boot in single user mode, then run the passwd command.

linux single

List current processes

ps

Kill a specific process eg. kill 123

kil 123

Location of Configuration files

 

 

List of devices and their associated mount points.

/etc/fstab

Message of the day

/etc/motd

Bash script that is executed at the end of login process. Similar to autoexec.bat in DOS.

/etc/rc.d/rc.local

Conatins full hostname including domain

/etc/HOSTNAME

There are 4 directories that automatically execute all scripts within the directory at intervals of hour, day, week or month.

/etc/cron.*

A list of all know host names and IP addresses on the machine.

/etc/hosts

Paramters for the Apache web server

/etc/httpd/conf

Specifies the run level that the machine should boot into.

/etc/inittab

Defines IP addresses of DNS servers

/etc/resolv.conf

LILO boot loder configuration file.

/etc/lilo.conf

System log daemon (syslogd) configuration

/etc/syslog.conf

SSH client and server configuration files.

/etc/ ssh_config

/etc/sshd_config

net time server.

/etc/ntp.conf

File- and print sharing with Microsoft clients.

/etc/smb.conf

File Permissions

 

 

 perm

If the command ls -l is given, a long list of file names is displayed. The first column in this list details the permissions applying to the file. If a permission is missing for a owner, group of other, it is represented by – eg. drwxr-x—x

 

Read = 4

Write = 2

File permissions are altered by giving the

chmod command and the appropriate

octal code for each user type. eg

Execute = 1

chmod 7 6 4 filename will make the file

called filename R+W+X for the owner,

R+W for the group and R for others.

 

 

chmod 755

Full permission for the owner, read and

execute access for the group and others.

chmod 777

read, write, execute for all

chmod +x filename

Make the file called filename executable

to all users.

 

Shortkeys

 

 

halts the current command

Ctrl+C

stops the current command

Ctrl+Z

erases the whole line

Ctrl+U

Display list of active X windows

Alt | escape

Start an xterm session

Shift|Control Altx

Printing

 

 

LPRng configuration file.

/etc/lpd.conf

Start | Stop the print daemon

/etc/rc.d/init.d/lpd start | stop

Display status of the print daemon

/etc/rc.d/init.d/lpd status

Display jobs in print queue

lpq

Remove jobs from queue

lprm

Printer control tool

lpc

Start X printer setup interface

printtool

Print a file

lpr

Processes

 

 

List current processes

ps

Monitor processes

top

Display free memory

free

Terminate process

Kill pid

kill all processes named proc *

killall proc

lists stopped or background jobs

bg

brings the most recent job to foreground

fg

brings job n to the foreground

Fg n

Scheduling Jobs

 

 

Schedule a job

at

Schedule repeated jobs

crontab

 

System info

 

 

show current uptime

uptime

display who is online

w

who you are logged in as

whoami

show kernel information

uname -a

cpu information

cat /proc/cpuinfo

memory information

cat /proc/meminfo

show the manual for command

man command

show memory and swap usage

free

show possible locations of app

whereis app

show which app will be run by default

which app

Print the system’s hostname

hostname

display network information

ifconfig

User Management

 

 

create an new user

Adduser

create, delete, modify an new user

useradd, userdel,

usermod

add, delete or modify group

groupadd, groupdel,

groupmod

Sendmail

 

 

Config

sendmail.cf

sendmail.mc

mail aliases, must run “newaliases” after change. use

:include: to include external list in a file.

aliases

mail access control, FEATURE(access_db) should be set in sendmail.mc. For example, in /etc/mail/access

cyberpromo.com REJECT

mydomain.com RELAY

spam@somewhere.com DISCARD

access

list all host/domain accepted for relaying

/etc/mail/relay-domains

NTP

 

 

Install the NTP package

yum install ntp

Configure NTP (udp 123)

Search for these entries:

# vi /etc/ntp.conf

 

server 0.rhel.pool.ntp.org

server 1.rhel.pool.ntp.org

server 2.rhel.pool.ntp.org

Start the NTP service and set it to launch automatically upon boot

service ntpd start

chkconfig ntpd on

Check NTP peers status

ntpq -p

Secure Copy

 

 

Copy a file from a remote host to the local host

scp your_username@remotehost:file.txt /some/local/directory

Copy a file  from the local host to a remote host

scp file.txt your_username@remotehost:/some/remote/directory

Copy a directory  from the local host to a remote host’s directory

scp -r yourdir your_username@remotehost:/some/remote/directory/yourdir

Copy file from remote host to remote host

scp your_username@host1:/some/remote/directory/file.txt \

your_username@host2:/some/remote/directory/

Webserver

 

 

Check if Apche is installed

rpm -qa | grep httpd

Install Apache Webserver

yum groupinstall “Web Server”
yum install httpd

Install PHP Support

yum groupinstall “PHP Support”
yum install php php-mysql

List of useful PHP-libraries and -modules

yum search php-

To see more details about what each module does

yum info name of the module

Start Webserver

service httpd start

apachectl start

set the Apache to run automatically when the server boots

chkconfig httpd on           

Install LAMP (Linux, Apache, MySQL, PHP)

yum groupinstall “Web Server” “PHP Support” “MySQL Database server” “MySQL Database client” 

yum install php-mysql                      

See PHP on the server by creating testpage

vi /var/www/html/info.php

<?php

phpinfo();

?>

 

Visit your site: http://server/info.php

Restart Apache

service httpd restart

Scrtipt to control the functioning of the Apache httpd daemon.

apachectl start|stop|restart|fullstatus|status|configtest

Restart / Stop without aborting currently open connections

apachectl graceful |graceful-stop

MySQL

 

 

Install MySQL

yum groupinstall “MySQL Database server” “MySQL Database client” 

or: yum install mysql-server

Start MySQL

service mysqld start

set MySQL to run automatically when the server boots

chkconfig mysqld on

Configure and set MySQL root password (default is empty)

/usr/bin/mysql_secure_installation

Access the MySQL shell

mysql -u root –p mysql

Create and Delete a MySQL Database

mysql> CREATE DATABASE database dbname;

mysql> DROP DATABASE database dbname;

Show Databases

mysql> SHOW DATABASES;

Show Users

mysql>select user from mysql.user;

Show Users (avoid duplicate names)

mysql>select distinct user from mysql.user;

To connect remotely bind MySQL port 3306 to your machines IP

vi /etc/mysql/my.cnf

 

#Replace xxx with your IP Address

bind-address        = xxx.xxx.xxx.xxx

 

or comment out this line to allow all ip’s.

 

Create user for local/remote logon

mysql>CREATE USER ‘myuser’@’localhost’ IDENTIFIED BY ‘mypass’;

mysql>CREATE USER ‘myuser’@’%’ IDENTIFIED BY ‘mypass’;

Grant permissions on all db’s

mysql>GRANT ALL ON *.* TO ‘myuser’@’localhost’;

mysql>GRANT ALL ON *.* TO ‘myuser’@’%’;

Grant permissions on a specific db

mysql>GRANT ALL ON database.* TO ‘myuser’@’localhost’;

mysql>GRANT ALL ON database.* TO ‘myuser’@’%’;

Grant all permissions on specific database for specific user     

mysql>GRANT ALL PRIVILEGES ON dbname.* TO ‘user’@’%’ IDENTIFIED BY ‘password’

Refresh privileges

mysql>FLUSH PRIVILEGES;

Set Root password

mysql>SET PASSWORD FOR ‘ROOT’@’LOCALHOST”

> = PASSWORD(‘new_password’);

Allow Remote ROOT Access (admin Users)

mysql>GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;

Grant access to database for remote IP address

mysql>GRANT ALL ON database.* TO ‘remoteuser’@’remoteIPaddress’ IDENTIFIED BY ‘PASSWORD’;

Firewall

 

 

Stop/Start Firewall

service iptables stop|start

Disable/Enable Fiewall

chkconfig iptables off|on

Verifiy Firewall status

service iptables status

Add firewall rule (for example MySQL)

/sbin/iptables -A INPUT -i eth0 -p tcp –destination-port 3306 -j ACCEPT

Add firewall rule for specified source (for example MySQL)

/sbin/iptables -A INPUT -i eth0 -s 10.5.1.3 -p tcp –destination-port 3306 -j ACCEPT
/sbin/iptables -A INPUT -i eth0 -s 10.5.1.0/24 -p tcp –destination-port 3306 -j ACCEPT

 

iptables -I INPUT 1 -p tcp –dport 443 -j ACCEPT

 

Meer informatie

Voor meer informatie of voor een persoonlijk adviesgesprek kunt u altijd vrijblijvend contact met mij opnemen.

E-Mail

info@tuncaysahin.nl