Top Banner
LINUX PREVIEW NETWORK ADMINISTRATION NETWORK ADMINISTRATION
69

Lession1 Linux Preview

May 14, 2015

Download

Technology

leminhvuong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lession1 Linux Preview

LINUX PREVIEW

NETWORK ADMINISTRATIONNETWORK ADMINISTRATION

Page 2: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 2/18

The Virtual File System StructureThe Virtual File System Structure VFS định nghĩa tập hợp các chức năng mà mỗi một filesystem phải có. Giao tiếp này xây dựng trên tập hợp các thao tác gắn liền tới 3 đối tượng là:

1. filesystems, 2. inodes, and 3. open files.

Page 3: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 3/18

Hệ thống tập tin EXT2Hệ thống tập tin EXT2 Đơn vị cơ sở của hệ thống tập tin EXT2 là i-node. Đây là

một cấu trúc điều khiển đặc biệt hoặc nó chỉ trực tiếp tới các tới các block dữ liệu (data block) hoặc là chỉ tới một i-node khác.

Hệ thống EXT2 cho phép các i-node liên kết tối đa 3 mức, do vậy độ lớn tối đa của một tập tin là 2 GB.

I-node chỉ lưu những thông tin về những tập tin và thư mục được trong hệ thống tập tin. Nhưng chúng không lưu tên tập tin và thư mục thực sự. Mỗi tập tin tạo ra sẽ được phân bổ một inode lưu những thông tin sau: Loại tập tin và quyền hạn truy cập tập tin Người sở hữu tập tin. Kích thước của tập tin và số hard link đến tập tin. Ngày và thời gian chỉnh sửa tập tin lần cuối cùng. Vị trí nội dung tập tin trong hệ thống tập tin.

Các thư mục trong EXT2 được xem như những tập tin đặc biệt chứa những con trỏ đến các i-node của các entry.

Page 4: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 4/18

I-Node and Data block in EXT2 FSI-Node and Data block in EXT2 FS

Page 5: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 5/18

I-Node and Data block in EXT2 FSI-Node and Data block in EXT2 FS

mode inode can describe one of file, directory,

symbolic link, block device, character device or FIFO.

Owner Information The user and group identifiers of the

owners of this file or directory. This allows the file system to correctly allow the right sort of accesses,

Size The size of the file in bytes,

Page 6: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 6/18

I-Node and Data block in EXT2 FSI-Node and Data block in EXT2 FS

Timestamps The time that the inode was created and

the last time that it was modified Datablocks

Pointers to the blocks that contain the data that this inode is describing. The first twelve are pointers to the physical blocks containing the data described by this inode and the last three pointers contain more and more levels of indirection.

Page 7: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 7/18

Directories in EXT2 FSDirectories in EXT2 FS

Directories are implemented as a special type of files. Actually, a directory is a file containing a list of entries. Each entry contains an inode number and a file name.

Page 8: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 8/18

Link (Liên kết) Link (Liên kết)

tạo ra một tên tập tin thứ hai cho một tập tin. Trong Linx tồn tại hai loại liên kết: 1. Hard Link: liên kết trong cùng hệ thống tập tin với

hai inode entry tương ứng trỏ đến cùng một nội dung vật lý (cùng inode number vì chúng trỏ đến cùng dữ liệu). Hard link chỉ có thể thực hiện được nếu file đích và nguồn nằm trên cùng một phân vùng ổ đĩa. Thực tế hai files này đều chỉ tới cùng một i-node vật lý :

$ ls -il testfile14253 testfile$ ln testfile test2$ ls -il testfile test214253 testfile 14253 test2Cả hai tập tin đều có inode number giống nhau

Page 9: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 9/18

Link (Liên kết) Link (Liên kết)

2. Soft (symbolic) Link : là một liên kết khác mà không sử dụng inode entry cho việc liên kết. Chúng ta sử dụng khi file đích và nguồn không nằm trên cùng một ổ đĩa.. Tùy chọn -s của lệnh ln cho phép tạo ra một soft link. Ví dụ:$ ls -il bigfile6253 bigfile$ ln -s bigfile anotherfile$ ls -il bigfile anotherfile6253 bigfile 8358 anotherfileNhư vậy i-node number của các tập tin khác nhau. Liệt

