Giáo trình Hệ thống mạng Linux - Nguyễn Tấn Khôi

Tóm tắt Giáo trình Hệ thống mạng Linux - Nguyễn Tấn Khôi: ...ch các ti?n trình ?ang ho?t ??ng trên h? th?ng. [user12@linux user12]$ ps PID TTY STAT TIME COMMAND - 12- 4516 p4 S 0:00 -bash 4703 p4 S 0:00 /usr/bin/mc -P 4705 r0 S 0:00 bash -rcfile .bashrc 4727 r0 R 0:00 ps [user12@linux user12]$ kill 4703 //H?y b? ti?n trình mc có s? hi?u 4703 Termina...100 6.2. Ch??ng trình tính giai th?a c?a m?t s? - Minh h?a các c?u trúc while do done, và cách s? d?ng [], $(()). - T?p tin giaithua.sh #!/bin/sh echo ?Chuong trinh tinh $1!? index=0 gt=1 while [ $index -lt $1 ] do index=$(($index + 1)) gt=$(($gt * $index)) done echo "$1!= $gt" exit ... ta ?ã dùng hàm read() và write() ?? vi?t (truy?n) và ??c (nh?n) trên ?ng d?n. 8.2.3. Liên l?c gi?a ti?n trình cha và ti?n trình con Trong ví d? d??i ?ây, m?t ti?n trình t?o ra m?t ?ng d?n, t?o ra m?t ti?n trình con, vi?t m?t v?n b?n vào ?ng d?n.Ti?n trình con th?a h??ng ?ng d?n và các ký hi?u ...

