Linux operating system experiment ten Linux network and service configuration

1. Experimental purpose and requirements

  1. Understand network related concepts
  2. Understand various network configuration files
  3. Master common network related commands
  4. Two ways to master network configuration
  5. Understanding Web Services
  6. Master common network service configuration and application (WWW/Samba, etc.)

2. Experimental platform

The experimental environment installed in the laboratory (Linux operating system) and Touge (www.educoder.net) experimental platform (course experiment)

3. Experimental content

  1. Two ways to master network configuration
  2. Master www service installation, startup, configuration, application
  3. Master Samba service installation, startup, configuration, application

4. Experiment details and steps

  1. Refer to the PPT courseware and red hat linux 9 installation instructions.doc, VMwareTools installation and network settings, complete 2 and 3
  2. Eth0 network (IP/gateway/subnet mask/DNS) configuration and activation (experiment of image interface and tools (setup and netconfig)), after setting, use the ping command to test whether the network is smooth or not
  3. Network command practice: use of hostname/ifcofig/route/netstat/write and other commands

mission details

WebA server generally refers to a website server, which refers to a program that resides on a certain type of computer on the Internet. It can Webprovide documents to clients such as browsers, and can also place website files for browsing by the world; it can also place data files for the world to browse. download.

The task of this level: introduce the Linuxcommonly used Webserver software on the system httpd, and we learn how to Linuxbuild a Webserver on the system.

related information

Currently the three most mainstream Webservers are Httpd, , Nginxand IIS.

HttpdIt is an open source software and is generally Webused as a server. At present, the most popular Webserver software is called . It was called httpdin the early days , and it was renamed . So sometimes hearing server and server actually mean the same thing.Http serverApacheHttp server 2.0HttpdApacheHttpd

HttpdIt is the main program of Apachethe Hypertext Transfer Protocol (HTTP HTTP) server. Designed as a stand-alone background process, it creates a pool of child processes or threads to handle requests.

LinuxThe system installation software Windowsis not the same as the installation software on the system. On the WindowsInternet, we only need to download the binary file of the software to be installed (the common format is .exe), and then double-click to install it. LinuxThe common ways to install software on the system are as follows :

  1. Source code compilation and installation
  2. package installation
  3. Install online

The source code installation step is to download the source code to the machine, then compile the source code to generate an executable file, and then copy the generated executable file to the corresponding installation directory. The common software source code package format is, .tar.gzetc .tar.bz2.;

The software package installation step is to download the compiled executable file package, and then use the corresponding package management tool to install it. Different Linuxsystems use different package management tools. The common package management tools are as follows:

  1. Ubuntu/Debian systems use the dpkg line to manage software packages (the suffix of the software package is .deb);
  2. The Redhat/CentOS system uses rpm to manage software packages (the suffix of the software package is .rpm);

Online installation means that the user does not need to download the corresponding software package in person, but the corresponding system needs to be able to access the Internet. Different Linuxsystems use different tools to install software online. Common online software installation tools are as follows:

  1. Ubuntu/Debian system uses apt-get to install software online;
  2. Redhat/CentOS system uses yum to install software online;

It is recommended to use online installation software. The common problem of offline installation software is the dependency between software. If you install software offline, you must manually install the dependent library, while online installation only needs one command to complete all operations, and online installation will automatically To install dependent libraries;

Install Httpd from source code

HttpdThe software depends on the following 3software packages, so Httpdyou need to install the following 3software before installing the software.

  1. arpApachePortable runtime library, supports cross-platform, and its memory management module is itransused by the engine.
  2. apr-util : It is APRa derivative version in the development package.
  3. pcre : A Perllibrary, including perlcompatible regular expression libraries.

The steps to install aprdependent packages are as follows:

  1. Decompress the source package: tar zxvf apr-4.5.tar.gz
  2. Enter the source code folder: cd apr-1.4.5/
  3. Configuration (generate Makefile): ./configure --prefix=/usr/local/apr
  4. Compile the source code: make
  5. Install the source code: sudo make install

