Archive for the ‘Linux’ Category

VPN Server

June 18, 2009

Server

  1. apt-get   install   ppp
  2. apt-get   install   pptpd
  3. vi   /etc/pptpd.conf

option /etc/ppp/pptpd-options –> (default). Location of the PPP Options file.

speed 115200 –> (default)

debug –> (default)

logwtmp –> (default). Use wtmp(5) to record client connections and disconnections

localip 7.7.7.10 à If chap Secrete IP is set dynamically then pool IP from this range

remoteip 7.7.7.10-100

#or

#localip 192.168.0.1

#remoteip 192.168.0.234-238,192.168.0.245

#or

#localip 192.168.0.234-238,192.168.0.245

#remoteip 192.168.1.234-238,192.168.1.245

4.  vi   /etc/ppp/pptpd-options

name PPTP –> Name of the local system for authentication purposes (must match

The second field in /etc/ppp/chap-secrets entries)

ms-dns 221.120.96.2

ms-dns 221.120.96.3

netmask 255.255.255.0

proxyarp  –> (default)

nodefaultroute  –> (default)

lock  –> (default)

nobsdcomp  –> (default)

5.  vi   /etc/ppp/chap-secrets

# Secrets for authentication using CHAP

# client            server  secret                      IP addresses

########        #####   ######                  #############

pavel               PPTP    pavel321              192.168.104.6

eximit              PPTP   exim321               221.120.97.28 àGive static IP to client

sum                 PPTP   sum321 * à pull an IP from remote IP range of
/etc/pptd.cong file of VPN server.

6.  /etc/init.d/pptpd   restart

Client
Linux

  1. apt-get install ppp
  2. apt-get install pptp-linux
  3. vi   /etc/ppp/peers/provider –> Delete all line and just write the following lines. pty “pptp 10.0.38.130 –nolaunchpppd” à IP of VPN server.

name eximit à Client name as same of VPN server chap-secrete.

remotename PPTP à As same of  /etc/ppp/pptpd-options of VPN server

file /etc/ppp/options.pptp

ipparam provider

noauth

persist

115200

defaultroute

proxyarp

:x !

  1. vi   /etc/ppp/chap-secrets

# Secrets for authentication using CHAP

# client            server        secret                     IP addresses

eximit          PPTP       exim321                 * à Get IP from remote IP range of

pptpd.conf file or get a static IP from chap-secrete of VPN server.

  1. vi   /etc/ppp/options.pptp  –> Delete all line and just write the following line.
    lock noauth nobsdcomp nodeflate
    :x !
  2. /etc/init.d/ppp restart

Windows

Network Connection –> Create a New connection –> Connect to the network at my workspace –> Virtual Private Network Connection –> Company name (sum) –> Do net dial the initial connection –> Host name/IP (221.120.96.236)

Debian

June 18, 2009

Debian 5.0 CD/DVD download

http://cdimage.debian.org/debian-cd/5.0.0/i386/iso-dvd/ >>>For Debian 5 DVD ISO

http://cdimage.debian.org/debian-cd/5.0.0/i386/iso-cd/ >>>>>For Debian 5 CD ISO