pdf47 trang | Chia sẻ: havih72 | Lượt xem: 246 | Lượt tải: 0download
Nội dung tài liệu Giáo trình Hệ thống mạng Linux - Nguyễn Tấn Khôi, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
h? mang tính ch?t t?m th?i, ch? t?n t?i trong th?i gian th?c hi?n c?a
??t ti?n trình t?o ra nó.
- Mu?n t?o ra m?t ?ng d?n ph?i b?t ??u b?ng m?t l?nh ??c bi?t: pipe().
- Nhi?u ti?n trình có th? vi?t và ??c trên cùng m?t ?ng d?n. Tuy nhiên, không có m?t
?? ch? nào ?? phân bi?t thông tin cho các ti?n trình ????u ra.
- Dung l??ng ?ng d?n b? h?n ch? (kho?ng 4KB). Do ?ó khi chúng ta c? g?ng vi?t khi
?ng d?n b????y thì s? g?p ph?i tr??ng h?p t?c ngh?n.
- 31-
- Các ti?n trình liên l?c qua ?ng d?n ph?i có m?i quan h? h? hàng và các ?ng d?n n?i
ph?i ???c m? tr??c khi t?o ra các ti?n trình con.
- Không th? t? thay ??i v? trí thông tin trong ?ng.
8.2.2. Thao tác v?i "?ng d?n liên l?c"
??o m?t ?ng d?n:
int p_desc[2];
int pipe(p_desc);
Giá tr? tr? v? là 0 n?u thành công, -1 n?u th?t b?i.
p_desc[0] : ch?a các s? hi?u mô t? nh???ó có th????c trong ?ng d?n.
p_desc[1] : ch?a các s? hi?u mô t? nh???ó có th? vi?t trong ?ng d?n.
Nh? v?y vi?c vi?t trong p_desc[1] là ?? truy?n d? li?u trong ?ng và vi?c ??c trong
p_desc[0] ?? nh?n chúng.
Ví d?:
#include 
#include 
main()
{
int i,ret, p_desc[2];
char c;
pipe(p_desc);
write(p_desc[1], "AB", 2);
for (i=1; i<=3,i ++) {
 ret=read(p_desc[0], &c, 1);
 if (ret == 1)
 printf(" Gia tri: %c\n",c);
 else
 perror("Loi ong dan rong");
 }
}
Ví d? trên ch? ra r?ng ta có th? truy?n và nh?n thông tin trên ?ng d?n. Chúng ta ?ã
dùng hàm read() và write() ?? vi?t (truy?n) và ??c (nh?n) trên ?ng d?n.
8.2.3. Liên l?c gi?a ti?n trình cha và ti?n trình con
Trong ví d? d??i ?ây, m?t ti?n trình t?o ra m?t ?ng d?n, t?o ra m?t ti?n trình
con, vi?t m?t v?n b?n vào ?ng d?n.Ti?n trình con th?a h??ng ?ng d?n và các ký hi?u
mô t? c?a ?ng d?n, th?c hi?n ??c trong ?ng d?n:
#include 
#include 
void code_fils(int number) {
 int fd, nread;
char texte[100];
- 32-
fd=number;
printf(" So hieu mo ta la %d\n",fd);
switch (nread=read(fd, texte, sizeof(texte)))
{
case -1:
 perror("Loi doc.");
case 0:
 perror("EOF");
default:
 printf("Van ban nhan duoc co %d ky tu: %s\n",fd, texte);
}
}
main() {
int fd[2];
char chaine[10];
if (pipe(fd)==-1)
 { perror("Loi khoi tao pipe.");
 exit(1);
}
switch (fork()) {
case -1:
 perror(" Loi khoi tao tien trinh.");
 break;
case 0:
 if (close(fd[1])==-1)
 perror(" Error.");
 code_fils(fd[0]);
 exit(0);
}
close(fd[0]);
if (write(fd[1]),"hello",6)==-1)
 perror("Loi truyen.");
}
??t qu? ch??ng trình:
So hieu mo ta la: 5
Van ban nhan duoc co 6 ky tu: hello
Chú ý r?ng, ti?n trình con ??c trong ?ng d?n mà không vi?t ???ó nên nó b?t ??u
??ng cách ?óng ph?n vi?t fd[1] ?? ti?t ki?m các tín hi?u mô t? c?a t? h?p. T??ng t?, vì
ti?n trình cha ch? s? d?ng ph?n vi?t nên nó ?óng ph?n ??c l?i (fd[0]). Sau ?ó ti?n trình
cha vi?t vào ?ng d?n 6 ký t? và ti?n trình con ?ã ??c chúng.
Bài 9 ??p trình m?ng TCP/IP
9.1. L?p trình client /server theo giao th?c TCP/IP
· Ch??ng trình tcpClient.c
/* Chuong trinh tcpClient.c */
- 33-
/* Khai báo các file th? vi?n c?n thi?t ?? g?i hàm socket*/
#include 
#include 
#include /*gethostbyname*/
#include 
#include 
#include 
#include /* close */
#define SERVER_PORT 1500
#define MAX_MSG 100
int main (int argc, char *argv[]) {
/* Kh?i t?o các bi?n dùng trong ch??ng trình */
 int sd, rc, i;
 struct sockaddr_in localAddr, servAddr;
 struct hostent *h;
 if(argc < 3) {
 printf("usage: %s ... \n",argv[0]);
 exit(1);
 }
 /* Hàm gethostbyname() l?y v????a ch? IP theo tên nh?p vào trong t?p tin /etc/hosts */
 h = gethostbyname(argv[1]);
 if(h==NULL) {
 printf("%s: unknown host '%s'\n",argv[0],argv[1]);
 exit(1);
 }
 servAddr.sin_family = h->h_addrtype;
 memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
 servAddr.sin_port = htons(SERVER_PORT);
 /* Gán các giá tr? cho ??i t??ng socket.
 T?o socket cho máy Client. L?u l?i s? mô t? socket */
 sd = socket(AF_INET, SOCK_STREAM, 0);
 if(sd<0) {
 perror("cannot open socket ");
 exit(1);
 }
 /* ??t tên socket cho ch??ng trình Client
 Gán ??a ch? k?t n?i cho socket theo giao th?c Internet */
 localAddr.sin_family = AF_INET;
 localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
 localAddr.sin_port = htons(0);
 /* Hàm htons() dùng ?? chuy?n ??i tr?t t? byte c?a s? nguyên tr??c khi g?i ?i ? do h?
 th?ng s? d?ng c? ch? giao ti?p TCP/IP */
/* Ràng bu?c tên v?i socket */
- 34-
 rc = bind(sd, (struct sockaddr *) &localAddr, sizeof(localAddr));
 if(rc<0) {
 printf("%s: cannot bind port TCP %u\n",argv[0],SERVER_PORT);
 perror("error ");
 exit(1);
 }
 /* Th?c hi?n k?t n?i ??n server theo tên/??a ch? nh?p vào t? dòng l?nh */
 rc = connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));
 if(rc<0) {
 perror("cannot connect ");
 exit(1);
 }
 /* Sau khi socket ?ã k?t n?i, th?c hi?n g?i các d? li?u ??n ch??ng trình Server */
 for(i=2;i<argc;i++) {
 rc = send(sd, argv[i], strlen(argv[i]) + 1, 0);
 if(rc<0) {
 perror("cannot send data ");
 close(sd);
 exit(1);
 }/* if */
 printf("%s: data%u sent (%s)\n",argv[0],i-1,argv[i]);
 }/* for */