[Configuration successful execution result ( ./configure --prefix=/usr/local/apr)]

[Result of successful installation]

The steps to install apr-utildependent packages are as follows:

  1. Decompress the source package: tar zxvf apr-util-3.12.tar.gz
  2. Enter the source code folder: cd apr-util-1.3.12/
  3. Placement (generated Makefile): ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
  4. Compile the source code: make
  5. Install the source code: sudo make install

[Configuration successful execution result ( ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config )]

[Result of successful installation]

The steps to install pcredependent packages are as follows:

  1. Unzip the source package: unzip pcre-8.10.zip
  2. Enter the source code folder: cd pcre-8.10/
  3. Configuration (generate Makefile): ./configure --prefix=/usr/local/pcre
  4. Compile the source code: make
  5. Install the source code: sudo make install

[Configuration successful execution result ( ./configure --prefix=/usr/local/pcre )]

[Result of successful installation]

Download Httpdthe source package, here is httpd-2.4.27.tar.gz  .

The specific installation steps are as follows:

  1. Decompress the source package: tar xvfj httpd-2.4.27.tar.bz2
  2. Enter the source code folder: cd httpd-4.27/
  3. 配置(生成Makefile):./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ -with-pcre=/usr/local/pcre
  4. Compile the source code: make
  5. Install the source code: sudo make install

[Configuration successful execution result ( ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ -with-pcre=/usr/local/pcre )]

[Result of successful installation]

At this point, the source code installation httpdsoftware is over. If it is installed correctly, you can execute apachectlthe command to start the service:

Install Httpd online

The system used in this experiment environment is Ubuntu, so use apt-getthe tool to install the software online. The specific steps are as follows:

  1. Update software sources: sudo apt-get update
  2. Install httpd: sudo apt-get install apache2

If the installation is successful, the following interface will appear:

Note: If the current user is root, you do not need to add it when executing the above installation command sudo.

programming requirements

The task of this level is to learn how to install Httpdsoftware online.

The specific programming requirements are as follows:

  • Install Httpdsoftware online (the experimental environment uses Ubuntuthe system);

mission details

Through the study of the previous level, we learned how to Linuxinstall Httpdsoftware on the system. After we installed it, we next learned how to turn on/off Httpdthe service.

Task of this level: Introduce Linuxhow to open, close and restart Httpdthe service on the system.

related information

When we install Httpdthe software successfully, the default Httpdservice is closed. At this point, if we need to access a locally built website, we must enable Httpdthe service.

The system used in this experiment environment is that Ubuntuwhen we use apt-getthe online installation software, /etc/init.d/a script to start the service software is usually generated in the directory. For example, after we use the apt-getinstallation Httpdsoftware, we can see that /etc/init.d/a script named apache2Script file, the script can be used to control Httpdthe startup and shutdown of services and other information.

[ Httpdservice script file]

Linux service command

LinuxCommands are used in the system serviceto control system services, which can start, stop, restart and shut down system services, and can also display the current status of all system services.

serviceThe usage format of the command:

service 服务名 控制命令

  • Service name: the name of the service to be automatically controlled, that is, /etc/init.dthe name of the script file in the directory;
  • Control commands: Control commands supported by system service scripts.

Common control commands:

  1. start: start the service;
  2. stop: close the service;
  3. restart: restart the service;
  4. status: View the service status;

Note that not all services support the above 4control commands. Different services provide different control commands. Most services support the above 4common control commands.

Httpd service management

When we have successfully installed Httpd, next, we use servicethe command to manage Httpdthe service.

We will introduce how to start, shut down, restart Httpdthe service, and view Httpdthe service status in the following case demonstrations.

Case presentation 1:

To view Httpdthe service status, you can use the following command:

sudo service apache2 status

[Please experience directly in the "command line" on the right]

You can see that the current Httpdservice is in NOT runningthe state, that is, closed.

Case presentation 2:

To start Httpdthe service and check whether it starts successfully, you can use the following command:

  1. sudo service apache2 start
  2. sudo service apache2 status

[Please experience directly in the "command line" on the right]