kê một thư mục sẽ thấy soft link:lrwxrwxrwx 1 root root 6 Sep 16:35 anotherfile -> bigfile-rw-rw-r-- 1 root root 2 Sep 17:23 bigfile

Page 10: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 10/18

Hard Link – Symbolic LinkHard Link – Symbolic LinkKhông có sự khác biệt giữa original file và hardlink file. Để xác định chỉ số i-node để xem 2 files có hardlink với nhau hay không phải dùng ls –li

ln abc habcln –s abc sabcls –i abc habc sabc12345 abc 12345 habc 12345 sabc

ls –il abc habc sabc12345 ….. abc12345 ….. habc23410 ….. sabc -> abc

Mọi sự thay đổi quyền hạn và chủ nhân trên original file đều dẫn đến thay đổi trên các hardlinks và ngược lại nhưng không ảnh hưởng đến symbolic links

Quyền hạn thể hiện (ls –l) trên symbolic link không bao giờ thay đổi và luôn là lrwxrwxrwx. Khi thay đổi quyền hạn trên symbolic link thì quyền hạn sẽ thây đổi trên original file (tất nhiên sẽ thay đổi trên tất cả hardlinks).

Chủ nhân symbolic link và original file là khác nhau

Page 11: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 11/18

PermissionsPermissions

- (rw-) (rw-) (r--) 1 sam sam | | | |Type owner group others

The first item, which specifies the file type, can show one of the following: d : a directory - (dash) : a regular file (rather than directory or link) l : a symbolic link to another program or file

Beyond the first item, in each of the following three sets, you will see one of the following: r : file can be read w : file can be written to x : file can be executed (if it is a program)

Page 12: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 12/18

Using File System Commands chmodchmod

chmod has two methods of changing filename permissions:

1. One way is the numeric method, which sets the user, group and world permissions at once.

2. The other way to specify chmod permissions is the character flag method, which changes only the attributes you specify.

Page 13: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 13/18

Chmod : Using a flag methodChmod : Using a flag method Identities