return 0;
}/*main*/
· Ch??ng trình tcpServer.c
/* Chuong trinh tcpServer.c */
/* Khai báo các file th? vi?n c?n thi?t ?? g?i hàm socket*/
#include 
#include 
#include 
#include 
#include 
#include 
#include /* close */
#define SUCCESS 0
#define ERROR 1
#define END_LINE 0x0
#define SERVER_PORT 1500
#define MAX_MSG 100
/* function readline */
int read_line();
- 35-
int main (int argc, char *argv[]) {
 int sd, newSd, cliLen;
 struct sockaddr_in cliAddr, servAddr;
 char line[MAX_MSG];
 /* Gán các giá tr? cho ??i t??ng socket.
 T?o socket cho máy Server. L?u l?i s? mô t? socket */
 sd = socket(AF_INET, SOCK_STREAM, 0);
 if(sd<0) {
 perror("cannot open socket ");
 return ERROR;
 }
 /* ??t tên socket cho ch??ng trình Server
 Gán ??a ch? k?t n?i cho socket theo giao th?c Internet */
 servAddr.sin_family = AF_INET;
 servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
 servAddr.sin_port = htons(SERVER_PORT);
 if(bind(sd, (struct sockaddr *) &servAddr, sizeof(servAddr))<0) {
 perror("cannot bind port ");
 return ERROR;
 }
 /* ??o hàng ??i l?ng nghe k?t n?i c?a client
 Cho phép hàng ??i nh?n t?i ?a 5 k?t n?i */
 listen(sd,5);
 /* L?p liên t?c ch? và lxy k?t n?i c?a client */
 while(1) {
 printf("%s: waiting for data on port TCP %u\n",argv[0],SERVER_PORT);
 cliLen = sizeof(cliAddr);
 /* Ch?p nh?n k?t n?i */
 newSd = accept(sd, (struct sockaddr *) &cliAddr, &cliLen);
 if(newSd<0) {
 perror("cannot accept connection ");
 return ERROR;
 }
 /* init line */
 memset(line,0x0,MAX_MSG);
 /* ??c d? li?u do Client g?i ??n - x? lý d? li?u nh?n ???c */
 while(read_line(newSd,line)!=ERROR) {
 printf("%s: received from %s:TCP%d : %s\n", argv[0], inet_ntoa(cliAddr.sin_addr),
 ntohs(cliAddr.sin_port), line);
 /* init line */
 memset(line,0x0,MAX_MSG);
- 36-
 } /* while(read_line) */
 } /* while (1) */
}
/* WARNING */
/* this function is experimental. I don't know yet if it works */
/* correctly or not. Use Steven's readline() function to have something robust.*/
/* rcv_line is my function readline(). Data is read from the socket when */
/* needed, but not byte after bytes. All the received data is read. */
/* This means only one call to recv(), instead of one call for each received byte. */
/* You can set END_CHAR to whatever means endofline for you. (0x0A is \n)*/
/* read_lin returns the number of bytes returned in line_to_return */
/* Hàm có ch?c n?ng ??c d? li?u t? socket*/
int read_line(int newSd, char *line_to_return) {
 static int rcv_ptr=0;
 static char rcv_msg[MAX_MSG];
 static int n;
 int offset;
 offset=0;
 while(1) {
 if(rcv_ptr==0) {
 /* read data from socket */
 memset(rcv_msg,0x0,MAX_MSG); /* init buffer */
 n = recv(newSd, rcv_msg, MAX_MSG, 0); /* wait for data */
 if (n<0) {
 perror(" cannot receive data ");
 return ERROR;
 } else if (n==0) {
 printf(" connection closed by client\n");
 close(newSd);
 return ERROR;
 }
 }
 /* if new data read on socket OR if another line is still in buffer */
 /* copy line into 'line_to_return' */
 while(*(rcv_msg+rcv_ptr)!=END_LINE && rcv_ptr<n) {
 memcpy(line_to_return+offset,rcv_msg+rcv_ptr,1);
 offset++;
 rcv_ptr++;
 }
 /* end of line + end of buffer => return line */
 if(rcv_ptr==n-1) {
 /* set last byte to END_LINE */
 *(line_to_return+offset)=END_LINE;
 rcv_ptr=0;
 return ++offset;
 }
- 37-
 /* end of line but still some data in buffer => return line */
 if(rcv_ptr <n-1) {
 /* set last byte to END_LINE */
 *(line_to_return+offset)=END_LINE;
 rcv_ptr++;
 return ++offset;
 }
 /* end of buffer but line is not ended => */
 /* wait for more data to arrive on socket */
 if(rcv_ptr == n) {
 rcv_ptr = 0;
 }
 } /* while */
}/*main*/
9.2. L?p trình client /server theo giao th?c UDP/IP
· Ch??ng trình udpClient.c
/* udpClient.c */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include /* memset() */
#include /* select() */
#define REMOTE_SERVER_PORT 1500
#define MAX_MSG 100
int main(int argc, char *argv[]) {
 int sd, rc, i;
 struct sockaddr_in cliAddr, remoteServAddr;
 struct hostent *h;
 /* check command line args */
 if(argc<3) {
 printf("usage : %s ... \n", argv[0]);
 exit(1);
 }
 /* get server IP address (no check if input is IP address or DNS name */
 h = gethostbyname(argv[1]);
 if(h==NULL) {
 printf("%s: unknown host '%s' \n", argv[0], argv[1]);
 exit(1);
 }
- 38-
 printf("%s: sending data to '%s' (IP : %s) \n", argv[0], h->h_name,
 inet_ntoa(*(struct in_addr *)h->h_addr_list[0]));
 remoteServAddr.sin_family = h->h_addrtype;
 memcpy((char *) &remoteServAddr.sin_addr.s_addr,
 h->h_addr_list[0], h->h_length);
 remoteServAddr.sin_port = htons(REMOTE_SERVER_PORT);
 /* socket creation */
 sd = socket(AF_INET,SOCK_DGRAM,0);
 if(sd<0) {
 printf("%s: cannot open socket \n",argv[0]);
 exit(1);
 }
 /* bind any port */
 cliAddr.sin_family = AF_INET;
 cliAddr.sin_addr.s_addr = htonl(INADDR_ANY);
 cliAddr.sin_port = htons(0);
 rc = bind(sd, (struct sockaddr *) &cliAddr, sizeof(cliAddr));
 if(rc<0) {
 printf("%s: cannot bind port\n", argv[0]);
 exit(1);
 }
 /* send data */
 for(i=2;i<argc;i++) {
 rc = sendto(sd, argv[i], strlen(argv[i])+1, 0,
 (struct sockaddr *) &remoteServAddr,
 sizeof(remoteServAddr));
 if(rc<0) {
 printf("%s: cannot send data %d \n",argv[0],i-1);
 close(sd);
 exit(1);
 }
 }
 return 1;
}
· Ch??ng trình udpServer.c
/* udpServer.c */
#include 
#include 
#include 
#include 
#include 
#include 
#include /* close() */
- 39-
#include /* memset() */
#define LOCAL_SERVER_PORT 1500
#define MAX_MSG 100
int main(int argc, char *argv[]) {
 int sd, rc, n, cliLen;
 struct sockaddr_in cliAddr, servAddr;
 char msg[MAX_MSG];
 /* T?o socket trên máy Server - ??t tên cho socket c?a ch??ng trình Server */
 sd=socket(AF_INET, SOCK_DGRAM, 0);
 if(sd<0) {
 printf("%s: cannot open socket \n",argv[0]);
 exit(1);
 }
 /* bind local server port ? ràng bu?c tên v?i socket */
 servAddr.sin_family = AF_INET;
 servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
 servAddr.sin_port = htons(LOCAL_SERVER_PORT);
 rc = bind (sd, (struct sockaddr *) &servAddr,sizeof(servAddr));
 if(rc<0) {
 printf("%s: cannot bind port number %d \n", argv[0], LOCAL_SERVER_PORT);
 exit(1);
 }
 printf("%s: waiting for data on port UDP %u\n", argv[0],LOCAL_SERVER_PORT);
 /* Th?c hi?n vòng l?p vô h?n trên Server ?? ch? và x? lý k?t n?i ??n t? máy client */
 while(1) {
 /* Kh?i t?o b????m */
 memset(msg,0x0,MAX_MSG);
 /* Nh?n d? li?u g?i ??n t? client */
 cliLen = sizeof(cliAddr);
 n = recvfrom(sd, msg, MAX_MSG, 0, (struct sockaddr *) &cliAddr, &cliLen);
 if(n<0) {
 printf("%s: cannot receive data \n",argv[0]);
 continue;
 }
 /* In d? li?u nh?n ???c */
 printf("%s: from %s:UDP%u : %s \n", argv[0],inet_ntoa(cliAddr.sin_addr),
 ntohs(cliAddr.sin_port),msg);
 }/*while*/
return 0;
}
- 40-
Bài 10 D?CH V? TRUY?N FILE FTP
FTP (File Transfer Protocol) là d?ch v? cho phép truy?n các t?p tin gi?a hai máy
tính Client và Server, qu?n lý các th? m?c và truy c?p vào th? tín ???n t?. FTP không
???c thi?t l?p ?? truy c?p vào m?t máy khác và ch?y các ch??ng trình ? máy ?ó, ch?
dùng cho vi?c truy?n t?p tin.
?? k?t n?i FTP, gõ l?nh sau : ftp 
??nh ng??i dùng FTP Mô t?
ascii Chuy?n sang ch???? truy?n ascii
bell âm thanh c?a ch??ng trình sau khi truy?n m?i t?p tin
binary Chuy?n sang ch???? truy?n nh? phân
cd directory Chuy?n ??i th? m?c hi?n hành trên server
cdup Lùi th? m?c hi?n hành v? m?t c?p tr??c ?ó
close Hu? k?t n?i
delete filename Xoá m?t t?p tin trên server
dir directory Hi?n th? th? m?c directory c?a server
get filename Truy?n t?p tin trên server v? máy c?c b?
hash Hi?n th?/làm m?t d?u # cho m?i kh?i các ký t???ã truy?n ???c
help Hi?n th? các tr? giúp
lcd directory Chuy?n ??i th? m?c hi?n hành trên máy c?c b?
ls directory Xem danh sách các t?p tin trong th? m?c directory trên Server
mdelete files Xóa nhi?u t?p tin trên máy Server
mdir directories Li?t kê các t?p tin trong nhi?u th? m?c trên máy Server
mget files ??i nhi?u t?p tin trên máy Server v? th? m?c hi?n hành c?a máy
??c b?
mkdir ??o th? m?c trên máy Server
mput files ??i m?t s? t?p tin t? máy c?c b? lên máy Server
open host ??t n?i v?i Server host t? xa
put filename Truy?n t?p tin t? máy c?c b? lên máy Server
pwd Hi?n th? th? m?c hi?n hành trên server
- 41-
status Hi?n th? tr?ng thái c?a ftp
rename file1 file2 ??i tên file1 trên máy Server thành file2
quote Cung c?p m?t l?nh FTP m?t cách tr?c ti?p
quit Ch?m d?t k?t n?i và thoát kh?i ftp
? Hi?n th? danh sách l?nh
Khi truy c?p vào h? th?ng, n?u ch?a có account, ng??i dùng có th? login v?i
account ??c bi?t là anonymous, không có m?t kh?u.
Th?c hành
C:\>ftp ¿ Kh?i ??ng ftp t? th? m?c hi?n hành C:\
(to) : 200.201.202.180
user : user01 Nh?p vào tên user
Password : Nh?p vào m?t kh?u t??ng ?ng
ftp> dir Xem n?i dung th? m?c
ftp> ? Xem n?i dung các l?nh c?a ftp
ftp>put autoexec.bat autoexec.dos Chuy?n t?p tin t? Client lên Server
??i tên m?i là autoexec.dos
ftp> ls Xem k?t qu? truy?n file
ftp>get autoexec.dos LINUX.TXT ??y t?p tin autoexec.dos trên Server v?
Client v?i tên m?i là LINUX.TXT
ftp>mget autoexec.dos ??y t?p tin autoexec.dos trên Server v?
Client th? m?c C:\
ftp>cd /home/user01 Chuy?n ??n th? m?c hi?n hành là user01
là th? m?c có toàn quy?n c?a user user01
ftp>mdir document ??o trong th? m?c user01 th? m?c m?i
có tên document
ftp> help dir Xem h??ng d?n s? d?ng l?nh dir
ftp>help get Xem h??ng d?n s? d?ng l?nh get
ftp> quit ??t thúc phiên làm vi?c
- 42-
Bài 11 CÁC T?P TIN C?U HÌNH M?NG
1. T?p tin /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
200.201.202.1 linuxsvr.dng.vn linuxsvr
2. ??p tin /etc/sysconfig/network
NETWORKING=yes
FORWARD_IPV4=false
HOSTNAME=linuxsvr.edu.vn
DOMAIN=edu.vn
GATEWAY=200.201.202.1
3. ??p tin /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
PEERDNS=no
TYPE=Ethernet
IPADDR=200.201.202.1
NETMASK=255.255.255.0
NETWORK=200.201.202.0
BROADCAST=200.201.202.255
4. Ch?y ch??ng trình X- Windows h? tr? c?u hình h? th?ng :
redhat-config-network
5. Kh?i ??ng l?i d?ch v? m?ng
[root@linuxsvr root]#/etc/init.d/network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Setting network parameters: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
6. Ki?m tra b?ng l?nh :
[root@linuxsvr root]#hostname
linuxsvr.dng.vn
- 43-
7. Xem thông tin v? c?u hình thi?t b? m?ng
[root@linuxsvr root]#ifconfig
eth0 Link encap:Ethernet HWaddr 00:06:7B:02:71:21
 inet addr:200.201.202.1 Bcast:200.201.202.255 Mask:255.255.255.0
 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
 RX packets:2326 errors:0 dropped:0 overruns:0 frame:0
 TX packets:70927 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:100
 RX bytes:218392 (213.2 Kb) TX bytes:6939053 (6.6 Mb)
 Interrupt:9 Base address:0x4c00