You can see Httpdthat the service is in runningstatus, and the process IDnumber is 4028.

Case presentation 3:

Restart Httpdthe service and check whether the restart is successful, you can use the following command:

  1. sudo service apache2 restart
  2. sudo service apache2 status

[Please experience directly in the "command line" on the right]

It can be seen that the current Httpdservice is restarted, and the new process IDnumber has also changed 4150.

Case presentation 4:

To shut down Httpdthe service and check whether the shutdown is successful, you can use the following command:

  1. sudo service apache2 stop
  2. sudo service apache2 status

[Please experience directly in the "command line" on the right]

You can see Httpdthat the service is in NOT runningthe state, which is closed.

Note: If the current user is root, you don’t need to add it when executing the above command sudo.

programming requirements

The mission of this level is to learn how to start/shut down Httpdthe server.

The specific programming requirements are as follows:

  • Start Httpdthe service (the experimental environment uses Ubuntuthe system).

mission details

Through the study of the above levels, we learned to install and start Apache2the server. Next let's learn how to configure Apache2the server.

The task of this level: learn Apache2the common configuration of the server.

related information

Before starting the setup Apache2, we know that as long as we start the service, we only need to enter or Httpdin the browser to open a default static web page, as shown in the figure below.localhost127.0.0.1

[It is recommended that you test on a local virtual machine]

The above operation process is roughly divided into the following steps:

  1. HTTPTo connect to IPthe server system at the above address through the protocol, 80the port is used by default (the default port is 80, there are other ports, if the default port is used, there is no need to display the input 80port) to request files Apachein the corresponding directory of the server ;html
  2. ApacheAfter the server receives the user's request, it finds and opens the corresponding file in the document directory it manages html, and responds to the client browser with the content of the file;
  3. After the browser receives Webthe response from the server, it receives and downloads htmlthe static code on the server side, then the browser interprets the code, and finally presents the web page.

The above are the general steps for requesting a webpage. Next, let's learn how to configure Apachethe server, such as modifying the default request port.

ApacheMultiple configuration files are provided, and the content in each configuration file is different. Commonly used configuration files are as follows:

  1. /etc/apache2/apache2.conf: main configuration file;
  2. /etc/apache2/ports.conf: file for configuring ports;
  3. /etc/apache2/sites-enabled/000-default.conf: configure the file of the root directory of the Web document;

Apache2Common configurations that we will cover next ;

Apache2Configuration file introduction

/etc/apache2/apache2.confYes Apache2, the main configuration file. The configuration items stored in it are global configuration items. The common configuration items are as follows:

  1. Timeout: Sets the number of seconds the server waits before declaring that the request has failed. The default value is 300;
  2. KeepAlive: Set whether to enable HTTP persistent connection, On means open, Off means close;
  3. MaxKeepAliveRequests: Limits the number of requests allowed per connection when KeepAlive is enabled. If this value is set to "0", the number of requests will not be limited;
  4. KeepAliveTimeout: Set the number of seconds the server waits between two requests in a persistent link;
Apache2other configuration files

/etc/apache2/ports.confIt is Apache2a port configuration file, which stores Apachethe listening port, and Listenthe configuration item is used to configure the listening port.

/etc/apache2/sites-enabled/000-defaultIt is Apache2a configuration file used to set the virtual host directory. A simple understanding is to set the deployed website information, as shown in the figure below.

[ /etc/apache2/sites-enabled/000-defaultfile content]

Here are a few things we need to pay attention to:

  1. <VirtualHost *:80>: indicates a virtual host, where 80 indicates its access port;
  2. DocumentRoot: Indicates the document root directory of the virtual host, which is the directory where our web pages are stored;
  3. <Directory /var/www/>: Indicates some attribute configurations of the root directory;

Case presentation 1:

By default , Apache2the server uses 80the port. Now we change the default port to 8080the following steps:

  1. Set Listen to 8080 (sudo vim /etc/apache2/ports.conf)
  2. Modify <VirtualHost *:80> to <VirtualHost *:8080> (sudo vim /etc/apache2/sites-enabled/000-default)
  3. sudo service apache2 restart
  4. Open the browser and enter: localhost:8080