[#]   vi   /etc/apt/sources.list

Debian 4
deb http://ftp2.de.debian.org/debian/ etch main

deb-src http://ftp2.de.debian.org/debian/ etch main

Debian 5

Source 1:

            deb     http://ftp.debian.org/debian/  stable main contrib non-free
            deb-src http://ftp.debian.org/debian/  stable main contrib non-free
            deb     http://security.debian.org/    stable/updates main contrib non-free
            deb-src http://security.debian.org/    stable/updates main contrib non-free

Source 2:

deb http://ftp.nl.debian.org/debian/ lenny main contrib non-free
deb http://security.debian.org/ lenny/updates main contrib non-free

            Source 3:

            deb http://http.us.debian.org/debian stable main contrib non-free
            deb http://non-us.debian.org/debian-non-US stable/non-US main contrib non-free
            deb http://security.debian.org stable/updates main contrib non-free

      Source 4:
      Latest debian apt source list

deb http://ftp.fr.debian.org/debian/ lenny main
deb-src http://ftp.fr.debian.org/debian/ lenny main

deb http://security.debian.org/ lenny/updates main
deb-src http://security.debian.org/ lenny/updates main

deb http://volatile.debian.org/debian-volatile lenny/volatile main
deb-src http://volatile.debian.org/debian-volatile lenny/volatile main

:x !

[#]   apt-get update àupdate the package lists

[#] apt-get upgrade àupgrade all installed packages

[#]   apt-get   install   package name

[#]   apt-get   remove package name à Remove package

[#]   dpkg –purge package name à Remove package

[#]   dpkg –l à show all installed and removed packages

[#]   dpkg –l   package name à Show the package is installed or not.

[#]   dpkg -L pkg à List of files in package

[#]   dpkg -s pkg à Show status of package

[#]   dpkg -p pkg à Show details of package

[#]   apt-cache search dhcp à Search for package

[#]   apt-get source pkg à get the source of package

Package name List

  1. portmap
  2. sysv-rc-conf  à Show the port status.
  3. traceroute
  4. openssl
  5. libssl-dev
  6. iproute
  7. iptraf
  8. tcpdump
  9. zip
  10. unzip
  11. php4-apc
  12. libpng
  13. libjpeg
  14. minicom
  15. mgetty
  16. dhcp3-server
  17. libnet-ssleay-perl
  18. rdate
  19. perl-suid
  20. ncurses
  21. mrtg
  22. snmpd
  23. zlib1g-dev
  24. pptp-linux
  25. namp
  26. squid
  27. wget
  28. vim
  29. psmisc
  30. sysv-rc-conf
  31. gcc
  32. tcptrack
  33. iftop
  34. mtr

PGF server

June 18, 2009

NAT, Firewall, Proxy

1st Step: Setup IP in Interface

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet static

address 221.120.99.72

netmask 255.255.255.224

network 221.120.99.64

gateway 221.120.99.65

auto eth1

iface eth1 inet static

address 192.168.100.1

netmask 255.255.255.0

auto eth1:0

iface eth1:0 inet static

address 192.168.0.1

netmask 255.255.255.0

auto eth1:1

iface eth1:1 inet static

OR
auto eth1:aknet
iface eth1:aknet

address 192.168.110.1

netmask 255.255.255.0

2nd Step: Squid Configuration

  1. apt-get   install squid
  2. vi   /etc/squid/squid.conf

3rd Step: Rules.sh Configuration

  1. 1. vi   /etc/init.d/rules.sh OR any name of the file

#!/bin/sh

any=0.0.0.0/0.0.0.0

local_net=192.168.0.0/24

echo 1 > /proc/sys/net/ipv4/ip_forward

#echo 163760 > /proc/sys/net/ipv4/ip_conntrack_max

#echo 3072 > /proc/sys/net/ipv4/neigh/default/gc_thresh1

#echo 4608 > /proc/sys/net/ipv4/neigh/default/gc_thresh2

#echo 6144 > /proc/sys/net/ipv4/neigh/default/gc_thresh3

########################### Flush all rules ###############################

/sbin/iptables   -F à Flash all firewall (INPUT, OUTPUT, FORWARD)

/sbin/iptables -F INPUT

/sbin/iptables -F OUTPUT

/sbin/iptables -F FORWARD

/sbin/iptables -F -t nat

########################## Set default policy ############################

iptables   -P   INPUT   ACCEPT or  iptables – -policy INPUT ACCEPT Accept

All incoming packet from internet inside gateway server.
iptables   -P   OUTPUT   ACCEPT Accept all output from gateway server to internet
iptables   -P   FORWARD   DROP –
Drop all forward packet.

################# Accept all internal communications with loop back ############

/sbin/iptables -A INPUT -j ACCEPT -i lo

/sbin/iptables -A OUTPUT -o lo -p all -j ACCEPT

######################## Rules for external interface ########################

/sbin/iptables -A INPUT -p ip -i eth0 -j ACCEPT

/sbin/iptables -A INPUT -p ip -i eth1 -j ACCEPT

/sbin/iptables -A INPUT -p ip -i ppp+ -j ACCEPT

##################### Accept Forwarding WAN interface ####################

iptables   -A   FORWARD   -i   eth0 –  Allow all packet from Local  PC to internet

Connected by Gateway server.

iptables   -A   FORWARD   -i   eth0   -j   ACCEPT Allow all packet from local pc to Internet connected by Gateway server.

iptables   -A   FORWAD   -s   0/0   -d   0/0   -j   ACCEPT –
Allow all packet from
Local PC to internet connected by Gateway server.

iptables   -A   FORWAD   -s   192.168.100.0/24   -d   0/0   -j   ACCEPT
à Allow  all

Packets from 192.168.100.0/24 block Local PC to all destinations (internet).

iptables   -A   FORWAD   -s   192.168.100.2/32   -d   4.2.2.2   -j   ACCEPT à Allow all Packet from 192.168.100.2 local pc to only 4.2.2.2 (destination)

########################   MAC base firewall   ############################

iptables   -A   FORWAD   -s   192.168.100.2  -d 0/0   -m  mac  – -mac-source
00:02:21:D4:C2:11  -j ACCEPT
– Allow the packet from a single local  PC whose

(IP- 192.168.100.2 and MAC – 00:02:21:D4:C2:11) to all destination (internet)

##########################   Rules for PPP interface   ######################

/sbin/iptables -A INPUT -p ip -i ppp+ -j ACCEPT

/sbin/iptables -A OUTPUT -p ip -o ppp+ -j ACCEPT

/sbin/iptables -A FORWARD -p ip -i ppp+ -j ACCEPT

####################### Rules for unnecessary ports ######################

NETBIOS_TCP=”135,136,137,138,139,445,3127,3198,5100,5001″

NETBIOS_UDP=”60,66,72,78,100,135,136,137,138,139,5100,5001″

/sbin/iptables -A INPUT -s 0/0 -p tcp -m multiport –dport $NETBIOS_TCP -j DROP

/sbin/iptables -A INPUT -s 0/0 -p udp -m multiport –dport $NETBIOS_UDP -j DROP

/sbin/iptables -A FORWARD -s 0/0 -p tcp -m multiport –dport $NETBIOS_TCP -j DROP

/sbin/iptables -A FORWARD -s 0/0 -p udp -m multiport –dport $NETBIOS_UDP -j DROP

########################### Trojan Block ###################

TROJAN_PORTS_TCP=”12345,12346,1524,27665,31337,19006,3969,9996,5554″

TROJAN_PORTS_UDP=”12345,12346,27444,31337,19006,3969,9996,5554″

/sbin/iptables -A INPUT -p tcp -s 0/0 -m multiport –dport $TROJAN_PORTS_TCP -j DROP

/sbin/iptables -A INPUT -p udp -s 0/0 -m multiport –dport $TROJAN_PORTS_UDP -j DROP

/sbin/iptables -A FORWARD -p tcp -s 0/0 -m multiport –dport $TROJAN_PORTS_TCP -j DROP

/sbin/iptables -A FORWARD -p udp -s 0/0 -m multiport –dport $TROJAN_PORTS_UDP -j DROP

######################## Block Susser worm  ################

#/sbin/iptables -A INPUT -p tcp –dport 9996 -s 0/0 -d 0/0 -j DROP

#/sbin/iptables -A INPUT -p tcp –dport 5554 -s 0/0 -d 0/0 -j DROP

####################### Allow ping replies on BOTH interface ################

iptables -A INPUT -p ICMP -i eth0 -j ACCEPT

iptables -A INPUT -p ICMP -i eth1 -j ACCEPT

#################### Open ftp port OUTSIDE interface ######################

iptables -A INPUT -p tcp -i eth0 –dport 21 -j ACCEPT
iptables -A INPUT -p udp -i eth0 –dport 21 -j ACCEPT
iptables -A INPUT -p tcp -i eth1 –dport 21 -j ACCEPT
iptables -A INPUT -p udp -i eth1 –dport 21 -j ACCEPT

################## Open secure shell port BOTH Interfaces ##################

iptables -A INPUT -p tcp -i eth0 –dport 22 -j ACCEPT
iptables -A INPUT -p udp -i eth0 –dport 22 -j ACCEPT
iptables -A INPUT -p tcp -i eth1 –dport 22 -j ACCEPT
iptables -A INPUT -p udp -i eth1 –dport 22 -j ACCEPT

######################### IP/ URL block ###############

iptables -A INPUT -s 192.168.0.5/32 -d 0/0 -j DROP

iptables -A FORWARD -s 192.168.0.5/32 -d 0/0 -j DROP

iptables -A INPUT -s 0/0  -d 192.168.2.11/32 -j DROP

iptables -A FORWARD -s 0/0 -d 192.168.2.11/32  -j DROP

iptables -A INPUT -s 192.168.0.0/24 -d facebook.com  -p tcp –dport 443 -j DROP

iptables -A FORWARD -s 192.168.0.0/24 -d facebook.com  -p tcp –dport 443 -j DROP

########################## Proxy rules #################

/sbin/iptables -t nat -A PREROUTING -p tcp -i eth1 -s 192.168.0.0/24   –dport 80 -j REDIRECT –to-port 8080

######################## Rules for Nating / Maquerading ####

#iptables -t   nat   -A   POSTROUTING   -s   192.168.100.0/24 -o eth0 -j   MASQUERADE

#/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE -s ${any} -d ${any}

#/sbin/iptables -t nat -A POSTROUTING -o ppp+ -j MASQUERADE -s ${local_net} -d ${any}

/sbin/iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -d 0/0 -j SNAT –to-source 221.120.99.72 – without proxy

/sbin/iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -d 0/0 -j SNAT –to-source 221.120.99.72 – using proxy server

# iptables -t nat –A PREROUTING –i eth1 –p tcp –d 0/0 – -dport 80 –j DNAT – -to
192.168.0.3:3128
– 192.168.0.1 is Gateway and 192.168.0.3 is Proxy server

  1. 2. chmod 744 rules.sh OR chmode   +x   rules.sh – Give executable permission to the file rules.sh.
  2. 3. /etc/init.d/rules.sh

  1. 4. Execute the sonic file during startup the machine

Debian

ln -s   /etc/init.d/rules.sh   /etc/rc2.d/S98rules.sh –Run this file during startup.

Red Hat

[#]   cp   rules.sh   /usr/bin/rules.sh– for give command by file name Ex – sonic.

[#]   vi   /etc/rc.local
rules.sh
:x !

etc directory

November 9, 2008

Ø System configuration files, user information are store in etc directory.

Ø /etc/password  User’s information in plaintext.

Ø /etc/shadow User’s information + password in Encrypted format.

Run level

I. init 0 Shutdown

II. init 1 Single user mode (close all consol except current working consol.
We can enter single user mode without root using password.)

III. init 2 Multi user mode without NFS (Network file system)

IV. init 3 Full Multi user mode (text mode).

V. init 4 Unused.

VI. init 5 X window (Graphical mode)

VII. init 6 Reboot

1. [#] runlevel Display init level. It will display
N 3 à N = none, 3 = current init level.
1 S à 1 = Current init level, S = single user mode.

2. [#] vi /etc/inittab Change run (init) level
id: 3: initdefault i change 3 (full multi user mode) to 1 (single user mode)
Esc – : x!

3. Create virtual terminal (consol)

[#] vi /etc/inittab go to 50 number line (by 50 gg)

1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
…………………………………………
6:2345:respawn:/sbin/mingetty tty3

8:2345:respawn:/sbin/mingetty tty8
:x !
[#] reboot Reboot the machine to work added F8 console
[#] init q Reload the inittab file. (It is better than reboot the machine)

4. Datives the Alt+Ctrl+Del command to reboot a machine and display a message.

[#] vi test
#!/bin/bash
echo “This feature is disable by the system admin”
:x !
[#] chmod +x test
[#] cp test /usr/bin/test
[#] vi /etc/inittab

#Trap CTRL-ALT-DELETE
#Ca: : ctrlaltdel:/sbin/shoutdown -t3 -r now comment out the line.
Ca: : ctrlaltdel:usr/bin/test add the line
:x !
[#] init q Reload the inittab file.

There are two type Boot Loader

Ø Grub grand Unified Boot Loader.

Ø LiLo Linux Loader (old version)

5. Set password to enter kernel boot loader.

[#] vi /etc/grub.conf

title fedora core 0
title others 1
default =1
default booting OS
timeout = 5 ­ 5 second wait for choosing booting OS
passwd=123
hidemenue give password of editing kernel by e during booting session
passwd=123

6. [#] vi /etc/passwd
root: x: 0:0: root: /root/bin/bash
mahmud: x: 500:500: Mahmudul Hasan/home/bin/bash

Here ……
root – User name.
x – User password in shadow file.
0 – User id (always root user id and password is 0:0, system created user id is
form 0 to 499 and Normal created user id is start form 500.
0 – Group id
root – User’s full name and other information (address, phone number etc.)
/root – Home directory of root.
/bin/bash – Shell. If here /bin/no login or /bin/false display then the user can
not login

7. [#] vi /etc/shadow à information are shown in encrypted format
root: lkdfhalkfj94u8392kldfna: 0:0: root: /root/bin/bash

8. [#] vi /etc/passwd
root:! x: 0:0: root: /root/bin/bash à The user is locked.
root: x: 0:0: root: /root/bin/bash à The user is unlocked.

We can also lock the user by command: –
[#] passwd –l mahmud à Lock the user named mahmud.
[#] passwd –u mahmud à Unlock the user named mahmud.


9. [#] vi/etc/motd à [motd – message of the day]. When login the message is
displayed in the screen.
Welcome to linux pathshala
:x !

10. [#] vi /etc/issue à Give message before login.

hello this is me
:x !

11. [#] vi /etc/rc.local à Run the file during start the machine.
reboot à Reboot the server when start the machine every time.
:x !

12. Deny services to the hosts

[#] vi /etc/hosts.deny

ALL:ALL or all:all Deny all service to all hosts [1st ALL is service name &
2nd ALL is host name].
sshd:ALL or sshd : ALL Deny sshd service to all hosts.
sshd,telnet:ALL Deny sshd and telnet service to all hosts.
sshd:sum,mum Deny sshd service to host sum and mum
sshd:192.168.1.1 192.168.1.2 Deny sshd service to the IP
sshd:192.168.1.1,192.168.1.2 Deny sshd service to the IP
sshd:ALL EXCEPT 192.168.1.1 Deny sshd service to all host except the IP.
:x !

13. Allow services to the hosts

[#] vi /etc/hosts.allow
ALL:ALL or all:all Allow all service to all hosts [1st ALL is service name &
2nd ALL is host name].
sshd:192.168.1.2 Allow sshd service to IP 192.168.1.2
sshd:linux2
Allow sshd service to host linux2
sshd:192.168.1. Allow sshd service to IP 192.168.1. all networks.
sshd:192.168.1.0/24 Allow sshd service to IP 192.168.1.2/24 all networks.
snmpd: 221.120.96. Allow snmpd to this block.
:x !

[#] cat /etc/service Display the port number of different protocol.

Interface Setup

November 6, 2008

LAN – Local Area Network

NIC – Network Interface Card

MAC – Media Access Control [00:21:03:A1:15:C6]
[00:21:03 – vendor ID, A1:15:C6 – Serial Number]

Ethernet Adapter – eth0 (LAN 1), eth1 (LAN 2)

ARP – Address Resolution Protocol. [IP to MAC]

PingPacket Internet Gopher.
init.d
d – Demon (service)

1. [#$] dmesg Display Kernel Log message.

2. [#$] dmesg | grep eth0 Search eth0 is connected or not.

3. [#$] dmesg | grep * Display all Ethernet interface.

4. [#$] ifconfig Display the interface properties.

5. [#$] ifconfig eth0 Display the interface properties of eth0 (1st LAN).

6. [#$] ifconfig –a [a-all]. Display the interface properties.

7. [#$] system-config-network-cmd Display LAN information.

8. [#$] mii-tool Check cable of all interface is connected or not. It has some output:

Link OK

Auto negation failed, Link Ok

No MII Transceiver present

No link.

9. [#$] mii-tool eth0 Display the cable is connected or not in eth0 interface.

10. [#$] mii-tool -r Reset all interface (disable then enable).

11. [#$] mii-tool -r eth0 Reset eth0 interface (disable then enable).

12. [#$] route –n Display the Gateway.

Change host Name

13. [#] hostname sum Change hostname to sum temporary. After restart the
machine the hostname (sum) will not exists.

14. Permanently set host name (this will effect after restart the server)
[#] vi /etc/sysconfig/network
Networking = yes

Hostname = sum
:x !

15. Input IP and host name in host file. Host file is working locally and it work before DNS. We can ping a machine by host in replace of IP. In that case the host name should be written against IP address in host file.

[#] vi /etc/hosts

127.0.0.1 Localhost.localdomain Localhost à This create during installation
192.168.100.1 sum.com ns1 Domain – sum.com Host name – ns1
192.168.100.1 ns1.sum.com.bd ns1 FQDN -Full Qualified Domain Name
(host name. Domain name)
192.168.1.1 Linux1 Mahmud 2 host name and not case sensitive.
:x !

[#] ping 192.168.1.2
or
[#] ping Linux1
or
[#] ping Mahmud

Set IP address

Static IP – Put IP manually
Dynamic IP – Pull an IP from DHCP server.
[*] Use Dynamic IP configuration (BOOTP/DHCP) [* - space bar]

IP Address: 192.168.1.2
Net Mask: 255.255.255.0
Default Gateway (IP): 192.168.1.254
Primary Name Server (DNS): 192.168.1.1

Set IP in LAN card

16. Debina [ vi /etc/network/interface ]

auto eth0

iface eth0 inet static

address 221.120.96.254

netmask 255.255.255.224

network 221.120.96.224

broadcast 221.120.96.255

gateway 221.120.96.225

# For Office AP

auto eth0:0

iface eth0:0inet static

address 172.16.119.1

netmask 255.255.255.224

RedHat

[#$] netconfig By default set IP in eth0.

[#$] netconfig –d eth1 Set IP in eth1.

[#$] netconfig - -device eth1 Set IP in eth1.

[#$] system-config-network Set IP in eth0 or eth1.

[#$] setup Network Configuration, Set IP address in eth0 or eth1

[#$] vi /etc/sysconfig/network-scripts/ifcfg-eth0

Device = eth0
ONBoot = yes
BOOT PROTO = static
IPADDRESS = 192.168.1.2
NETMASK = 255.255.255.0
GATEWAY = 192.168.1.254
DNS = 192.168.1.1
If ifcfg-eth0 file is not in network-scripts directory then-

[#] cd /etc/sysconfig/network-scripts
[#] ls see the file under network-scripts directory.
[#] cp ifcfg-lo ifcfg-eth0 Create a file named ifcfg-eth0 from lo (loop back)
[#] vi /eht0

17. After set the IP should be restart the service network

[#$] service network restart
[#$] /etc/init.d/network restart

18. IP Aliasing (set more than one IP in a single LAN card)

Temporary (After rebooting the machine the IP will release)

ifconfig eth1 192.168.10.1
ifconfig eth1:0 192.168.10.1 By default get subnet mask of that IP (2nd IP in a NIC)
ifconfig eth1:1 192.168.10.2 netmask 255.255.255.0 Give the subnet mask. (3rd IP)

Permanent

[#] vi /etc/rc.local

ifconfig eth1:0 192.168.10.1 netmask 255.255.255.0 2nd IP
ifconfig eth1:1 192.168.20.2 netmask 255.255.255.0
3rd IP
:x !

[#] service network restart After restart the Network service the extra IP will release.
[#] /etc/rc.local After this command the IP will add in LAN card.

ICMP REQUEST

19. Temporary block replay of ping request (this will deactivate after reboot machine)
[#] cat /proc/sys/net/ipv4/icmp_echo_ignore_all Display ICMP request is
Blocked or not [0-not block replay of ping request, 1or other is value – block]

[#] echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all Write 1 to the file for
block the replay of ping request.

20. Permanently block replay of ping request
[#] vi /etc/re.local this file will execute when PC getting start)
touch à after the touch write the line.
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
:x !
[#] /etc/rc.local Run the rc.local file without reboot the machine.

21. Linux and Windows Ping properties
[#$] ping 192.168.1.1 [Linux] Continuous Ping request
[#$] ping 192.168.1.1 [Windows] 4 ping request.
[#$] ping 192.168.1.1 –t or /t [Windows] Continuous Ping request.
[#$] Ctrl + C [Linux, Windows] Quit form ping request.
[#$] ping 192.168.1.1 –c 10 [Linux] 10 packet send

[#$] ping 192.168.1.1 –n 10 [Windows] 10 packet send

[#$] ping 192.168.1.1 –i 5 [Linux] Send packet after each 5 second.
[#$] ping 192.168.1.1 –s 128 [Linux] Packet Size change to 128 byte (default 64)
[#$] ping 192.168.1.1 –l 128 [Win] Packet Size change to 128 byte (default 32)
[Linux by default TTL - 64] [Windows by default TTL - 128]

23. Display the hop to reach the destination and packet loss of each hop.
[#$] traceroute 4.2.2.2 (linux)
mtr 4.2.2.2 (linux)
tracert 4.2.2.2 (win)

pathping 4.2.2.2 (win)


ARP – Address Resolution Protocol. [IP to MAC]

22. [#] arp – a [a-all]. If the machine has IP 192.168.1.2 then it takes MAC of all IP
holder machine of 192.168.3.0 block.

23. [#] arp 122.247.47.11 Get the MAC of the IP and check the physical link.

24. [#] arp –i eth1 [i-interface]. Take MAC of pc’s that are connected by eth1.

25. [#] arp –i eth1 -nv [i-interface, n- number, v- verbose]. Take MAC of pc’s that
are connected by eth1 and show the number of pc connected by eth1.

MAC Clone

26. Temporary (after reboot the machine the new cloned MAC flashed)

[#] ifconfig eth0 down Down the eth0 interface
or
[#] ifdown eht0

[#] ifconfig eth0 hw ether 00:21:03:A1:15:C6 Old MAC

[#] ifconfig eth0 up Up the eth0 interface
or
[#] ifup eht0

27. Permanently Change the MAC

[#] vi /etc/rc.local

ifdown eht0
ifconfig eth0 hw ether 00:21:03:A1:15:C6
à Old MAC

ifconfig eth0 up Up the eth0 interface

: x!

Hard Drive

September 11, 2008
  1. Type of Hard drive

    1. IDE – Integrated Device Electronics.
    2. SATA – Serial Advance Technology Attachment.
    3. SCSI – Small computer system interface.
  2. Cable Selection

    IDE device

    SATA / SCSI

    Primary Master [P.M]

    hda

    sda

    Primary Slave [P.S]

    hdb

    sdb

    Secondary Master [S.M]

    hdc

    sdc

    Secondary Slave

    hdd

    sdd

3. Parts of Hard drive

    1. Zero Sector àIt has two part

(a) MBR (Master Boot Recorder) – Have boot information of OS.
(b) Partition information – Have information of different partitions

    1. Other space of a Hard Dri

      Partitions of Hard Drive

a. Primary  windows have 1 primary & Linux have4 primary partition

Primary partition 1 hda 1

Primary partition 2 hda 2

Primary partition 3 hda 3
Primary partition 4 hda 4

Extended we can create logical partition in extended partition.

Logical partition 5 hda 5 (drive D)
Logical partition 6
hda 6 (drive E)
Logical partition 7
hda 7 (drive F)

Troubleshooting

September 10, 2008

1. Get password to enter kernel

Ø Insert the 1st CD of Linux

Ø Boot: linux rescue [Enter]

Ø Language: English [Enter]

Ø Keyboard: US [Enter]

Ø Yes/No [Enter]

Ø Continue [Enter]

Ø Ok [Enter]

Ø chroot /mnt/sysimage à to work in root user.

ü [#] vi /etc/grub.conf
password = 1234 à write this line below or upper of hide menu line

2. Get root password

ü Insert CD and take the above steps.

ü [#] vi /etc/passwd
delete password [:x: à ::]
root: x: 0:0: root: /root/bin/bash

ü Reboot the machine and login without root password and then write

ü [#] passwd à and change the root password.

Or

ü Reboot the server by Alt+ctrl+del

ü When booting option come select Linux à press e for edit run level à select Kernel (2nd option) à e à give a space and write 1 (run level) or single or single b or single boot (single user mode to change password) à Enter à b

ü After login write Passwd and give a new password root

3. Recover Linux boot loader.

ü Insert CD and take the above steps.

ü [#] fdisk –l à See the hard disk is hda or hdb

ü [#] grub-install /dev/hdc

ü [#] reboot

4. Reboot the machine during startup

ü [#] vi /etc/rc.local à This file execute during startup a machine
erase reboot or give hash before reboot to inactive the command.

ü [#] reboot


Or

ü Reboot the server by Alt+ctrl+del

ü When booting option come select Linux à press e for edit run level à select Kernel (2nd option) à e à give a space and write 1 (run level) or single or single b or single boot (single user mode to change password) à Enter à b

ü After login write vi /etc/inittab and change the run level form 0 or 6 to 3

5. Retrieve file and data loss due to power loss before save the file.

ü During editing a file if the power goes down before save it the file will save as .abc.swp format where abc is the original file name.

ü [#] vi -r abc à To recover the file and it’s data

ü [#] rm .abc.swp à Delete the .swp file that created for power loss.


6. dsafda



Basic Command

September 10, 2008

Linux Command

  • Linux is multi user & multi task Operating System.
  • Alt + F1 to Alt+F6 à Console Mode. (By default)
  • Alt + F7 à Graphical Mode. (By default)
  • [root@ns1 ~]# à Here root is User name, ns1 is Host name
  • # à Super user. Have access to all application.
  • $ à Normal user. Do not have access to all application

System Information

1. [# $] tty à Type of terminal. Display the current working terminal.

2. [# $] logout, exit, Ctrl+d à Exit form the login user.

3. [# $] clear, Ctrl+L à Clear screen.

4. [# $] date à Display Operating System date and time.

5. [#] hwclock à Display BIOS date and time.

6. [# $] date 021520522008.35 –> Edit Operating System year, date, time

Format- MM DD HH mm YYYY.sec (second is optional).

7. [#] hwclock – -systohc à Edit BIOS (hardware) time from OS time then reboot machine.

8. [#] hwclock – -hctosys à Edit OS time from BIOS (hardware) time then reboot machine.

9. [# $] history à Display the command used previously.

10. [# $] history 5 à Display the last 5 command used previously.

11. [# $] !10 à Execute the number 10 history command.

12. [# $] !p à Execute the most recent command that have an alphabet p

13. [# $] history –c à Clear history.

14. [# $] cal à Display the current month calendar.

15. [# $] cal 2 2001 à Display calendar of February 2001

16. [# $] cal 2 à Display calendar of year 2 (12 month)

17. [# $] bc à Calculator (press 12+15 à Enter, result =28)
quit à exit from calculator

18. [# $] man à Manual. Ex – man cal (give the manual of calendar).

19. [# $] init 0 à shutdown now
poweroff à shutdown now
shutdown –h now à shutdown now
shutdown –h 0 à shutdown now
shutdown –h 10 à shutdown after 10 minutes.
halt –p à shutdown now

20. [# $] init 6 à reboot now
reboot à reboot now
shutdown –r now à reboot now
shutdown –r 0
à reboot now
shutdown –r 10 à reboot after 10 minutes.
Alt + Ctrl + Delete à reboot now

21. [# $] Ctrl + C à Cancel Shutdown and Reboot

22. [# $] Shift + Page UP à Page UP

23. [# $] wall à Send message to every console. Ex- wall welcome (“welcome”
message is send to all working terminal) or Ex – wall “dmidexcode –q”.

24. [# $] w à USER TTY FROM LOGIN (time) IDLE JCPU PCPU WHAT
who
à root tty1 April 12 21:24
finger
à Login Name Tty Idle Login Time Office OfficePhone
users à mahmud root

25. [# $] finger mahmud à Display user mahmud is exist or not and display its folder
information.

26. [#] fdisk –l à [fixed disk]. Display the hard drive information.

27. [# $] free –m à Display free memory of RAM and Swap.

28. [# $] df –h à [d - Disk, f – free, h - human readable.] Display Linux Drive space
Information.

29. [# $] du –sh /home/Alex à [s- summary, h-human readable]. Display the
summary of space used of /home/Alex directory.

30. [# $] du –h /home/Alex à [h-human readable]. Display the details space use sage
of /home/Alex directory.

31. [# $] cat /proc/cpuinfo à Display CPU (processor) information.

32. [# $] cat /proc/meminfo à Display memory of RAM & Swap information.

33. [# $] cat /proc/partitions à Display partition information of Hard Disk.

34. [# $] cat /proc/version à Display OS (Linux) version.

35. [# $] uname –r à Display kernel version.

36. [# $] top à Display Linux Task Manager.
Z à Display Colored files.
q à Exit form Task Manager.

37. [# $] eject à Open CD-ROOM.

38. [# $] eject –t à Close CD-ROOM.

39. [# $] startx à Go to graphical mode.

40. [# $] init 5 à Go to graphical mode.

41. [# $] pwd à Display present working directory.

42. [# $] hostname à Display the Host name.

43. [# $] ls à Display list of files and directories under the working directory.

44. [# $] ls –l à Display long list of file and directories under the working directory.

45. [# $] ls –l test à Display long list of file [test] under the working directory.

46. [# $] ls –ld test or alex à Display long list of file [test] and directory [alex]
under the working directory.

47. [# $] ls –la à Display also hidden files and directories under the working directory.

48. [# $] cd / à Go to root directory.

49. [# $] cd /home à Go to home directory.

50. [# $] cd .. à Go to previous directory.

51. [# $] ./test à Run a test file from current Directory

52. [# $] ../test à Run a test file form Parent Directory.

User Add, delete and lock

All user account information is store in Home directory.

53. [#] useradd mahmud à Add the user named mahmud
[#] passwd mahmud à Create/Change password of mahmud (doesn’t need
user’s current password).
New Password:
Retype Password:

54. [$] password à Change password of logging User.
Current password:
New Password:
Retype Password:

55. [#] useradd –ou 0 alex à [o=duplicate, u =user, 0 (zero) =user id]. Give super
power when create the user alex
[#] passwd mahmud à Give password to super user alex
New Password:
Retype Password:

56. [#] userdel mahmud à Delete user mahmud without delete the directory of user
mahmud located in Home directory.

57. [#] userdel –r mahmud à Delete user mahmud with delete the directory of user
mahmud located in Home directory.

58. [#] passwd –l mahmud à Lock user mahmud

59. [#] passwd –u mahmud à Unlock user mahmud

60. [$] su - à Switch user (root)/ super user.

[#] Password: à Give password of root.
[#] exit à Exit form root and go to previous normal user.

61. [# $] su mahmud à Switch to user mahmud for login.

62. [#] chfn usernameà [Ex – chfn mahmud] Change the information of user- name,
address, phone number etc.

Create Group and User under the group

[#] groupadd aktel à Create a group named aktel
[#] useradd –g aktel mahmud à Create a user named mahmud under aktel group.

[#] useradd -g aktel -d /home/aktel mahmud à Create user under specific directory.

[#] passwd mahmud à Give password to user mahmud.

New password:
Retype password:

63. [#] vi /etc/group à Display the group list.

64. [#] gpasswd –a username groupname à [Ex- gpasswd –a mhamud aktel].
Display the user under its group in /etc/group directory.

Create File, Hidden file, Link file, Directory

65. [#$] touch abc à Create empty file, name abe under pwd.

66. [#$] touch abc xyz à Create 2 empty file, name abc and xyz under pwd.

67. [#$] touch “video song” or touch video\ song à create empty file video song.

68. [#$] touch .abc or vi .abc à Create hidden file named abc

69. [#$] mkdir Folder1 à Create folder, name Folder1 under pwd.

70. [#$] mkdir F1 F2 à Create 2 folder, name F1 and F2 under pwd.

71. [#$] mkdir “video song” or mkdir video\ song à create folder, name video song.

72. [#$] mkdir F1/F2 à Create folder F1 & F2 but F2 under F1.

73. [#$] mkdir –p F1/F2/F3 à Create folder F1, F2 & F3 but F3àF2àF1.

74. [#$] mkdir /home/sum/F1 à Create folder F1 under /home/sum directory.

Create Link file ( Shortcut in Windows)
[$#] ln –s sourcefile destinationfile
[$#] ln –s /home/Alex/abc /temp/abc à If we edit any link file then both source
and destination file will edited. If we delete source file then destination file will
be deleted. If we delete destination file then there will be no effect in source file.
[$#] ln –s /home/Alex /temp/* à Link all file form Alex directory.
[$#] ln –d /home/Alex/song /temp/song à Link directory of song folder.
[$#] unlink /temp/abc à Unlink the destination abc file.

Copy, Move, Delete, Rename file and directory

75. [#$] cp abc /temp à [cp source destination]. Copy abc file form current
directory to /temp.

76. [#$] cp /home/mahmud/abc /temp/Alex à Copy abc file from /home/mahmud
directory to /temp/Alex directory.

77. [#$] cp abc def à Copy abc to def file when abc and def are in same directory. If
def file does not exist in current directory then create a new file named def and
copy the file to it.

78. [#$] cp –r F2 F1 à Copy folder F2 in F1 when they are in same directory.

79. [#$] cp *.out /home/mahmud à Copy all .out extension file to mahmud.

80. [#$] mv /home/abc /temp/new/xyz à Move abc file from /home directory to
/temp/new directory by name xyz if xyz file is exist in destination folder
otherwise rename new.

81. [$#] mv sum /home/mahmud à Move sum folder to /home/mahmud directory.

82. [#$] mv new old à Rename file new to old in same directory.

83. [#$] rm abc à Remove abc file.

84. [#$] rm –r new à Remove folder named new

85. [#$] rm –fr new à Forcefully remove folder named new, don’t ask to delete
subdirectory of new folder.

86. [#$] rm * à Delete all file form current directory.

[#$] rm * .in à Delete all file that have .in extension from current directory.

87. Display permissions (read, write, Execute ) of a file or directory

[#] vi /home/mahmud
[#] ls –l

- rw- r- - r- – 1 mahmud aktel 26 Feb 21:39
[-] [- - -] [- - -] [- - -] 1 mahmud aktel 26 Feb 21:39

Here

[-] à Type of file d = directory/ folder.
- = ordinary file/ normal file
l = link file.

[- - -] à Owner permission
[r w x] à r = read, w = write, x = Execute

[- - -] à Group permission. User under the group.
[r w x] à r = read, w = write, x = Execute

[- - -] à Other permission. User excluded owner and its group.
[r w x] à r = read, w = write, x = Execute

r = 4
w = 2
x = 1
———-
Total 7

88. Give permission to all kind of users.

[#] chmod u+x abc à [u=owner], Give permission to the owner of the file to
execute abc file.

[#] chmod u-w abc à [u=owner], Take permission from owner to write abc file.

[#] chmod g+w xyz à [g=group], Give permission to other user of the same group
to write xyz file.

[#] chmod o+r abc à [o=other],Give permission to other user to read abc file.

[#] chmod u+rwx abc à Give permission to the owner of the file to read, write
and execute the abc file.

[#] chmod ugo+x abc à Give permission to the owner, group and other users to
execute the abc file under current working directory.

[#] chmod +x /home/mahmud/abc à Give permission to all user (owner, group,
other) to execute the abc file under /home/mahmud.

[#] chmod ugo+rwx abc or chmod +rwx abc or chmod 777 abc à Give permission
to the owner, group, other user of to read, write and execute the abc file.

89. Mount CD Room/ Writer, DVD Room/ Writer, Flash memory, HDD.

Mount CD Room/DVD Rom

ü [#] mount /media/cdrom àFedora & Enterprise
mount /media/cdrecoder
à for cd writer. User tab
mount /media/dvdrom
à for dvd rom. Use tab
mount /media/dvdrecoder
à for dvd writer. User tab
[#] cd /media/cdrom

ü [#] mount /mnt/cdrom à Red Hat
cd /mnt/cdrom

ü [#] fdisk –l à See HDD is hda or not. If HDD is hda then CD Room must
be others like hdb/hac/had
[#] mkdir /home/cddata
[#] mount /dev/hab /home/cddata
[#] cd /home/cddata
[#] ls

ü [#] umount /media/cdrom or umount /dev/hdd or umount /home/cddata

Mount Flash Drive

ü [#] mkdir /home/pendata
[#] mount /dev/sda1 /home/pendata

ü [#] umount /dev/sda1 or umount /home/pendata

Mount HDD

ü [#] fdisk –l à show windows Drive only FAT, FAT -32, NTFS
[#] mkdir /home/Ddrive
[#] mount /dev/hda5 /home/Ddrive

ü umount /dev/hda5 or umount /home/Ddrive

90. Compress and Extract file(*.tar) and folder (*.Zip)

tar - Tape of Archive.

[#] tar –cvf etc.tar /etc à [c-create, v –verbose, f – file]. Create etc.tar file of
/etc folder in current directory.

[#] tar –xvf etc.tar à [x- extract]. Untar etc.tar file to etc folder in current
working directory. And both etc.tar and tar folder are exist.

[#] gzip etc.tar à Create etc.tar.gz file form etc.tar in PWD.
[#] gunzip etc.tar.gz à Unzip etc.tar.gz file to etc.tar file in PWD

Create command

91. [#] vi /root/.bashrc à Open .bashrc file of root (Only root user can access the
command)
alias c=clear à set c for clear
alias 12=pwd
à set 12
unalias c
à diactive the command c for clear
:x !

ü Logout and Login by root user to activate the alias command.

[#] vi /home/mahmud/.bashrc à Open .bashrc file of user mahmud (Only user
mahmud can access the command).

92. [#] vi /etc/skel/.bashrc à All user can access the command.

Shell Script

(Create command; create a command using combination of some command)

93. [#] vi cdrom

#!/bin/bash
eject
à Open the cdrom
sleep 5
à Wait 5 second
eject –t
à Close cdrom
:x !

Or

[#] vi cdrom
#! /bin/bash
eject; sleep 5; eject –t

:x !

[#] bash cdrom à Execute file from current directory without execute permission
[#] bash /hom/cdrom à Execute file from current directory without execute permission
[#] ls –l à See the file is executable or not. If not executable write command.
[#] chmod +x cdrom à give executable permission to cdrom.
[#] /home/cdrom à Write the path of the file to execute it.
[#] ./cdrom à Execute file from current directory.
[#] ../cdrom à Execute file from parent directory.

Ø After move the file to /user/bin then only we writer the file name except path to
execute the file command

[#] mv cdrom /usr/bin
[#] mv cdrom /usr/bin/cdrom

Usually the location of command is
/bin
/sbin
/usr/bin
/usr/sbin
/usr/local/bin

/usr/local/sbin

94. [#$] date > a.txt à Create a file named a.txt in PWD and Copy system date to a.txt

95. [#$] cal 2 2007 > a.txt à Overwrite the calendar in a.txt.

96. [#$] cal 2 2007 >> a.txt à Append or Add calendar after the previous text.

97. [#$] date > a.txt; cal >> a.txt [not date;cal>> a.txt]

98. [#$] echo “Linux patshala” à Display Linux patshala in the screen.

99. [#$] echo 1 > a.txt à 1 is write in a.txt file.

100. Write the things in a file named a.txt and display the things in screen.

********************
System date
——————————-
Calendar of January 2008
********************

[#$] echo “***************” > a.txt
[#$] date >> a.txt
[#$] echo “———————–“ >> a.txt
[#$] cal 1 2008 >> a.txt
[#$] echo “***************” >> a.txt
[#$] cat a.txt

Software install, update and uninstall
rpm – Red Hat Package Manager (*.rpm where *.exe for windows)

101. [#$] rpm –qa à [q- query, a- all]. Display the software installed in Linux.

102. [#$] rpm –qa | grep sendmail à Display the sendmail software is installed or not.

103. [#$] rpm –qa sendmail à Display the exact sendmail software is installed or not.

104. Display how many package installed in Linux.
[#$] rpm –qa > r.txt
[#$] wc –l r.txt
or
[#$] rpm –qa | wc –l

105. [#] rpm –ivh abc.rpm à [i- install, v-verbose, h-hash (#)]. Install package

106. [#] rpm –Uvh abc.rpm à [U- upgrade]. Upgrade abc.rpm package. If abc.rpm
package is installed then upgrade it, if not install then install abc.rpm

107. [#] rpm – ivh – -nodeps abc.rpm à Install abc.rpm package without dependency
of another package. [def.rpmàxyz.rpmà abc.rpm]

108. [#] rpm -e abc.rpm à Uninstall abc.rpm package.

109. [#] rpm -e – -nodeps abc.rpm à Uninstall abc.rpm package without dependency.

110. [#$] ps –a à[p-process, s-status, a-all]. Dsplay process ID that are running in TTY

111. [#] kill -9 1960 à [9-priority (0-10) to a process, 1960- process ID]. Kill a process
which has process ID – 1960.

Schedule Task (Cron)

112. [#] crontab –l à Display list of task in schedule.

113. [#] crontab –e à Edit schedule task list.

114. [#] crontab –r à Remove all jobs from schedule task.

MH HD DM MY DW
Minute Hour Date Month Weak Command
[0-59] [0-23] [1-31] [1-12] [0-6] reboot

115. [#] vi /etc/crontab

5 * * * * reboot
à Reboot machine 5 minute of every hour.
5 9 1 12 * reboot root reboot à Reboot machine 9:05 minute of 01 December
by root user. All time are system time
5,10,15 * * * * reboot à Reboot machine 5, 10, 15 minute of every hour.
0-59/5 * * * * reboot à Reboot machine after 5 minute of every hour.
0-59/7 * * * * reboot à Reboot machine after 7 minute of every hour.
5 0-23/2 * * * reboot à Reboot machine after 2 hour & 5 minutes of every day.
:x !

116. To execute the schedule task below command should be write

[#] service crond stop
[#] service crond start
or
[#] service crond restart
or
[#] service crond reload
or
[#] /etc/init.d/crond stop
[#] /etc/init.d/crond start
or
[#] /etc/init.d/crond stop
[#] /etc/init.d/crond start


Linux

September 8, 2008

This topic cover linux documentation.