Archive for November, 2008

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!