[edit ports.conffile]

 

[edit 000-defaultfile]

 

[Use a browser to access localhost:8080the address]

[Use a browser to access localhostthe address]

It can be seen that 80when the port is used for access again, it cannot be accessed normally, because the port Apache2is listening at this time 8080.

Case presentation 2:

Configure Apache2to listen to two ports at the same time, one is 80and the other is 8080, both ports access the default static web page at the same time, the specific steps are as follows:

  1. Add Listen to 80 (sudo vim /etc/apache2/ports.conf)
  2. Add <VirtualHost *:80>(sudo vim /etc/apache2/sites-enabled/000-default), completely copy the content under the <VirtualHost *:8080> structure, and then just copy the 8080 of the copied structure Change it to 80
  3. sudo service apache2 restart
  4. Open the browser and enter: localhost:8080
  5. Open the browser and enter: localhost:80

[edit ports.conffile]

[edit 000-defaultfile]

 

[Use a browser to access localhost:8080the address]

[Use a browser to access localhostthe address]

It can be seen that the access 80and 8080port display results are the same at this time, indicating that Apache2requests from these two ports are simultaneously monitored at this time.

Case presentation 3:

Modify 80the root directory of the website monitored by the port /var/www/html, and modify the content of the default webpage at the same time. The specific steps are as follows:

  1. sudo directory /var/www/html
  2. sudo touch /var/www/html/index.html
  3. Add content to file /var/www/html/index.html: This is my first web! (sudo vim /var/www/html/index.html)
  4. Set <VirtualHost *:80> (sudo vim /etc/apache2/sites-enabled/000-default), modify all /var/www under the <VirtualHost *:80> structure to /var/www/html
  5. sudo service apache2 restart
  6. Open the browser and enter: localhost:80

[add content /var/www/html/index.html]

[edit 000-defaultfile]

[Use a browser to access localhostthe address]

programming requirements

The mission of this level is to learn how to configure Apache2the server.

Note: Before executing the task of this level, first execute the following command to initialize the task environment.

  1. mkdir /var/www/html/test
  2. cp /var/www/html/index.html /var/www/html/test

The specific programming requirements are as follows:

  • Modify the default access port from 80to 8011;
  • Add a new listening port as 8012and set the root directory to /var/www/html/test;

mission details

SambaIt is a free software that implements the agreement on the system Linuxand system , and is composed of a server and a client program.UNIXSMB

The task of this level: we learn how to Linuxbuild a Sambaserver on the system.

related information

SambaIt is a free software that implements the agreement on the system Linuxand system , and is composed of a server and a client program. ( , information service block) is a communication protocol for sharing files and printers on a local area network. It provides sharing services for resources such as files and printers among different computers in the local area network.UNIXSMBSMBServer Messages Block

SMBThe protocol is a client/server type protocol that allows clients to access shared file systems, printers, and other resources on the server. Through setting, NetBIOS over TCP/IPit Sambacan not only share resources with local area network hosts, but also share resources with computers all over the world.

LinuxThe system installation software Windowsis not the same as the installation software on the system. On the WindowsInternet, we only need to download the binary file of the software to be installed (the common format is .exe), and then double-click to install it. LinuxThe common ways to install software on the system are as follows :

  1. Source code compilation and installation
  2. package installation
  3. Install online

The source code installation step is to download the source code to the machine, then compile the source code to generate an executable file, and then copy the generated executable file to the corresponding installation directory. The common software source code package format is, .tar.gzetc .tar.bz2.;

The software package installation step is to download the compiled executable file package, and then use the corresponding package management tool to install it. Different Linuxsystems use different package management tools. The common package management tools are as follows:

  1. Ubuntu/Debian systems use dpkg to manage software packages (the suffix of the software package is .deb);
  2. The Redhat/CentOS system uses rpm to manage software packages (the suffix of the software package is .rpm);