u the user who owns the file (that is, the owner) g the group to which the user belongs o others (not the owner or the owner's group) a everyone or all (u, g, and o)

Permissionsr read access w write access x execute access

Actions+ adds the permission - removes the permission = makes it the only permission

Page 14: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 14/18

Chmod : Using a flag methodChmod : Using a flag method chmod u+rw sneakers.txt Here are some common examples of settings

that can be used with chmod: g+w — adds write access for the group o-rwx — removes all permissions for others u+x — allows the file owner to execute the file a+rw — allows everyone to read and write to the

file ug+r — allows the owner and group to read the

file g=rx — allows only the group to read and execute

(not write) By adding the -R option, you can change

permissions for entire directory trees.

Page 15: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 15/18

Changing Permissions With Changing Permissions With NumbersNumbers

Each permission setting can be represented by a numerical value: r = 4 w = 2 x = 1 - = 0

For sneakers.txt, here are the numerical permissions settings:

- ( r w - ) ( r w - ) ( r - - ) | | | 4+2+0 4+2+0 4+0+0

Page 16: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 16/18

Changing Permissions With Changing Permissions With NumbersNumbers

The total for the user is six, the total for the group is six, and the total for others is four. The permissions setting is read as 664.

To implement these new settings, type: chmod 644 sneakers.txt

Page 17: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 17/18

Changing Permissions With Changing Permissions With NumbersNumbers

-rw------- (600) Only the owner has read and write permissions. -rw-r--r-- (644) Only the owner has read and write permissions;

the group and others have read only. -rwx------ (700) Only the owner has read, write, and execute

permissions. -rwxr-xr-x (755) The owner has read, write, and execute

permissions; the group and others have only read and execute.

-rwx--x--x (711) The owner has read, write, and execute permissions; the group and others have only execute.

-rw-rw-rw- (666) Everyone can read and write to the file. (Be careful with these permissions.)

-rwxrwxrwx (777) Everyone can read, write, and execute. (Again, this permissions setting can be hazardous.)

Here are some common settings for directories: drwx------ (700) Only the user can read, write in this directory. drwxr-xr-x (755) Everyone can read the directory; users and

groups have read and execute permissions.

Page 18: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 18/18

Khi User tạo ra file hoặc folder mới, thì bao giờ file hoặc folder mới này cũng có một quyền hạn mặc định nào đó

Lệnh umask : Quyền hạn mặc địnhLệnh umask : Quyền hạn mặc định

ví dụ : file.txt có quyền hạn mặc định là 664 ; folder là 775

Page 19: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 19/18

Lệnh umask : Quyền hạn mặc địnhLệnh umask : Quyền hạn mặc định Để tính quyền hạn mặc định này Linux sử dụng

phương pháp sau:quyền hạn mặc định của file = 666 – umaskquyền hạn mặc định của folder = 777 – umaskumask là biến mà chúng ta có thể hiệu chỉnh umask : hiển thị giá trị umask umask newNumber : umask = newNumbervd:

umask 666 touch file

File sẽ có quyền 000.

Page 20: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 20/18

Sticky bitSticky bit

Khi UserA có quyền Write đối với một folder thì UserA đó có thể xóa bất kỳ một file hoặc subfolder nào ngay cả khi UserA không phải là chủ nhân và cũng không có quyền hạn gì đối với file và subfolder nói trên.

Để xem thuộc tính của folder hãy dùng ls -ld

Ví dụ. /tmp/ có thuộc tính dwrxwrxwrx

Page 21: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 21/18

Sticky bitSticky bit

Mặc dù User sv không có quyền gì đối với file root.txt , nhưng sv có thể xóa root.txt.

Để UserA không thể xóa files của UserB trong folder mà tất cả Users đều có quyền Write chúng ta hãy sử dụng Sticky Bits: chmod +t folder.

Page 22: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 22/18

The Root DirectoryThe Root Directory the following directories, or symbolic links to

directories, are required in / :/bin Essential command binaries /boot Static files of the boot loader /dev Device files /etc Host-specific system configuration /lib Essential shared libraries and kernel

modules /mnt Mount point for mounting a filesystem temporarily /sbin Essential system binaries /tmp Temporary files /usr Secondary hierarchy /var Variable data

Page 23: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 23/18

Running Programs at Boot TimeRunning Programs at Boot Time The /etc/rc.d/rc.local script is executed by the

init command at boot time or when changing runlevels. Adding commands to this script is an easy way to perform necessary tasks like starting special services or initialize devices without writing complex initialization scripts in the /etc/rc.d/init.d/ directory and creating symbolic links.

The /etc/rc.serial script is used if serial ports must be setup at boot time. This script runs setserial commands to configure the system's serial ports.

Page 24: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 24/18

Users and GroupsUsers and Groups Control of users and groups is a core element of

Red Hat Linux system administration. Users can be either people, meaning accounts tied

to physical users, or accounts which exist for specific applications to use.

Groups are logical expressions of organization, tying users together for a common purpose. Users within the same group can read, write, or execute files owned by the group.

Each user and group have a unique numerical identification number called a userid (UID) and a groupid (GID) respectively.

A good system administrator must first understand what user accounts and groups are and how they work.

Page 25: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 25/18

User and Group Management User and Group Management ToolsTools

The following command line tools can also be used to manage users and groups: useradd, usermod, and userdel — Industry-

standard methods of adding, deleting and modifying user accounts.

groupadd, groupmod, and groupdel — Industry-standard methods of adding, deleting, and modifying user groups.

gpasswd — Industry-standard method of administering the /etc/group file.

Page 26: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 26/18

/etc/group

Page 27: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 27/18

Adding a UserAdding a User

To add a user to the system:1. Issue the useradd command to create a

locked user account:useradd [options] <username>

2. Unlock the account by issuing the passwd command to assign a password and set password aging guidelines:passwd <username>

Page 28: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 28/18

The command line options for The command line options for useradd useradd

-c comment Comment for the user -d home-dir Home directory to be used

instead of default /home/username -e date Date for the account to be

disabled in the format YYYY-MM-DD -f days Number of days after the

password expires until the account is disabled. (If 0 is specified, the account is disabled immediately after the password expires. If -1 is specified, the account will not be disabled after the password expires.)

-g group-name Group name or group number for the user's default group (The group must exist prior to being specified here.)

Page 29: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 29/18

The command line options for The command line options for useradd useradd

-m Create the home directory if it does not exist.

-M Do not create the home directory. -n Do not create a user private group for

the user. -r Create a system account with a UID

less than 500 and without a home directory. -p password The password encrypted with

crypt. -s User's login shell, which defaults to

/bin/bash. -u uid User ID for the user, which must be

unique and greater than 499, unless the -o option is used. Values between 0 and 99 are typically reserved for system accounts.

Page 30: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 30/18

Delete a user account - userdelDelete a user account - userdel

userdel [-r] user_name The userdel command modifies the

system account files, deleting all entries that refer to login. The named user must exist. The options which apply to the userdel command are:

-r Files in the user’s home directory will be removed along with the home

directory itself and the user’s mail spool. Files located in other file systems will have to be searched for and deleted manually.

Page 31: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 31/18

Modify a user account - usermodModify a user account - usermod usermod [option] user_name -c comment The new value of the user’s password

file comment field. It is normally modified using the chfn(1) utility.

-d home_dir The user’s new login directory. If the -

m option is given the contents of the current home directory will be moved to the new home directory, which is created if it does not already exist.

-e expire_date The date on which the user account will

be disabled. The date is specified in the format YYYY-MM-DD.

Page 32: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 32/18

Modify a user account - usermodModify a user account - usermod -g initial_group

The group name or number of the user’s new initial login group.The group name must exist. A group number must refer to an already existing group. The default group number is 1.

-p passwdThe encrypted password, as returned by crypt(3).

-u uid The numerical value of the user’s ID. This value must be unique, unless the -o option is used. The value must be non-negative. Values between 0 and 99 are typically reserved for system accounts. Any files which the user owns and which are located in the directory tree rooted at the user’s home directory will have the file user ID changed automatically. Files outside of the user’s home directory must be altered manually.

Page 33: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 33/18

Modify a user account - usermodModify a user account - usermod

-L Lock a user’s password. This puts a ’!’ in

front of the encrypted password, effectively disabling the password. You can’t use this option with -p or -U.

-U Unlock a user’s password. This removes the ’!’

in front of the encrypted password. You can’t use this option with -p or -L.

Page 34: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 34/18

change Command Line Options change Command Line Options Lock the user's password — If the user does not

exist, use the useradd command to create the user account, but do not give it a password so that it remains locked. If the password is already enabled, lock it with the command:

usermod -L username Force immediate password expiration — Type the

following command: change -d 0 username This command sets the value for the date the

password was last changed to the epoch (January 1, 1970). This value forces immediate password expiration. It means that the user must to set a password the first time the user log in.

Note, this process does not work if the user logs in using the SSH protocol.

Page 35: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 35/18

Adding a GroupAdding a Group groupadd [options] <group-name> -g gid Group ID for the group, which

must be unique and greater than 499, unless the -o option is used.-r Create a system group with a GID less than 500.-f Exit with an error if the group already exists. If -g and -f are specified, but the group already exists, the -g option is ignored.

Page 36: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 36/18

User Private GroupsUser Private Groups Red Hat Linux uses a user private group (UPG)

scheme, which makes UNIX groups easier to manage.

A UPG is created whenever a new user is added to the system. A UPG has the same name as the user for which it was created and that user is the only member of the UPG.

UPGs makes it is safe to set default permissions for a newly created file or directory which allow both the user and that user's group to make modifications to the file or directory.

The setting which determines what permissions are applied to a newly created file or directory is called a umask and is configured in the /etc/bashrc file. Traditionally, on UNIX systems the umask is set to 022, which allows only the user who created the file or directory to make modifications.

Page 37: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 37/18

Group DirectoriesGroup Directories a group of people work on files in the /var/IT

directory. Some people are trusted to modify the directory but certainly not everyone. So first create an emacs group, as in the following command:

groupadd it_group In order to associate the contents of the

directory with the emacs group, type: chown -R root.it_group /var/IT Now, it is possible to add the proper users to

the group with the gpasswd command: gpasswd -a <username> it_group Allow the users to actually create files in the

directory with the following command: chmod 775 /var/IT

Page 38: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 38/18

/etc/passwd/etc/passwd The /etc/passwd file is world-readable and contains a

list of users, each on a separate line. On each line is a colon delimited list containing the following information:

Username — The name the user types when logging into the system.

Password — Contains the encrypted password (or an x if shadow passwords are being used — more on this later).

User ID (UID) — The numerical equivalent of the username which is referenced by the system and applications when determining access privileges.

Group ID (GID) — The numerical equivalent of the primary group name which is referenced by the system and applications when determining access privileges.

Page 39: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 39/18

/etc/passwd/etc/passwd Home directory — The absolute path to the user's

home directory, such as /home/juan/. Shell — The program automatically launched

whenever a user logs in. This is usually a command interpreter (often called a shell). Under Red Hat Linux, the default value is /bin/bash. If this field is left blank, /bin/sh is used. If it is set to a non-existent file, then the user will be unable to log into the system.

Here is an example of a /etc/passwd entry: root:x:0:0:root:/root:/bin/bash This line shows that the root user has a shadow

password, as well as a UID and GID of 0. The root user has /root/ as a home directory, and uses /bin/bash for a shell.

Page 40: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 40/18

/etc/shadow/etc/shadow Because the /etc/passwd file must be world-readable

(the main reason being that this file is used to perform the translation from UID to username), there is a risk involved in storing everyone's password in /etc/passwd.

Therefore, the /etc/shadow file is readable only by the root user and contains password (and optional password aging information) for each user. As in the /etc/passwd file, each user's information is on a separate line. Each of these lines is a colon delimited list including the following information: Username — The name the user types when logging

into the system. This allows the login application to retrieve the user's password (and related information).

Page 41: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 41/18

/etc/shadow/etc/shadow Encrypted password — The 13 to 24 character

password. The password is encrypted using either the crypt(3) library function or the md5 hash algorithm. In this field, values other than a validly-formatted encrypted or hashed password are used to control user logins and to show the password status. For example, if the value is ! or *, the account is locked and the user is not allowed to log in. If the value is !! a password has never been set before (and the user, not having set a password, will not be able to log in).

Date password last changed — The number of days since January 1, 1970 (also called the epoch) that the password was last changed. This information is used in conjunction with the password aging fields that follow.

Number of days before password can be changed — The minimum number of days that must pass before the password can be changed.

Page 42: Lession1 Linux Preview

Linux NetworkingLinux Networking

Page 43: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 43/18

Determining Your IP Address Determining Your IP Address You can determine the IP address of this device with the "ifconfig" command.

[root@bigboy tmp]# ifconfig   eth0 Link encap:Ethernet HWaddr 00:A0:CC:60:B7:G4 inet addr:192.168.100.5 Bcast:192.168.100.255

Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:161930 errors:1 dropped:0 overruns:0

frame:0 TX packets:244570 errors:0 dropped:0 overruns:0

carrier:0 collisions:475 txqueuelen:100 RX bytes:55075551 (52.5 Mb) TX bytes:178108895 (169.8

Mb) Interrupt:10 Base address:0x9000

Page 44: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 44/18

Changing Your IP AddressChanging Your IP Address If you wanted, you could give this eth0 interface an

IP address using the ifconfig command. [root@bigboy tmp]# ifconfig eth0 10.0.0.1 netmask

255.255.255.0 up 

The "up" at the end of the command activates the interface. To make this permanent each time you boot up you'll have to add this command in your /etc/rc.d/rc.local file.

Linux also makes life a little easier with interface configuration files located in the /etc/sysconfig/network-scripts directory. Interface eth0 has a file called ifcfg-eth0, eth1 uses ifcfg-eth1 ... etc. You can place your IP address information in these files which are then used to auto-configure your NICs when Linux boots.

Page 45: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 45/18

Interface Configuration Files Interface Configuration Files Interface configuration files control the software interfaces for individual network devices. As the system boots, it uses these files to determine what interfaces to bring up and how to configure them. These files are usually named ifcfg-<name>, where <name> refers to the name of the device that the configuration file controls.

One of the most common interface files is ifcfg-eth0, which controls the first Ethernet network interface card or NIC in the system. In a system with multiple NICs, there are multiple ifcfg-eth<X> files (where <X> is a unique number corresponding to a specific interface). Because each device has its own configuration file, an administrator can control how each interface functions individually.

Page 46: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 46/18

Example configuration fileExample configuration fileBelow is a sample ifcfg-eth0 file for a system using a fixed IP address:

DEVICE=eth0 BOOTPROTO=none ONBOOT=yes NETWORK=10.0.1.0 NETMASK=255.255.255.0 IPADDR=10.0.1.27 USERCTL=no

For example, the ifcfg-eth0 file for an interface using DHCP looks quite a bit different, because IP information is provided by the DHCP server:

DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes

Page 47: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 47/18

the configurable parameters in an the configurable parameters in an Ethernet interface configuration fileEthernet interface configuration file

BOOTPROTO=<protocol>, where <protocol> is one of the following: none — No boot-time protocol should be used. bootp — The BOOTP protocol should be used. dhcp — The DHCP protocol should be used.

BROADCAST=<address>, where <address> is the broadcast address. This directive is deprecated.

DEVICE=<name>, where <name> is the name of the physical device (except for dynamically-allocated PPP devices where it is the logical name).

DNS{1,2}=<address>, where <address> is a name server address to be placed in /etc/resolv.conf if the PEERDNS directive is set to yes.

Page 48: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 48/18

the configurable parameters in an the configurable parameters in an Ethernet interface configuration fileEthernet interface configuration file

IPADDR=<address>, where <address> is the IP address. NETMASK=<mask>, where <mask> is the netmask

value. NETWORK=<address>, where <address> is the network

address. This directive is deprecated. ONBOOT=<answer>, where <answer> is one of the

following: yes — This device should be activated at boot-time. no — This device should not be activated at boot-time.

USERCTL=<answer>, where <answer> is one of the following: yes — Non-root users are allowed to control this device. no — Non-root users are not allowed to control this

device.

Page 49: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 49/18

Interface Control Scripts Interface Control Scripts The interface control scripts activate and deactivated system interfaces. There are two primary interface control scripts, /sbin/ifdown and /sbin/ifup, that call on control scripts located in the /etc/sysconfig/network-scripts/ directory.

The ifdown and ifup interface scripts are symbolic links to scripts in the /sbin/ directory. When either of these scripts are called, they require the value of the interface to be specified, such as:

[root@bigboy network-scripts]# ifup eth0 Determining IP information for eth0... done.

The easiest way to manipulate all network scripts simultaneously is to use the /sbin/service command on the network service (/etc/rc.d/init.d/network), as illustrated the following command:

# /etc/rc.d/init.d/network <action> <action> can be either start, stop, restart, or status.

Page 50: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 50/18

How To Change Your Default How To Change Your Default Gateway Gateway

This can be done with a simple command. This example uses the standard ethernet interface eth0.

[root@bigboy tmp]# route add default gw 192.168.1.1 eth0

In this case, make sure that the router / firewall with IP address 192.168.1.1 is connected to the same network as interface eth0 !

Once done, you'll need to update your /etc/sysconfig/network file to reflect the change. This file is used to configure your default gateway each time Linux boots.

NETWORKING=yesHOSTNAME=bigboyGATEWAY=192.168.1.1

Some people don't bother with this step and just place the "route add" command in the file /etc/rc.d/rc.local

Page 51: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 51/18

/etc/sysconfig/network /etc/sysconfig/network The /etc/sysconfig/network file is used to specify information about the desired network configuration. The following values may be used:

NETWORKING=<value>, where <value> is one of the following boolean values:

yes — Networking should be configured. no — Networking should not be configured.

HOSTNAME=<value>, where <value> should be the Fully Qualified Domain Name (FQDN), such as hostname.expample.com, but can be whatever hostname is necessary.

GATEWAY=<value>, where <value> is the IP address of the network's gateway.

GATEWAYDEV=<value>, where <value> is the gateway device, such as eth0.

NISDOMAIN=<value>, where <value> is the NIS domain name.

Page 52: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 52/18

To Change The Duplex Setting Of Your To Change The Duplex Setting Of Your NICNIC

A Ethernet NICs built into motherboards (onboard NICs) frequently don't negotiate port speed and duplex correctly.

You can manage the duplex and speed settings of your NIC with the mii-tool command. It is best to use this command with compatible hardware.

In the example below, we can see the output of the command verbose "-v" mode. In this case, negotiation was OK, with the NIC selecting 100Mbps, full duplex mode (FD).

[root@bigboy tmp]# mii-tool –veth1: negotiated 100baseTx-FD, link ok product info: vendor 00:10:18, model 33 rev 2 basic mode:   autonegotiation enabled basic status: autonegotiation complete, link ok capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD advertising:  100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control

Page 53: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 53/18

To Change The Duplex Setting Of Your To Change The Duplex Setting Of Your NICNIC

You can set your NIC to force itself to a particular speed and duplex by using the "-F" switch with any of the following options: 100baseTx-FD, 100baseTx-HD, 10baseT-FD, or 10baseT-HD. Remember that you could lose all network connectivity to your server if you force your NIC to a particular speed/duplex that doesn't match that of your switch!!!.

[root@bigboy tmp]# mii-tool -F 100baseTx-FD eth0 I have seen where NICs appear to work with failed

negotiation, but this is usually accompanied by many "collision" type errors being seen on the NIC when using the ifconfig -a command and only marginal performance. The causes for this could include an incompatible NIC, incorrect settings on your switch port or a bad cable.

Page 54: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 54/18

Configuring Your /etc/hosts FileConfiguring Your /etc/hosts FileThe /etc/hosts file is just a list of IP addresses and their corresponding server names. Your server will typically check this file before referencing DNS, if the name is found with a corresponding IP address then DNS won't be queried at all.

192.168.1.101  smallfry In the example above server "smallfry" has an IP address of 192.168.1.101. You can access 192.168.1.101 using the "ping", "telnet" or any other network aware program by referring to it as "smallfry" Here is an example using the "ping" to see if "smallfry" is alive and well on the network.

[root@bigboy tmp]# ping smallfryPING zero (192.168.1.101) 56(84) bytes of data.64 bytes from smallfry (192.168.1.101): icmp_seq=0 ttl=64 time=0.197 ms64 bytes from smallfry (192.168.1.101): icmp_seq=1 ttl=64 time=0.047 ms

Page 55: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 55/18

Configuring Your /etc/hosts FileConfiguring Your /etc/hosts FileYou can also add "aliases" to the end of the line which will allow you to refer to the server using other names. Here we have set it up so that "smallfry" can also be accessed using the names "tiny" and "littleguy".

192.168.1.101  smallfry  tiny  littleguy You should never have an IP address more than once in this file as Linux will only use the values in the first entry it finds.

  192.168.1.101  smallfry    # (Wrong) 192.168.1.101  tiny        # (Wrong) 192.168.1.101  littleguy   # (Wrong)

Page 56: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 56/18

The Loopback Interface's Localhost The Loopback Interface's Localhost EntryEntry

Usually the very first entry in /etc/hosts defines the IP address of the server's virtual loopback interface. This is usually mapped to the name localhost.localdomain (the universal name used when a server refers to itself) and localhost (the shortened "alias" name). By default, System inserts the hostname of the server between the 127.0.0.1 and the localhost entries like this:

127.0.0.1     bigboy    localhost.localdomain    localhost When the server is connected to the Internet this first entry after

the 127.0.0.1 needs to be the fully qualified domain name (FQDN) of the server. For example, bigboy.mysite.com, like this: 

127.0.0.1  bigboy.my-site.com    localhost.localdomain    localhost Some programs such as Sendmail are very sensitive to this and if

they detect what they feel is an incorrect FQDN they will default to using the name "localhost.localdomain" when communicating with another server on the network. This can cause confusion, as the other server also feels it is "localhost.localdomain".

Note: You MUST always have a localhost and localhost.localdomain entry mapping to 127.0.0.1 for Linux to work properly.

Page 57: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 57/18

GUI Network ConfigurationGUI Network Configuration GUI : Start Menu => System Settings => Network or Shell: # redhat-config-network

Page 58: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 58/18

Overview Overview To configure a network connection with the

Network Administration Tool, perform the following steps:

1. Add the physical hardware device to the hardware list.

2. Add a network device associated with the physical hardware device.

3. Configure the hostname and DNS settings.4. Configure any hosts that cannot be looked up

through DNS.

Page 59: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 59/18

Establishing an Ethernet Establishing an Ethernet Connection Connection

To add an Ethernet connection, follow these steps: 1. Click the Devices tab.2. Click the New button on the toolbar.3. Select Ethernet connection from the Device Type list,

and click Forward.4. If you have already added the network interface card

to the hardware list, select it from the Ethernet card list. Otherwise, select Other Ethernet Card to add the hardware device.

5. If you selected Other Ethernet Card, the Select Ethernet Adapter window appears. Select the manufacturer and model of the Ethernet card. Select the device name. If this is the system's first Ethernet card, select eth0 as the device name; if this is the second Ethernet card, select eth1 (and so on). The Network Administration Tool also allows you to configure the resources for the NIC. Click Forward to continue.

Page 60: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 60/18

Establishing an Ethernet Establishing an Ethernet ConnectionConnection

6. In the Configure Network Settings window, choose between DHCP and a static IP address. If the device receives a different IP address each time the network is started, do not specify a hostname. Click Forward to continue.

7. Click Apply on the Create Ethernet Device page.

Page 61: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 61/18

Establishing an Ethernet Establishing an Ethernet ConnectionConnection

After configuring the Ethernet device, it appears in the device list as shown in bellow Figure

Page 62: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 62/18

Establishing an Ethernet Establishing an Ethernet ConnectionConnection

Be sure to select File => Save to save the changes. After adding the Ethernet device, you can edit its configuration by selecting the device from the device list and clicking Edit. For example, when the device is added, it is configured to start at boot time by default. To change this setting, select to edit the device, modify the Activate device when computer starts value, and save the changes.

When the device is added, it is not activated immediately, as seen by its Inactive status. To activate the device, select it from the device list, and click the Activate button. If the system is configured to activate the device when the computer starts (the default), this step does not have to be performed again.

If you associate more than one device with an Ethernet card, the subsequent devices are device aliases. A device alias allows you to setup multiple virtual devices for one physical device, thus giving the one physical device more than one IP address. For example, you can configure an eth1 device and an eth1:1 device.

Page 63: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 63/18

Managing DNS Settings Managing DNS Settings

Page 64: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 64/18

Managing Hosts Managing Hosts

Page 65: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 65/18

Managing HostsManaging HostsTo add an entry to the /etc/hosts file, go to the Hosts tab, click the New button on the toolbar, provide the requested information, and click OK. Select File => Save or press [Ctrl]-[S] to save the changes to the /etc/hosts file. The network or network services do not need to be restarted since the current version of the file is referred to each time an address is resolved.

To change lookup order, edit the /etc/host.conf file. The line order hosts, bind specifies that the /etc/hosts takes precedence over the name servers. Changing the line to order bind, hosts configures the system to resolve hostnames and IP addresses using the name servers first. If the IP address cannot be resolved through the name servers, the system then looks for the IP address in the /etc/hosts file.

Page 66: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 66/18

Activating Devices Activating Devices Network devices can be configured to be active or

inactive at boot time. For example, a network device for a modem connection is usually not configured to start at boot time; whereas, an Ethernet connection is usually configured to activate at boot time. If your network device is configured not to start at boot time, you can use the Red Hat Control Network program to activate it after boot time. To start it, select Main Menu Button (on the Panel) => System Tools => Network Device Control or type the command redhat-control-network.

To activate a device, select it from the list and click the Activate button. To stop the device, select it from the list and click Deactivate.

Page 67: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 67/18

Activating DevicesActivating Devices

Page 68: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 68/18

Device Aliases Device Aliases Device aliases are virtual devices associated with the same physical hardware, but they can be activated at the same time to have different IP addresses. They are commonly represented as the device name followed by a colon and a number (for example, eth0:1).

After configuring the Ethernet device, such as eth0, to use a static IP address (DHCP does not work with aliases), go to the Devices tab and click New. Select the Ethernet card to configure with an alias, set the static IP address for the alias, and click Apply to create it. Since a device already exists for the Ethernet card, the one just created is the alias such as eth0:1.

To modify the settings for the device alias such as whether to activate it at boot time and the alias number, select it from the list and click the Edit button.

Select the alias and click the Activate button to activate the alias. If you have configured multiple profiles, select which profiles in which to include it.

Page 69: Lession1 Linux Preview

Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 69/18

Activating DevicesActivating Devices

To verify that the alias has been activated, use the command ifconfig. The output should show the device and the device alias with different IP address