lo Link encap:Local Loopback
 inet addr:127.0.0.1 Mask:255.0.0.0
 UP LOOPBACK RUNNING MTU:16436 Metric:1
 RX packets:933 errors:0 dropped:0 overruns:0 frame:0
 TX packets:933 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:0
 RX bytes:87261 (85.2 Kb) TX bytes:87261 (85.2 Kb)
Hình 1. C?u hình d?ch v? m?ng b?ng ti?n ích redhat-config-network.
- 44-
Bài 12 ??U HÌNH D?CH V? DNS
12.1. Các t?p tin c?u hình d?ch v? DNS
12.1.1. T?p tin /etc/host.conf
order hosts,bind
12.1.2. T?p tin /etc/resolv.conf
:search dng.vn
nameserver 200.201.202.1
12.1.3. T?p tin /etc/named.conf
# named.conf - configuration for bind
# Generated automatically by redhat-config-bind, alchemist et al.
# Any changes not supported by redhat-config-bind should be put
# in /etc/named.custom
controls {
 inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
include "/etc/named.custom";
include "/etc/rndc.key";
zone "0.0.127.in-addr.arpa" {
 type master;
 file "0.0.127.in-addr.arpa.zone";
};
zone "localhost" {
 type master;
 file "localhost.zone";
};
zone "dng.vn" {
 type master;
 file "dng.vn.zone";
};
zone "edu.vn" {
 type master;
 file "edu.vn.zone";
};
12.1.4. T?p tin /var/named/dng.vn.zone
$TTL 86400
@ IN SOA dng. root.localhost (
 1 ; serial
 28800 ; refresh
 7200 ; retry
 604800 ; expire
 86400 ; ttl
 )
 IN NS 200.201.202.1.
- 45-
www IN A 200.201.202.1
tankhoi01 IN A 200.201.202.1
tankhoi02 IN A 200.201.202.2
12.1.5. T?p tin /var/named/edu.vn.zone
$TTL 86400
@ IN SOA edu. root.localhost (
 2 ; serial
 28800 ; refresh
 7200 ; retry
 604800 ; expire
 86400 ; ttl
 )
 IN NS 200.201.202.1.
www IN A 200.201.202.1
tankhoi01 IN A 200.201.202.1
tankhoi02 IN A 200.201.202.2
12.1.6. T?p tin /var/named/0.0.127.in-addr.arpa.zone
$TTL 86400
@ IN SOA localhost. root.linuxsvr.dng.vn (
 36 ; serial
 28800 ; refresh
 7200 ; retry
 604800 ; expire
 86400 ; ttk
 )
@ IN NS localhost.
1 IN PTR localhost.
1 IN PTR www.
1 IN PTR tankhoi01.
2 IN PTR tankhoi02.
1 IN PTR www.
1 IN PTR tankhoi01.
2 IN PTR tankhoi02.
12.1.7. T?p tin /var/named/localhost.zone
$TTL 86400
@ IN SOA @ root.localhost (
 1 ; serial
 28800 ; refresh
 7200 ; retry
 604800 ; expire
 86400 ; ttl
 )
 IN NS localhost.
@ IN A 127.0.0.1
12.1.8. L?nh kh?i ??ng d?ch v? DNS
/etc/init.d/named restart
- 46-
12.2. Các l?nh và ti?n ích h? tr?
12.2.1. L?nh nslookup
#nslookup
Note: nslookup is deprecated and may be removed from future releases.
Consider using the `dig' or `host' programs instead. Run nslookup with
the `-sil[ent]' option to prevent this message from appearing.
> www.dng.vn
Server: 200.201.202.1
Address: 200.201.202.1#53
Name: www.dng.vn
Address: 200.201.202.1
> tankhoi02.edu.vn
Server: 200.201.202.1
Address: 200.201.202.1#53
Name: tankhoi02.edu.vn
Address: 200.201.202.2
12.2.2. L?nh host
#host tankhoi01.dng.vn
tankhoi01.dng.vn has address 200.201.202.1
12.2.3. L?nh dig
# dig dng.vn
; > DiG 9.2.1 > dng.vn
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58922
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;dng.vn. IN A
;; AUTHORITY SECTION:
dng.vn. 86400 IN SOA dng. root.localhost.dng.vn. 1 28800 7200
604800 86400
;; Query time: 28 msec
;; SERVER: 200.201.202.1#53(200.201.202.1)
;; WHEN: Mon Mar 22 09:14:13 2004
;; MSG SIZE rcvd: 78
12.2.4. Ti?n ích redhat-config-bind
#redhat-config-bind
- 47-
Hình 2. C?u hình d?ch v? BIND b?ng ti?n ích redhat-config-bind.
@2004, Nguy?n T?n Khôi
KHOA CÔNG NGH? THÔNG TIN - TR??NG ??I H?C BÁCH KHOA ?À N?NG

File đính kèm:

  • pdfgiao_trinh_he_thong_mang_linux_nguyen_tan_khoi.pdf