Online installation means that the user does not need to download the corresponding software package in person, but the corresponding system needs to be able to access the Internet. Different Linuxsystems use different tools to install software online. Common online software installation tools are as follows:

  1. Ubuntu/Debian system uses apt-get to install software online;
  2. Redhat/CentOS system uses yum to install software online;

It is recommended to use online installation software. The common problem of offline installation software is the dependency between software. If you install software offline, you must manually install the dependent library, while online installation only needs one command to complete all operations, and online installation will automatically To install dependent libraries;

Install Samba from source code

SambaThe software depends on the following software packages, so before installing Sambathe software, you need to install the following dependent packages first.

  1. python-dev: sudo apt-get install python-dev
  2. libgnutls-dev: sudo apt-get install libgnutls-dev
  3. libacl1-dev: sudo apt-get install libacl1-dev
  4. libldap2-dev: sudo apt-get install libldap2-dev

First download the source package, here is samba-4.8.2.tar.gz .

The specific installation steps are as follows:

  1. Decompress the source package: tar zxvf samba-4.8.2.tar.gz
  2. Enter the source code folder: cd samba-4.8.2/
  3. Placement (generated Makefile): ./configure --prefix=/usr/local/samba --without-pam
  4. Compile the source code: make
  5. Install the source code: sudo make install

[`./configure --prefix=/usr/local/samba --without-pam`successful execution

[`make` successful execution result]

[`sudo make install` successful execution result]

At this point, the source code installation Sambasoftware is finished. If it is installed correctly, you can execute the following command to start the service:

  1. sudo /usr/local/samba/sbin/smbd –D
  2. sudo /usr/local/samba/sbin/nmbd –D

##### Install Samba online The system used in this experiment environment is `Ubuntu`, so use the `apt-get` tool to install the software online, the specific steps are as follows:

  1. Update software sources: sudo apt-get update
  2. Install samba: sudo apt-get install samba

If the installation is successful, the following interface will appear:

Note: If the current user is root, you do not need to add it when executing the above installation command sudo.

programming requirements

The task of this level is to learn how to install sambasoftware online.

The specific programming requirements are as follows:

  • Install sambathe software online (the experimental environment uses Ubuntuthe system).

mission details

Through the study of the previous level, we learned how to Linuxinstall sambasoftware on the system. After we installed it, we next learned how to turn on/off sambathe service.

Task of this level: Introduce Linuxhow to open, close and restart sambathe service on the system.

related information

When we install sambathe software successfully, Ubuntu 12.04the system default sambaservice is enabled.

The system used in this experimental environment is that Ubuntuwhen we use apt-getthe online installation software, /etc/init.d/a script to start the service software is usually generated in the directory. For example, after we use apt-getthe installation sambasoftware, we can see that a script file /etc/init.d/named .smbdsamba

[`samba` service script file]

##### Linux service command

LinuxCommands are used in the system serviceto control system services, which can start, stop, restart and shut down system services, and can also display the current status of all system services.

serviceThe usage format of the command:

service 服务名 控制命令

  • Service name: the name of the service to be automatically controlled, that is, /etc/init.dthe name of the script file in the directory;
  • Control commands: Control commands supported by system service scripts.

Common control commands:

  1. start: start the service;
  2. stop: close the service;
  3. restart: restart the service;
  4. status: View the service status;

Note that not all services support the above 4control commands. Different services provide different control commands. Most services support the above 4common control commands.

samba service management

When we have successfully installed samba, next, we use servicethe command to manage sambathe service.

We will introduce how to start, shut down, restart sambathe service, and view sambathe service status in the following case demonstrations.

Case presentation 1:

To view sambathe service status, you can use the following command:

sudo service smbd status

[Please experience directly in the "command line" on the right]

You can see that the current `samba` service is in the `running` state, that is, the running state, and the `ID` of its running process is `54244`.

Case presentation 2:

To shut down sambathe service and check whether the shutdown is successful, you can use the following command:

  1. sudo service smbd stop
  2. sudo service smbd status

[Please experience directly in the "command line" on the right]

You can see the status sambaof the service waiting.

Case presentation 3:

To start sambathe service and check whether it starts successfully, you can use the following command:

  1. sudo service smbd start
  2. sudo service smbd status

[Please experience directly in the "command line" on the right]

You can see that the `samba` service is in the `running` state, and the `ID` of the running process is `54408`.

Case presentation 4:

To restart sambathe service and check whether the restart is successful, you can use the following command:

  1. sudo service smbd restart
  2. sudo service smbd status

[Please experience directly in the "command line" on the right]

You can see that the current sambaservice is blocked first stop, and then blocked start.

Note: If the current user is root, you don’t need to add it when executing the above command sudo.

programming requirements

The mission of this level is to learn how to start/shut down sambathe server.

The specific programming requirements are as follows:

  • Start sambathe service (the experimental environment uses Ubuntuthe system).

mission details

Through the learning of the above levels, we have learned how to install and start sambathe server software. Next, we will learn how to use sambathe client software to log in to the server remotely.

The task of this level: learn how to use sambathe client software to log in to the server remotely.

related information

The client software is available on Linuxthe system .sambasmbclient

smbclientCommands are sambasuites that provide a command-line use for interactive access to sambathe server's shared resources. Linux smbclientSome frequently used commands of the command are detailed here .

smbclientInstall software online

The system used in this experiment environment is Ubuntu, so use apt-getthe tool to install the software online. The specific steps are as follows:

  1. Update software sources: sudo apt-get update
  2. 安装smbclient:sudo apt-get install smbclient

If the installation is successful, the following interface will appear:

**Note**: If the current user is `root`, there is no need to add `sudo` when executing the above installation command.

sambaUser Management

smbpasswdCommands belong to sambathe suite, which can add or delete sambausers and change passwords for users.

smbpasswdCommand format:

smbpasswd 选项 用户名

Common options are as follows:

  1. -a: Add users to the smbpasswd file;
  2. -c: Specify the configuration file of samba;
  3. -x: delete the user from the smbpasswd file;
  4. -d: disable the specified user in the smbpasswd file;
  5. -e: Activate the specified user in the smbpasswd file;
  6. -n: empty the password of the specified user;

Username: Specify smbthe user whose password is to be changed.

Note: The user used here is an existing user in the system.

Case presentation 1:

To add a sambauser sambaUser, you can use the following command:

  1. sudo useradd sambaUser
  2. sudo smbpasswd -a sambaUser

[Please experience directly in the "command line" on the right]

Common usage of smbclient command

smbclientCommand format:

smbclient 选项 smb服务器

Common options are as follows:

  1. -L: Display all resources shared by the server;
  2. -p<TCP connection port>: specify the server-side TCP connection port number;
  3. -s<directory>: specify the directory where smb.conf is located;
  4. -U<user name>: specify the user name;
  5. -N: Do not ask for a password;

smbServer: Specify the server to connect to smb.

Common smbclientcommands are as follows:

  1. smb: \> ? or help [command] provides help about help or a command;
  2. smb: \> ![shell command] Execute the used SHELL command, or let the user enter the SHELL prompt;
  3. smb: \> cd [directory] switch to the specified directory on the server side, if not specified, smbclient returns the current local directory;
  4. smb: \> lcd [directory] switch to the directory specified by the client;
  5. smb: \> dir or ls lists the files in the current directory on the server side;
  6. smb: \> exit or quit to exit smbclient;
  7. smb: \> get file1 file2 Download file1 from the server, and store it on the local machine with the file name file2; if you don’t want to change the name, you can omit file2;
  8. smb: \> mget file1 file2 file3 filen Download multiple files from server;
  9. smb: \> md or mkdir directory to create a directory on the server;
  10. smb: \> rd or rmdir directory to delete a directory on the server;
  11. smb: \> put file1 [file2] Upload a file file1 to the server, and rename it to file2 on the server;
  12. smb: \> mput file1 file2 filen Upload multiple files to the server;

Note: smbclientMany of the commands and ftpthe commands are used similarly.

Case demonstration environment initialization: perform the following operations: /etc/samba/smb.confappend the following content to the end of the file, and restart Sambathe server. The next level explains why this is done.

  1. [homes]
  2.         comment = smbclient homes
  3.         path = /tmp
  4.         browseable = no
  5.         writable = yes
  6.         create mask = 0664
  7.         directory mask = 0775

[modified config file]

List shared folders provided by an IP address

Case presentation 1:

Use smbclientthe client to list the shared folders provided locally (use sambaUserthe user to log in to the server, the password is fzm), you can use the following command:

smbclient -L 127.0.0.1 -U sambaUser%fzm

[Please experience directly in the "command line" on the right]

You can see that there are 3 local shared folders, namely: print$, IPC$and sambaUser.

Connect to Samba server remotely

Case presentation 2:

Use smbclientthe client to connect to sambaUserthe shared folder (use sambaUserthe user to log in to the server, the password is fzm), you can use the following command:

smbclient //127.0.0.1/sambaUser -U sambaUser%fzm

[Please experience directly in the "command line" on the right]

other operations

Case presentation 3:

Display the current directory of the remote host, and display the current working directory of the client, display all file information in the current directory of the remote host, and display all information in the current working directory of the client, you can use the following commands:

  1. pwd
  2. ! pwd
  3. ls
  4. ! ls

[Please experience directly in the "command line" on the right]

Case presentation 4:

Create a new folder on the remote host , then upload newDirthe local file to the directory, download the file on the remote host to the directory, and rename it , and finally exit the client, you can use the following command:/home/fzm/testFilenewDirsambaUser/fzm/home/fzmnewFzmsmbclient

  1. mkdir newDir
  2. put /home/fzm/testFile newDir/testFile
  3. get sambaUser/fzm /home/fzm/newFzm
  4. exit

[Please experience directly in the "command line" on the right]

Case presentation 5:

To access the shared folder of the system Windowsthrough the server on the system , you can use the following steps:sambaLinux

  • WindowsOpen "Run" (shortcut key ) on the host and enter the address to win+rbe accessed (format: LinuxIP\\IP );

[Please verify on `Windows` host]

  • After pressing Enter, you can see Linuxthe shared folder on the host ( fzm);

[Please verify on `Windows` host]

  • Just open fzmthe folder for access (sometimes you need to enter sambathe user name and password to access).

[Please verify on `Windows` host]

programming requirements

The task of this level is to learn how to use smbclientcommands to access sambathe shared resources of the server.

Note: Before executing the task of this level, first execute the following command to initialize the task environment.

  1. apt-get update
  2. apt-get install smbclient
  3. useradd testUser
  4. smbpasswd -a testUser (enter the newly set password)
  5. touch testFile
  6. Append the following content to the end of the file `/etc/samba/smb.conf`, and restart the `Samba` server, and restart the service
  1. [homes]
  2.         comment = smbclient homes
  3.         path = /tmp
  4.         browseable = no
  5.         writable = yes
  6.         create mask = 0664
  7.         directory mask = 0775

The specific programming requirements are as follows:

  • start sambathe service;
  • Use smbclientthe command to connect to the local testUsershared folder (use this machine as a remote server and use testUserthe user to access);
  • Create a new directory on the remote server Dir;
  • Upload a local file ( /root/testFile) to the directory of the remote host Dirand rename it to upLoadFile.

mission details

Through the study of the above levels, we have learned to use smbclientcommands to log in to the remote host, and perform file upload and download operations. Next let's learn how to configure sambathe server.

The task of this level: learn sambathe common configuration of the server.

related information

In the previous level, we initialized a series of environments before the case demonstration, and now we will introduce in detail why we need to configure those environments.

sambaThe server provides a lot of configuration items, and each configuration item has a different function. Next, we introduce the sambacommon configuration item functions. sambaThe storage path of the server configuration file is: /etc/samba/smb.confunder the directory.

smb.confstructure

smb.confThe file includes 4structures, [ Global], [ Homes], [ printers], [ Userdefined_shareName], among which:

  1. Globa: used to define global parameters and default values;
  2. Homes: shared home directory for users;
  3. Printers: used to define printer sharing;
  4. Userdefined_ShareName: Used for custom sharing (multiple available).
Global configuration parameters [Global]

The commonly used global configuration parameters are as follows:

  1. Workgroup: Set the workgroup to be joined by samba;
  2. server string: Specify the machine description in the browse list;
  3. netbios name: Set the NetBIOS name of samba (you need to add it yourself);
  4. Interface: Set the interface IP address;
  5. Host allow: Set the host IP that is allowed to access;
  6. log file: Specify the name of the log file;
  7. Max log size: Specify the maximum size of the log file (KB);
  8. security: It defines the installation level of samba.

Case presentation 1:

Modify the machine description in the browse list to This is My Samba Server, specifically use the following steps:

  1. Modify the server string value in the smb.conf file (sudo vim /etc/samba/smb.conf)
  2. sudo service smbd restart
  3. smbclient -L 127.0.0.1 -U sambaUser%fzm

[Modify configuration file]

[Please experience directly in the "command line" on the right]

Configure home sharing [homes]

homeBy default, sharing will share the user's home directory, which is very dangerous. For security reasons, we need to specify the shared directory ourselves. homeThe advantage of using the shared directory is that the name of the shared directory seen by different login users is their own user name.

Common properties for setting shared directories are as follows:

  1. comment : describe the name of the share;
  2. path: defines the shared directory;
  3. browseable : Specifies whether the shared directory can be browsed;
  4. Writable: Specify whether the shared directory has write permission;
  5. read only: Specifies that the shared directory is read-only;
  6. Public: Specify whether to allow Guest account access;
  7. Guest ok: Same as public, yes means guest access is allowed;
  8. create mask: the default permission to create files;
  9. directory mask: Default permission to create directories.

Let's now explain why we added the following properties to the configuration file in the previous level:

[Previous level configuration file]

You can see that we have homespecified the shared directory as /tmp, and the settings can have write permissions, as well as the default permissions for creating files and directories.

Case presentation 1:

Set homeit as browsable, specifically use the following steps:

  1. Modify the server string value in the smb.conf file (sudo vim /etc/samba/smb.conf)
  2. sudo service smbd restart
  3. smbclient -L 127.0.0.1 -U sambaUser%fzm

[Please experience directly in the "command line" on the right]

homesYou can see that there is now one more folder in the local shared folder .

custom share

Multiple custom shared folders can be set, the setting method homeis similar to that of , and the name of the shared folder can be chosen at will.

Case presentation 1:

To customize a shared folder, set the shared name to MyShare, specify the shared directory to /tmp, and set its writable attribute and the default permissions for creating files and directories to 0644and respectively 0755. The specific steps are as follows:

  1. Modify the server string value in the smb.conf file (sudo vim /etc/samba/smb.conf)
  2. sudo service smbd restart
  3. smbclient -L 127.0.0.1 -U sambaUser%fzm

[append configuration file]

[Please experience directly in the "command line" on the right]

You can see that the newly created shared folder MyShareis successfully displayed. If you log in, you only need to enter:smbclient //127.0.0.1/MyShare -U userName%passwd

programming requirements

The mission of this level is to learn how to configure sambathe server.

Note: Before executing the task of this level, first execute the following command to initialize the task environment.

  1. mkdir /testDir
  2. chmod 777 /testDir
  3. useradd testUser
  4. smbpasswd -a testUser (enter the newly set password)
  5. touch testFile

The specific programming requirements are as follows:

  • Customize a shared folder, set the shared name to TestShare, specify the shared directory to /testDir, and set it to be browseable, and set its writable attribute and the default permissions for creating files and directories to 0644and respectively 0755;
  • Use smbclientthe command to connect to the local TestShareshared folder (use this machine as a remote server and use testUserthe user to access);
  • Create a new directory on the remote server Dir;
  • Upload a local file ( /root/testFile) to the directory of the remote host Dirand rename it to upLoadFile.

Guess you like

Origin blog.csdn.net/qq_64314976/article/details/131414143
Recommended